static char * _apExplain[] =
{
"This sample shows how to use edit widgets with a",
"user defined callback function and how to set a",
"user defined AddKey function. It selects the",
"contents of the edit field on receiving the focus",
"and overwrites the contents if a key other than",
"a cursor key is pressed.",
};
switch (pMsg->MsgId)
{
case WM_INIT_DIALOG:
FRAMEWIN_SetFont(pMsg->hWin, &GUI_Font13_ASCII);
FRAMEWIN_SetTextAlign(pMsg->hWin, GUI_TA_HCENTER);
for (i = 0; i < 2; i++)
{
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0 + i); // Get the handle of the edit widget
//EDIT_AddKey(hItem, GUI_KEY_ADD);//向指定的编辑字段(Edit窗口)添加用户输入。EDIT_AddKey(hItem, 'A');
EDIT_SetText(hItem, "Hello world!"); // Fill widget with text
//很奇怪,会选中第一个文本框(hItem=5),而不是第二(hItem=A)个!
EDIT_SetSel(hItem, 0, -1); // Select the whole contents of the edit field 选定的字符通常反色显示
//EDIT_SetSel((WM_HWIN)0xA, 0, -1); // 失败
}
break;
case WM_KEY://对话框接受按键事件,当焦点在文本框,按键触发的不同Key值,如果是有效输入key,对话框收到38消息;如果是无效,将是WM_KEY消息
switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key)
{
case 0x41://文本框能接受的输入字数有限,后面再按,文本框没反应,对话框也收不到38消息
printf("_cbDialog 0x41 Key2\r\n");//焦点在行文本框,不会执行,是个有效Key(输入A)。对话框收到38消息
//GUI_EndDialog(hDlg, 1);
break;
case 0x61://文本框能接受的输入字数有限,后面再按,文本框没反应,对话框也收不到38消息
printf("_cbDialog 0x61 KeyUp\r\n");//焦点在行文本框,不会执行,是个有效Key(输入a)。对话框收到38消息
//GUI_EndDialog(hFrame, 0);
break;
case GUI_KEY_ESCAPE:
printf("_cbDialog GUI_KEY_ESCAPE key1\r\n"); //焦点在行文本框,会执行,是个无效Key。对话框收到14消息
//GUI_EndDialog(hDlg, 1);
break;
case GUI_KEY_ENTER:
printf("_cbDialog GUI_KEY_ENTER key0\r\n"); //焦点在行文本框,会执行,是个无效Key。对话框收到14消息
//GUI_EndDialog(hDlg, 0);
break;
}
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); // Id of widget
NCode = pMsg->Data.v; // Notification code
switch (NCode)
{
case WM_NOTIFICATION_RELEASED: // React only if released
if (Id == GUI_ID_OK)
{ // OK Button
GUI_EndDialog(hDlg, 0);
}
if (Id == GUI_ID_CANCEL)
{ // Cancel Button
GUI_EndDialog(hDlg, 1);
}