请教STemWin实体按键如何传入驱动API?

2019-12-19 18:13发布

本帖最后由 styleno1 于 2014-5-22 11:59 编辑

汗颜,手册上愣是没找到明白的说明。

请各位一键点破!

思路说明:

一个进程键盘检测,一个进程GUI_Exec(),按下按键,发出键值,GUI进程调用初始化传递的Callback响应。

编辑说明:补充
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
10条回答
styleno1
2019-12-20 07:34

  1. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] =
  2. {
  3.         { FRAMEWIN_CreateIndirect, "Edit winmode", 0,         90,  90, 140, 130, FRAMEWIN_CF_MOVEABLE},
  4.         { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT0,    10,  10, 110,  20, 0, 15},
  5.         { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT1,    10,  40, 110,  20, 0, 15},
  6.         { BUTTON_CreateIndirect,   "Ok",     GUI_ID_OK,       10,  80,  50,  20 },
  7.         { BUTTON_CreateIndirect,   "Cancel", GUI_ID_CANCEL,   70,  80,  50,  20 },
  8. };
复制代码

回调函数:
  1. static void _cbDialog(WM_MESSAGE * pMsg)
  2. {
  3.         int     i;
  4.         int     NCode;
  5.         int     Id;
  6.         WM_HWIN hDlg;
  7.         WM_HWIN hItem;

  8.         hDlg = pMsg->hWin;
  9.         switch (pMsg->MsgId)
  10.         {
  11.                 case WM_INIT_DIALOG:
  12.                         FRAMEWIN_SetFont(pMsg->hWin, &GUI_Font13_ASCII);
  13.                         FRAMEWIN_SetTextAlign(pMsg->hWin, GUI_TA_HCENTER);
  14.                         for (i = 0; i < 2; i++)
  15.                         {
  16.                                 hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0 + i);  // Get the handle of the edit widget
  17.                                 EDIT_AddKey(hItem, GUI_KEY_ADD);
  18.                                 EDIT_SetText(hItem, "Hello world!");             // Fill widget with text
  19.                                 EDIT_SetSel(hItem, 0, -1);                       // Select the whole contents of the edit field
  20.                         }
  21.                         break;
  22.                  case WM_KEY:
  23.             switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key)
  24.             {
  25.                                 case GUI_KEY_ESCAPE:
  26.                     GUI_EndDialog(hDlg, 1);
  27.                     break;
  28.                                
  29.                 case GUI_KEY_ENTER:
  30.                     GUI_EndDialog(hDlg, 0);
  31.                     break;
  32.             }
  33.             break;
  34.                 case WM_NOTIFY_PARENT:
  35.                         Id    = WM_GetId(pMsg->hWinSrc);      // Id of widget
  36.                         NCode = pMsg->Data.v;                 // Notification code
  37.                         switch (NCode)
  38.                         {
  39.                                 case WM_NOTIFICATION_RELEASED:      // React only if released
  40.                                         if (Id == GUI_ID_OK)
  41.                                         {         // OK Button
  42.                                                 GUI_EndDialog(hDlg, 0);
  43.                                         }
  44.                                         if (Id == GUI_ID_CANCEL)
  45.                                         {        // Cancel Button
  46.                                                 GUI_EndDialog(hDlg, 1);
  47.                                         }
  48.                                        
  49.                                         break;
  50.                         }
  51.                         break;
  52.                 default:
  53.                         WM_DefaultProc(pMsg);
  54.         }
  55. }
复制代码

任务循环代码:
  1. GUI_Delay(10);
复制代码

按键发送:
  1. GUI_SendKeyMsg(GUI_KEY_ESCAPE, 1);
复制代码

补充描述:

发送按键,没有触发回调函数:WM_KEY。

一周热门 更多>