STM32 - EMWIN DROPDOWN control (17)

EMWI

foreword

The DROPDOWN widget is used to select an element from a list with several columns. It displays the currently selected item in a non-open state. If the user opens the DROPDOWN widget, a LISTBOX for selecting a new item appears

1. Introduction to the DROPDOWN control

The DROPDOWN controls are shown in Figures 16.1.1 and 16.1.2 respectively when open and closed
insert image description here
insert image description here

2. Notification code

The following table lists the types of messages that the DROPDOWN 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_SCROLL_CHANGED
已打开的下拉列表小工具的可选滚动条的滚动位置已改变。
WM_NOTIFICATION_SEL_CHANGED 下拉列表的选择已更改。

3. Keyboard response

If the DROPDWON control has input focus, it will react to the following keys:

GUI_KEY_ENTER 从打开的下拉列表中选择项目,然后关闭列表。
GUI_KEY_SPACE 打开下拉列表

4. DROPDOWN control API function

DROPDOWN_AddString() 给 DROPDOWN 列表添加元素。
DROPDOWN_Collapse() 关闭下拉列表。
DROPDOWN_Create() 创建 DROPDOWN 小工具。
DROPDOWN_CreateEx() 创建 DROPDOWN 小工具。
DROPDOWN_CreateIndirect() 从资源表项创建 DROPDOWN 小工具。
DROPDOWN_CreateUser() 使用额外字节作为用户数据创建 DROPDOWN 小工具。
DROPDOWN_DecSel() 减小选定范围。
DROPDOWN_DecSelExp() 递减处于展开状态的选取项。
DROPROWN_DeleteItem() 删除 DROPDOWN 列表的项目。
DROPDOWN_Expand() 打开下拉列表。
DROPDOWN_GetDefaultFont() 返回用于创建 DROPDOWN 小工具的默认字体。
DROPDOWN_GetItemDisabled() 返回给定项目的状态。
DROPDOWN_GetListbox() 返回处于展开状态的附加 DROPDOWN 的句柄
DROPDOWN_GetNumItems() 返回下拉列表中项目的数量。
DROPDOWN_GetSel() 返回当前选定元素的数量。
DROPDOWN_GetSelExp() 返回处于展开状态的当前选定元素的数量。
DROPDOWN_GetUserData() 检索使用 DROPDOWN_SetUserData()设置的数据
DROPDOWN_IncSel() 增加选定范围。
DROPDOWN_IncSelExp() 递增处于展开状态的选取项。
DROPDOWN_SetAutoScroll() 启用在下拉列表中自动使用滚动条。
DROPDOWN_SetBkColor() 设置背景颜色。
DROPDOWN_SetColor() 设置 DROPDWON 小工具的箭头和按钮的颜色。
DROPDOWN_SetDefaultColor() 设置 DROPDWON 小工具的箭头和按钮的默认颜色。
DROPDOWN_SetDefaultFont() 设置 DROPDWON 小工具的默认字体。
DROPDOWN_SetDefaultScrollbarColor() 设置下拉列表中可选滚动条的默认颜色。
DROPDOWN_SetFont() 设置给定 DROPDWON 小工具的字体。
DROPDOWN_SetItemDisabled() 设置给定项目的状态。
DROPDOWN_SetItemSpacing() 设置下拉列表中各项目之间的间距。
DROPDOWN_SetScrollbarColor() 设置下拉列表中滚动条的颜色。
DROPDOWN_SetSel() 设置当前选定内容。
DROPDOWN_SetSelExp() 设置处于展开状态的当前选择。
DROPDOWN_SetTextAlign() 设置用于显示关闭状态下拉文本的对齐方式。
DROPDOWN_SetTextColor() 设置给定 DROPDWON 小工具的文本颜色。
DROPDOWN_SetTextHeight() 设置用于显示关闭状态下拉文本的矩形的高度。
DROPDOWN_SetUserData() 设置 DROPDWON 小工具的额外数据。

Five, DROPDOWN control demonstration routine

#include "dropdowndemo.h"
#include "DIALOG.h"
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x02)
#define ID_DROPDOWN_0 (GUI_ID_USER + 0x04)
//对话框资源表
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = 
{
    
    
{
    
     FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 320, 240, 
FRAMEWIN_CF_MOVEABLE, 0x64, 0 },
{
    
     DROPDOWN_CreateIndirect, "Dropdown", ID_DROPDOWN_0, 88, 24, 109, 60, 0, 0x0, 0 },
};
//对话框回调函数
static void _cbDialog(WM_MESSAGE * pMsg) 
{
    
    
WM_HWIN hItem;
int NCode;
int Id;
switch (pMsg->MsgId) 
{
    
    
case WM_INIT_DIALOG:
hItem = pMsg->hWin;
//初始化 FRAMEWIN
FRAMEWIN_SetText(hItem, "DROPDOWN ");
FRAMEWIN_SetFont(hItem, GUI_FONT_16_ASCII);
FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
//初始化 DROPDOWN
hItem = WM_GetDialogItem(pMsg->hWin, ID_DROPDOWN_0);
DROPDOWN_SetFont(hItem, GUI_FONT_13H_ASCII); (1)
DROPDOWN_SetAutoScroll(hItem,1);//启用自动使用滚动条 (2)
DROPDOWN_AddString(hItem, "China"); (3)
DROPDOWN_AddString(hItem, "Cambodia");
DROPDOWN_AddString(hItem, "Japan");
DROPDOWN_AddString(hItem, "Australien");
DROPDOWN_AddString(hItem, "Canada");
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) 
{
    
    
case ID_DROPDOWN_0: //DROPDOWN 通知代码
switch(NCode) 
{
    
    
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_SEL_CHANGED:
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
} 
}
//创建对话框
void dropdown_demo(void) 
{
    
    
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, 
WM_HBKWIN, 0, 0);
while(1)
{
    
    
GUI_Delay(100);
} 
}

(1), set the font of the DROPDOWN control.
(2), enable the DROPDOWN control to automatically use the scroll bar function, so that when there are too many items in the control, a scroll bar will appear.
(3), add a new element to the DROPDOWN control. This routine is relatively simple. Segger officially provides a DROPDOWN routine: WIDGET_Dropdown.c. You can use the simulator to simulate and run this routine. This routine shows the use of DROPDOWN API functions in detail.
insert image description here

Guess you like

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