STM32 - EMWIN BUTTON control (14)

EMWI

1. Introduction to the BUTTON control

Button is a commonly used control, which can display text or bitmap on the button. By default, the button is displayed as shown in the figure.
insert image description here
We can change the display effect of the button by setting the skin of the button. After setting the button skin, it will be displayed as shown in the figure.
insert image description here

1. Notification code

The following events are sent by the button widget to its parent window as part of the WM_NOTIFY_PARENT message. We usually write the function of the button according to the following notification code, especially in the code generated by GUIBulider

WM_NOTIFICATION_CLICKED 按钮已被点击。
WM_NOTIFICATION_RELEASED 按钮已被释放。
WM_NOTIFICATION_MOVED_OUT 按钮已被点击,且指针已移出按钮并且没有释放。

2. Keyboard response

If the gadget has input focus, it will react to the following keys

GUI_KEY_ENTER 此类键按下后,按钮认为它被按下并立即释放,然后作出相应反应。
GUI_KEY_SPACE此类键按下后,按钮状态改变为已按下。键释放后,按钮状态改变为未按下。

3. Common API functions

BUTTON_Create() 创建 BUTTON 小工具
BUTTON_CreateAsChild() 将 BUTTON 小工具创建为子窗口
BUTTON_CreateEx() 创建 BUTTON 小工具
BUTTON_CreateIndirect() 从资源表项创建 BUTTON 小工具
BUTTON_CreateUser() 使用额外字节作为用户数据创建 BUTTON 小工具。
BUTTON_GetBitmap() 返回指向 BUTTON 位图的指针。
BUTTON_GetBkColor() 返回 BUTTON 的背景色。
BUTTON_GetDefaultBkColor() 返回 BUTTON 小工具的默认背景色。
BUTTON_GetDefaultFont() 返回 BUTTON 小工具的默认字体。
BUTTON_GetDefaultTextAlign() 返回 BUTTON 小工具的默认文本对齐方式。
BUTTON_GetDefaultTextColor() 返回 BUTTON 小工具的默认文本颜色。
BUTTON_GetFont() 返回 BUTTON 小工具字体的指针。
BUTTON_GetText() 检索指定 BUTTON 的文本。
BUTTON_GetTextAlign() 返回 BUTTON 文本的对齐方式。
BUTTON_GetTextColor() 返回指定 BUTTON 的文本颜色。
BUTTON_GetUserData() 检索用 BUTTON_SetUserData 设置的数据。
BUTTON_IsPressed() 返回表示按钮是否按下的值。
BUTTON_SetBitmap() 设置显示 BUTTON 时使用的位图。
BUTTON_SetBitmapEx() 设置显示 BUTTON 时使用的位图。
BUTTON_SetBkColor() 设置按钮的背景色。
BUTTON_SetBMP() 设置显示 BUTTON 时使用的位图。
BUTTON_SetBMPEx() 设置显示 BUTTON 时使用的位图。
BUTTON_SetDefaultBkColor() 设置 BUTTON 小工具的默认背景色。
BUTTON_SetDefaultFont() 设置 BUTTON 小工具的默认字体。
BUTTON_SetDefaultTextAlign() 设置 BUTTON 小工具的默认文本对齐方式。
BUTTON_SetDefaultTextColor() 设置 BUTTON 小工具的默认文本颜色
BUTTON_SetFocussable() 设置接收输入焦点的能力。
BUTTON_SetFont() 选择文本的字体。
BUTTON_SetPressed() 将按钮的状态设置为按下或未按下。
BUTTON_SetReactOnLevel() 将所有 BUTTON 小工具设置为对水平做出反应。
BUTTON_SetStreamedBitmap() 设置显示 BUTTON 小工具时使用的位图。
BUTTON_SetStreamedBitmapEx() 设置显示 BUTTON 小工具时使用的位图。
BUTTON_SetText() 设置文本。
BUTTON_SetTextAlign() 设置 BUTTON 文本的对齐方式。
BUTTON_SetTextColor() 设置文本的颜色。
BUTTON_SetTextOffset() 根据当前的文本对齐方式设置,调节按钮文本的位置。
BUTTON_SetUserData() 设置 BUTTON 小工具的额外数据。

2. Basic routine of BUTTON control

#include "DIALOG.h"
#include "ButtonUse.h"
#include "led.h" //包含 LED 和 BEEP 头文件
#include "beep.h"
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_BUTTON_1 (GUI_ID_USER + 0x02)
//对话框资源表
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = 
{
    
    
{
    
     FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 800, 480, 0, 0x64, 0 },
{
    
     BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 300, 122, 150, 50, 0, 0x0, 0 },
{
    
     BUTTON_CreateIndirect, "Button", ID_BUTTON_1, 300, 251, 150, 50, 0, 0x0, 0 },
};
//对话框回调函数
static void _cbDialog(WM_MESSAGE * pMsg) 
{
    
    
WM_HWIN hItem;
int NCode;
int Id;
switch (pMsg->MsgId) 
{
    
    
case WM_INIT_DIALOG: (1)
//初始化对话框
hItem = pMsg->hWin;
FRAMEWIN_SetTitleHeight(hItem, 30);
FRAMEWIN_SetText(hItem, "ALIENTE BUTTON USE");
FRAMEWIN_SetFont(hItem, GUI_FONT_24_ASCII);
FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
FRAMEWIN_SetTextColor(hItem, 0x0000FFFF);
//初始化 BUTTON0
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetFont(hItem, GUI_FONT_24_ASCII);
BUTTON_SetText(hItem, "LED1");
//初始化 BUTTON1
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
BUTTON_SetText(hItem, "BEEP");
BUTTON_SetFont(hItem, GUI_FONT_24_ASCII);
break;
case WM_NOTIFY_PARENT: (2)
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v; (3)
switch(Id) 
{
    
    
case ID_BUTTON_0: //BUTTON_0 的通知代码,控制 LED1
switch(NCode) 
{
    
    
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED: //按钮被按下并释放 (4)
LED1=~LED1; //LED1 反转 (5)
break;
}
break;
case ID_BUTTON_1: //BUTTON_1 的通知代码,控制 BEEP
switch(NCode) 
{
    
    
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
BEEP=~BEEP; //蜂鸣器反转 (6)
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
} }
//创建一个对话框
WM_HWIN CreateFramewin(void) 
{
    
    
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog,WM_HBKWIN, 0, 0);
return hWin;
}
//BUTTO 演示函数
void ButtonUse_Demo(void)
{
    
    
WM_HWIN hWin;
hWin=CreateFramewin();
while(1)
{
    
    
GUI_Delay(100);
} }

(1) The WM_INIT_DIALOG message is used to initialize the widgets in the dialog box.
(2) The notification message sent by the child control to the parent control. In this message, we make different processing according to different message types of different controls.
(3) The notification code of the widget is placed in the variable Data.v of the structure WM_MESSAGE, where we get the notification code of the BUTTON button, and judge whether the BUTTO is pressed or released by analyzing the notification code.
(4), the BUTTON button is released.
(5), control the LED switch.
(6), control the buzzer switch.
insert image description here
When pressed, the corresponding function will be executed.

Guess you like

Origin blog.csdn.net/qq_51963216/article/details/124038843