STM32 - EMWIN CHECKBOX control (sixteen)

EMWI

foreword

Checkboxes are one of the most common gadgets for selecting a variety of options, allowing users to check or uncheck boxes, and to check any number of boxes at once. When using the keyboard interface, the state of the focused checkbox can be toggled with the spacebar, and disabled boxes are grayed out

1. Notification code

The following lists the types of messages that a checkbox widget sends to its parent window as part of the WM_NOTIFY_PARENT message:

WM_NOTIFICATION_CLICKED 复选框已被点击。
WM_NOTIFICATION_RELEASED 复选框已被释放。
WM_NOTIFICATION_MOVED_OUT 复选框已被点击,且指针已移出框并且没有释放。
WM_NOTIFICATION_VALUE_CHANGED 复选框的状态已改变。

2. Keyboard response

If the CHECKBOX control has input focus, it will react to the keys listed below:

GUI_KEY_SPACE 切换小工具的选中状态。

3. CHECKBOX control API function

CHECKBOX_CreateEx() 创建 CHECKBOX 小工具。
CHECKBOX_CreateIndirect() 从资源表项创建 CHECKBOX 小工具。
CHECKBOX_CreateUser() 使用额外字节作为用户数据创建 CHECKBOX 小工具。
CHECKBOX_GetDefaultBkColor() 返回 CHECKBOX 小工具文本的默认背景
CHECKBOX_GetDefaultFont() 返回用于显示 CHECKBOX 小工具文本的默认字体。
CHECKBOX_GetDefaultSpacing() 返回 CHECKBOX 小工具文本和框之间的默认间距。
CHECKBOX_GetDefaultTextAlign() 返回用于显示 CHECKBOX 小工具文本的默认对齐方式。
CHECKBOX_GetDefaultTextColor() 返回用于显示 CHECKBOX 小工具文本的默认文本颜色。
CHECKBOX_GetState() 返回复选框的当前状态。
CHECKBOX_GetText() 返回复选框的文本。
CHECKBOX_GetUserData() 检索使用 CHECKBOX_SetUserData()设置的数据。
CHECKBOX_IsChecked() 返回复选框的当前状态(选中或未选中)
CHECKBOX_SetBkColor() 设置给定 CHECKBOX 小工具的背景色。
CHECKBOX_SetBoxBkColor() 设置复选框区域的背景色。
CHECKBOX_SetDefaultBkColor() 设置 CHECKBOX 小工具的默认背景色。
CHECKBOX_SetDefaultFocusColor() 设置 CHECKBOX 小工具的默认焦点矩形颜色。
CHECKBOX_SetDefaultFont() 设置用于显示 CHECKBOX 小工具文本的默认字体。
CHECKBOX_SetDefaultImage() 设置复选框被选中后要显示的默认图像。
CHECKBOX_SetDefaultSpacing() 设置 CHECKBOX 小工具文本和框之间的默认间距。
CHECKBOX_SetDefaultTextAlign() 设置用于显示复选框文本的默认对齐方式。
CHECKBOX_SetDefaultTextColor() 设置用于显示CHECKBOX 小工具文本的默认文本颜色。
CHECKBOX_SetFocusColor() 设置聚焦框的颜色。
CHECKBOX_SetFont() 设置复选框字体。
CHECKBOX_SetImage() 设置复选框被选中后要显示的图像。
CHECKBOX_SetNumStates() 设置复选框的可能状态的数量(23)
CHECKBOX_SetSpacing() 设置框和复选框文本之间的间距。
CHECKBOX_SetState() 设置 CHECKBOX 小工具的状态。
CHECKBOX_SetText() 设置 CHECKBOX 小工具的文本。
CHECKBOX_SetTextAlign() 设置用于显示 CHECKBOX 小工具文本的对齐方式。
CHECKBOX_SetTextColor() 设置用于显示 CHECKBOX 小工具文本的颜色。
CHECKBOX_SetUserData() 设置 CHECKBOX 小工具的额外数据

3. CHECKBOX control demonstration routine

Segger officially provides a demo routine about the CHECKBOX control. Here we transplant this routine to the development board and learn how to use the CHECKBOX control.

#include "checkboxdemo.h"
#include "GUI.h"
#include "DIALOG.h"
//对话框资源表
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    
    
 {
    
     FRAMEWIN_CreateIndirect, "Check box sample",0,10,10,300,220, \
FRAMEWIN_CF_MOVEABLE},
 {
    
     TEXT_CreateIndirect, "Enabled:", 0, 5, 10, 120, 0 },
 {
    
     CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK0, 5, 30, 120, 0 },
 {
    
     CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK1, 5, 60, 120, 0 },
 {
    
     CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK2, 5, 90, 120, 20 },
 {
    
     CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK3, 5, 125, 120, 26 },
 {
    
     TEXT_CreateIndirect, "Disabled:", 0, 150, 10, 120, 0 },
 {
    
     CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK4, 150, 30, 120, 0 },
 {
    
     CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK5, 150, 60, 120, 0 },
 {
    
     CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK6, 150, 90, 120, 26 },
 {
    
     CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK7, 150, 125, 120, 26 },
 {
    
     BUTTON_CreateIndirect, "OK", GUI_ID_OK, 10, 165, 80, 30 },
 {
    
     BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 200, 165, 80, 30 },
};
//复选框文本
static const char* _apLabel[]={
    
    
"Default",
"3 States",
"Box XL",
"Box XXL"
};
//回调函数
static void _cbCallback(WM_MESSAGE *pMsg)
{
    
    
int i;
int NCode,Id;
WM_HWIN hDlg,hItem;
hDlg = pMsg->hWin;
switch(pMsg->MsgId)
{
    
    
case WM_INIT_DIALOG:
//获取 CHECKBOX 的句柄
hItem = WM_GetDialogItem(hDlg,GUI_ID_CHECK0); 
for(i=0;i<8;i++) (1)
{
    
    
int Index=i%4;
//获取 CHECKBOX 的句柄
hItem = WM_GetDialogItem(hDlg,GUI_ID_CHECK0+i); (2) 
CHECKBOX_SetText(hItem,_apLabel[Index]);
switch(Index)
{
    
    
case 1: (3)
CHECKBOX_SetNumStates(hItem,3); (4)
CHECKBOX_SetImage(hItem,&_abmBar[0],\ (5)
CHECKBOX_BI_INACTIV_3STATE);
CHECKBOX_SetImage(hItem,&_abmBar[1],\ (6)
CHECKBOX_BI_ACTIV_3STATE);
CHECKBOX_SetState(hItem,2); (7)
break;
case 2: (8)
CHECKBOX_SetState(hItem,1);
CHECKBOX_SetImage(hItem,&_abmXL[0],\
CHECKBOX_BI_INACTIV_CHECKED);
CHECKBOX_SetImage(hItem,&_abmXL[1],\
CHECKBOX_BI_ACTIV_CHECKED);
CHECKBOX_SetFont(hItem,&GUI_FontComic18B_ASCII);
break;
case 3: (9)
CHECKBOX_SetState(hItem,1);
CHECKBOX_SetImage(hItem,&_abmXXL[0],\
CHECKBOX_BI_INACTIV_CHECKED);
CHECKBOX_SetImage(hItem,&_abmXXL[1],\
CHECKBOX_BI_ACTIV_CHECKED);
CHECKBOX_SetFont(hItem,&GUI_FontComic24B_ASCII);
break;
}
//失能对话框右边的所有 CHECK 小工具
if(i>=4)
{
    
    
WM_DisableWindow(hItem);
} }
break;
case WM_NOTIFY_PARENT:
Id=WM_GetId(pMsg->hWinSrc); //小工具 ID
NCode=pMsg->Data.v; //通知代码
switch(NCode)
{
    
    
case WM_NOTIFICATION_RELEASED:
if(Id==GUI_ID_OK)
{
    
    
GUI_EndDialog(hDlg,0); //关闭对话框
}
if(Id==GUI_ID_CANCEL)
{
    
    
GUI_EndDialog(hDlg,1); //关闭对话框
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
 }
 //CHECKBOX 小工具演示 Demo
void CheckBoxDemo(void)
{
    
    
GUI_CURSOR_Show();
#if GUI_SUPPORT_MEMDEV
WM_SetCreateFlags(WM_CF_MEMDEV);
#endif
WM_SetDesktopColor(GUI_BLACK);
while(1)
{
    
    
GUI_ExecDialogBox(_aDialogCreate,GUI_COUNTOF(_aDialogCreate),\
&_cbCallback,0,0,0);
GUI_Delay(500);
} }

(1) Under the WM_INIT_DIALOG message, it is used to initialize the CHECKBOX control. Because there are 8
CHECKBOX in total, it needs to be set 8 times in a loop.
(2), according to the different i get the handle of each CHECKBOX control.
(3) There are four rows of CHECKBOX gadgets, two in each row. The order of the 8 CHECKBOXes is from top to bottom and from left to right.
(4), call the CHECKBOX_SetNumStates() function to set the number of optional states of the check box. By default, the check box has 2 states, checked (1) and unchecked (0). Use the function CHECKBOX_SetNumStates() to set the possible The state is incremented to 3, and the function returns 2 if the checkbox is in the third state.
(5) . Call the function CHECKBOX_SetImage() to set the image displayed after the check box is selected. The
meaning of the third parameter of the CHECKBOX_SetImage() function is shown in the table

CHECKBOX_BI_INACTIV_UNCHECKED 设置复选框被取消选中并禁用时显示的位图。
CHECKBOX_BI_ACTIV_UNCHECKED 设置复选框被取消选中并启用时显示的位图。
CHECKBOX_BI_INACTIV_CHECKED 设置复选框被选中并禁用时显示的位图。
CHECKBOX_BI_ACTIV_CHECKED 设置复选框被选中并启用时显示的位图。
CHECKBOX_BI_INACTIV_3STATE 设置复选框处于第三种状态并禁用时显示的位图。
CHECKBOX_BI_ACTIV_3STATE 设置复选框处于第三种状态并启用时显示的位图。

Here we set the display bitmap when the second row of checkboxes is in the third state and disabled.
(6) As above, set the bitmap that the second row of checkboxes is in the third state and is displayed when enabled.
(7), call the function CHECKBOX_SetState() to set the state of the check box control, here is set to 2, that is, the third state, the allowable values ​​of the second parameter of the function CHECKBOX_SetState() are shown in Table
insert image description here
(8), set the second row Properties of the two checkboxes.
(9), set the properties of the two checkboxes in the third row.
insert image description here
I don't know what it is for the time being. I will use EMWIN to combine the Internet of Things to make an interface later.

おすすめ

転載: blog.csdn.net/qq_51963216/article/details/124068200
おすすめ