首页 > 代码库 > [ucgui] 对话框2——小窗口初始化与消息响应

[ucgui] 对话框2——小窗口初始化与消息响应

 

>_<" 上一节已经说过,创建过得窗口虽然可见,但是它们是以 “空”的形式出现的。这是因为对话框过程函数尚未包含初始化单个元素的代码。小工具的初始值、由它们所引起的行为以及它们之间的交互作用都需要在对话框过程中进行定义。这里在过程函数的WM_INIT_DIALOG消息下实现对小窗口初始化,然后在WM_NOTIFY_PARENT消息下实现对小工具的响应~

 1 /********************************************************************* 2 * 3 对话框可以基于阻塞(使用GUI_ExecDialogBox())或非阻塞(使用GUI_CreateDialogBox()) 4 方式创建。必须首先定义一个资源表,以指定在对话框中所要包括的所有小工具。下面的示例说明了创 5 建资源表的方法: 6 对话框中所要包括的任何小工具都必须使用<WIDGET>_CreateIndirect()函数来间接创建。 7 */ 8 static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { 9     { FRAMEWIN_CreateIndirect, "Dialog", 0, 10, 10, 180, 230, FRAMEWIN_CF_MOVEABLE, 0 },10     { BUTTON_CreateIndirect, "OK", GUI_ID_OK, 100, 5, 60, 20 },11     { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 100, 30, 60, 20 },12     { TEXT_CreateIndirect, "LText", 0, 10, 55, 48, 15, TEXT_CF_LEFT },13     { TEXT_CreateIndirect, "RText", 0, 10, 80, 48, 15, TEXT_CF_RIGHT },14     { EDIT_CreateIndirect, NULL, GUI_ID_EDIT0, 60, 55, 100, 15, 0, 50 },15     { EDIT_CreateIndirect, NULL, GUI_ID_EDIT1, 60, 80, 100, 15, 0, 50 },16     { TEXT_CreateIndirect, "Hex", 0, 10, 100, 48, 15, TEXT_CF_RIGHT },17     { EDIT_CreateIndirect, NULL, GUI_ID_EDIT2, 60, 100, 100, 15, 0, 6 },18     { TEXT_CreateIndirect, "Bin", 0, 10, 120, 48, 15, TEXT_CF_RIGHT },19     { EDIT_CreateIndirect, NULL, GUI_ID_EDIT3, 60, 120, 100, 15 },20     { LISTBOX_CreateIndirect, NULL, GUI_ID_LISTBOX0,10, 10, 48, 40 },21     { CHECKBOX_CreateIndirect, NULL, GUI_ID_CHECK0, 10, 140, 0, 0 },22     { CHECKBOX_CreateIndirect, NULL, GUI_ID_CHECK1, 30, 140, 0, 0 },23     { SLIDER_CreateIndirect, NULL, GUI_ID_SLIDER0, 60, 140, 100, 20 },24     { SLIDER_CreateIndirect, NULL, GUI_ID_SLIDER1, 10, 170, 150, 30 }25 };26 /*********************************************************************27 *28 对话框过程函数29 */30 static void _cbCallback(WM_MESSAGE * pMsg) {31     int NCode, Id;32     static const GUI_ConstString _apListBox[] = {  //ListBox contant33             "English", "Deutsch", "Fran?ais", "Japanese", "Italiano", NULL34     };35     WM_HWIN hEdit0, hEdit1, hEdit2, hEdit3, hListBox;36     WM_HWIN hWin = pMsg->hWin;37     switch (pMsg->MsgId) {38     /*用它们各自的初始值对小工具进行初始化。在对话框过程函数中,这是对WM_INIT_DIALOG39     消息做出反应时的通常做法*/40     case WM_INIT_DIALOG:41         /* Get window handles for all widgets */42         hEdit0 = WM_GetDialogItem(hWin, GUI_ID_EDIT0);43         hEdit1 = WM_GetDialogItem(hWin, GUI_ID_EDIT1);44         hEdit2 = WM_GetDialogItem(hWin, GUI_ID_EDIT2);45         hEdit3 = WM_GetDialogItem(hWin, GUI_ID_EDIT3);46         hListBox = WM_GetDialogItem(hWin, GUI_ID_LISTBOX0);47         /* Initialize all widgets */48         EDIT_SetText(hEdit0, "EDIT widget 0");49         EDIT_SetText(hEdit1, "EDIT widget 1");50         EDIT_SetTextAlign(hEdit1, GUI_TA_LEFT);51         EDIT_SetHexMode(hEdit2, 0x1234, 0, 0xffff);52         EDIT_SetBinMode(hEdit3, 0x1234, 0, 0xffff);53         LISTBOX_SetText(hListBox, _apListBox);54         WM_DisableWindow (WM_GetDialogItem(hWin, GUI_ID_CHECK1));55         CHECKBOX_Check( WM_GetDialogItem(hWin, GUI_ID_CHECK0));56         CHECKBOX_Check( WM_GetDialogItem(hWin, GUI_ID_CHECK1));57         SLIDER_SetWidth( WM_GetDialogItem(hWin, GUI_ID_SLIDER0), 5);58         SLIDER_SetValue( WM_GetDialogItem(hWin, GUI_ID_SLIDER1), 50);59         break;60     /*告知父窗口,其子窗口中发生了某些改变。上面是小工具的初始化,下面是过程中变化的处理*/61     case WM_NOTIFY_PARENT:62         Id = WM_GetId(pMsg->hWinSrc); /* Id of widget 获得小工具的ID*/63         NCode = pMsg->Data.v; /* Notification code 通知消息代号*/64         switch (NCode) {65         case WM_NOTIFICATION_RELEASED:/* React only if released 此通知消息将在被点击的小工具已被释放时发送。*/66             if (Id == GUI_ID_OK) { /* OK Button */67                 GUI_EndDialog(hWin, 0);68             }69             if (Id == GUI_ID_CANCEL) { /* Cancel Button */70                 GUI_EndDialog(hWin, 1);71             }72             break;73         case WM_NOTIFICATION_SEL_CHANGED:/* Selection changed 此通知消息将在小工具选择已更改时发送。*/74             FRAMEWIN_SetText(hWin, "Dialog - sel changed");75             break;76         default:77             FRAMEWIN_SetText(hWin, "Dialog - notification received");78         }79         break;80     default:81     WM_DefaultProc(pMsg);82     }83 }84 /*********************************************************************85 *86 * MainTask87 */88 void Fun(void) {89     //对于该示例,对话框显示时会有下列代码行:90     GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),&_cbCallback, 0, 0, 0);91 }

 

[ucgui] 对话框2——小窗口初始化与消息响应