WM Widgets Don't Respong to Key Press Evets

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • WM Widgets Don't Respong to Key Press Evets

    I have created a simple window with a couple of widgets on it. I have a callback function to
    repaint the window background etc.

    I have a seperate task that reads my keypad and when a key press/release event occurs calls the
    GUI_SendKeyMsg() function to send the key event to the WM.

    If I run the project I see my window and the widgets - all fine.

    However the window manager does not seem respond to key events, the widgets don't appear to get
    the focus or respond to the UP, DOWN, ENTER or TAB keys. I can see the GUI_SendKeyMsg() is
    getting called correctly (via a breakpoint).

    If I add a breakpoint on window callback [cbForegroundWin(WM_MESSAGE* pMsg)] it never gets
    called when I press a key. I am expecting a WM_KEY event to fire.

    I am calling WM_Exec() in my UI task loop.

    Any ideas?

    (This is a ARM-RL RTOS project)
  • Numpad GUISendKey

    I am adapting the numpad example in my application. I have a Graph Window already execution after which I trigger the numpad example. The dialog and numpad loads up. All keys when typed numbers show up on the TEXT EDIT widget. When OK button is pressed I read back the number using

    C Source Code

    1. hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0); /* Get the handle of the edit widget */
    2. i = EDIT_GetValue(hItem);
    But the response I get is always 0. Please help.


    Attached my numpad modifed code


    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * Defines
    5. *
    6. **********************************************************************
    7. */
    8. //
    9. // Recommended memory to run the sample with adequate performance
    10. //
    11. #define RECOMMENDED_MEMORY (1024L * 10)
    12. /*********************************************************************
    13. *
    14. * Static data
    15. *
    16. **********************************************************************
    17. */
    18. //
    19. // End Flag
    20. //
    21. unsigned char end_dialog_flag = 0;
    22. int key_byte = 0;
    23. //
    24. // Numpad handle
    25. //
    26. WM_HWIN hNumPad;
    27. //
    28. // Array of keys
    29. //
    30. static int _aKey[] = {GUI_KEY_DELETE, GUI_KEY_TAB, GUI_KEY_LEFT, GUI_KEY_RIGHT};
    31. //
    32. // Dialog resource of numpad
    33. //
    34. static const GUI_WIDGET_CREATE_INFO _aDialogNumPad[] = {
    35. //
    36. // Function Text Id Px Py Dx Dy
    37. //
    38. { WINDOW_CreateIndirect, 0, 0, 0, 120, 240, 200},
    39. { BUTTON_CreateIndirect, "1", GUI_ID_USER + 11, 0, 0, 80, 40},
    40. { BUTTON_CreateIndirect, "2", GUI_ID_USER + 12, 80, 0, 80, 40},
    41. { BUTTON_CreateIndirect, "3", GUI_ID_USER + 13, 160, 0, 80, 40},
    42. { BUTTON_CreateIndirect, "4", GUI_ID_USER + 14, 0, 40, 80, 40},
    43. { BUTTON_CreateIndirect, "5", GUI_ID_USER + 15, 80, 40, 80, 40},
    44. { BUTTON_CreateIndirect, "6", GUI_ID_USER + 16, 160, 40, 80, 40},
    45. { BUTTON_CreateIndirect, "7", GUI_ID_USER + 17, 0, 80, 80, 40},
    46. { BUTTON_CreateIndirect, "8", GUI_ID_USER + 18, 80, 80, 80, 40},
    47. { BUTTON_CreateIndirect, "9", GUI_ID_USER + 19, 160, 80, 80, 40},
    48. { BUTTON_CreateIndirect, "0", GUI_ID_USER + 10, 0, 120, 80, 40},
    49. { BUTTON_CreateIndirect, ".", GUI_ID_USER + 20, 80, 120, 80, 40},
    50. { BUTTON_CreateIndirect, "Del", GUI_ID_USER + 21, 160, 120, 80, 40},
    51. { BUTTON_CreateIndirect, "Tab", GUI_ID_USER + 22, 0, 160, 80, 40},
    52. { BUTTON_CreateIndirect, "<", GUI_ID_USER + 23, 80, 160, 80, 40},
    53. { BUTTON_CreateIndirect, ">", GUI_ID_USER + 24, 160, 160, 80, 40},
    54. };
    55. //
    56. // Dialog resource of user dialog
    57. //
    58. static const GUI_WIDGET_CREATE_INFO _aDialogUser[] = {
    59. //
    60. // Function Text Id Px Py Dx Dy
    61. //
    62. { FRAMEWIN_CreateIndirect, "Enter SR Number", 0, 0, 0, 240, 120, FRAMEWIN_CF_MOVEABLE},
    63. { EDIT_CreateIndirect, 0, GUI_ID_EDIT0, 60, 15, 110, 20, 0, 12},
    64. { BUTTON_CreateIndirect, "Ok", GUI_ID_OK, 0, 50, 118, 40 },
    65. { BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 120, 50, 110, 40 },
    66. };
    67. /*********************************************************************
    68. *
    69. * Static code
    70. *
    71. **********************************************************************
    72. */
    73. /*********************************************************************
    74. *
    75. * _cbDialogNumPad
    76. *
    77. * Function description
    78. * Callback function of the numpad.
    79. */
    80. static void _cbDialogNumPad(WM_MESSAGE * pMsg) {
    81. GUI_RECT r;
    82. unsigned i;
    83. int NCode;
    84. unsigned Id;
    85. int Pressed;
    86. WM_HWIN hDlg;
    87. WM_HWIN hItem;
    88. Pressed = 0;
    89. hDlg = pMsg->hWin;
    90. switch (pMsg->MsgId) {
    91. case WM_PAINT:
    92. WM_GetClientRect(&r);
    93. GUI_SetColor(0x000000);
    94. GUI_DrawRect(r.x0, r.y0, r.x1, r.y1); /* Draw rectangle around it */
    95. /* Draw the bright sides */
    96. GUI_SetColor(0xffffff);
    97. GUI_DrawHLine(r.y0 + 1, r.x0 + 1, r.x1 - 2); /* Draw top line */
    98. GUI_DrawVLine(r.x0 + 1, r.y0 + 1, r.y1 - 2);
    99. /* Draw the dark sides */
    100. GUI_SetColor(0x555555);
    101. GUI_DrawHLine(r.y1-1, r.x0 + 1, r.x1 - 1);
    102. GUI_DrawVLine(r.x1-1, r.y0 + 1, r.y1 - 2);
    103. break;
    104. case WM_NOTIFY_PARENT:
    105. Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
    106. NCode = pMsg->Data.v; /* Notification code */
    107. switch (NCode) {
    108. case WM_NOTIFICATION_CLICKED:
    109. Pressed = 1;
    110. case WM_NOTIFICATION_RELEASED:
    111. if ((Id >= (GUI_ID_USER+10)) && (Id <= (GUI_ID_USER + 10 + GUI_COUNTOF(_aDialogNumPad) - 1))) {
    112. int Key;
    113. if (Id < GUI_ID_USER + 21) {
    114. char acBuffer[10];
    115. BUTTON_GetText(pMsg->hWinSrc, acBuffer, sizeof(acBuffer)); /* Get the text of the button */
    116. Key = acBuffer[0];
    117. } else {
    118. Key = _aKey[Id - GUI_ID_USER - 21]; /* Get the text from the array */
    119. }
    120. GUI_SendKeyMsg(Key, Pressed); /* Send a key message to the focussed window */
    121. }
    122. break;
    123. }
    124. default:
    125. WM_DefaultProc(pMsg);
    126. }
    127. }
    128. /*********************************************************************
    129. *
    130. * _cbDialogUser
    131. *
    132. * Purpose:
    133. * Callback function of the user dialog.
    134. */
    135. static void _cbDialogUser(WM_MESSAGE * pMsg) {
    136. int i;
    137. int NCode;
    138. int Id;
    139. WM_HWIN hDlg;
    140. WM_HWIN hItem;
    141. hDlg = pMsg->hWin;
    142. switch (pMsg->MsgId) {
    143. case WM_INIT_DIALOG:
    144. hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0); /* Get the handle of the edit widget */
    145. EDIT_SetText(hItem, ""); /* Set text */
    146. break;
    147. case WM_NOTIFY_PARENT:
    148. Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
    149. NCode = pMsg->Data.v; /* Notification code */
    150. switch (NCode) {
    151. case WM_NOTIFICATION_RELEASED: /* React only if released */
    152. if (Id == GUI_ID_OK) { /* OK Button */
    153. GUI_EndDialog(hDlg, 0);
    154. GUI_EndDialog(hNumPad,0);
    155. end_dialog_flag = 1;
    156. }
    157. if (Id == GUI_ID_CANCEL) { /* Cancel Button */
    158. GUI_EndDialog(hDlg, 1);
    159. GUI_EndDialog(hNumPad,0);
    160. }
    161. break;
    162. }
    163. break;
    164. default:
    165. WM_DefaultProc(pMsg);
    166. }
    167. }
    168. WM_HWIN CreateNumpadWindow(void);
    169. WM_HWIN CreateNumpadWindow(void) {
    170. hNumPad = GUI_CreateDialogBox(_aDialogNumPad,
    171. GUI_COUNTOF(_aDialogNumPad),
    172. _cbDialogNumPad, WM_HBKWIN, 0, 0); /* Create the numpad dialog */
    173. WM_SetStayOnTop(hNumPad, 0);
    174. do{
    175. GUI_ExecDialogBox(_aDialogUser,
    176. GUI_COUNTOF(_aDialogUser),
    177. _cbDialogUser, WM_HBKWIN, 0, 0); /* Execute the user dialog */
    178. GUI_Delay(1000);
    179. } while(end_dialog_flag == 0);
    180. return hNumPad;
    181. }
    182. /*************************** End of file ****************************/
    Display All


    Attached my maintask

    C Source Code

    1. void MainTask(void) {
    2. int j = 0;
    3. WM_HWIN hDlg;
    4. HAL_StatusTypeDef error_status = HAL_OK;
    5. hDlg = CreateWindow2();
    6. hdGraph = WM_GetDialogItem(hDlg,ID_GRAPH_0);
    7. hdProgressBar = WM_GetDialogItem(hDlg,ID_PROGBAR_0);
    8. hdStatusMessage = WM_GetDialogItem(hDlg,ID_TEXT_0);
    9. char debug_print[30] = {0};
    10. GUI_Delay(20);
    11. for (int i = 0; i < 30; i++) {
    12. aY[i] = 0;
    13. }
    14. for (int i = 30; i < 160; i++) {
    15. aY[i] = 125;
    16. }
    17. for (int i = 160; i < GUI_COUNTOF(aY); i++) {
    18. aY[i] = 0;
    19. }
    20. for (int i = 0; i < 25; i++) {
    21. aZ[i] = 0;
    22. }
    23. for (int i = 25; i < 150; i++) {
    24. aZ[i] = 110;
    25. }
    26. for (int i = 150; i < GUI_COUNTOF(aY); i++) {
    27. aZ[i] = 0;
    28. }
    29. while (1) {
    30. MX_USB_HOST_Process(); //polls usb of insertion or removal of pendrive
    31. hYData = GRAPH_DATA_YT_Create(GUI_DARKGREEN, GUI_COUNTOF(aY), aY,
    32. GUI_COUNTOF(aY));
    33. GRAPH_AttachData(hdGraph, hYData);
    34. hZData = GRAPH_DATA_YT_Create(GUI_LIGHTYELLOW, GUI_COUNTOF(aZ), aZ,
    35. GUI_COUNTOF(aZ));
    36. GRAPH_AttachData(hdGraph, hZData);
    37. GUI_Delay(50);
    38. MX_USB_HOST_Process();
    39. GRAPH_DetachData(hdGraph, hYData);
    40. GRAPH_DetachData(hdGraph, hZData);
    41. GRAPH_DATA_YT_Delete(hYData);
    42. GRAPH_DATA_YT_Delete(hZData);
    43. if(pendrive_attached_flag) { ///// WM_HideWindow(hDlg);
    44. CreateNumpadWindow();
    45. // TEXT_SetText(hdStatusMessage, "Pendrive Connected");
    46. // GUI_Delay(5);
    47. //// append_file("1,Success,\r\n",12);
    48. // error_status = update_file();
    49. // WM_ShowWindow(hDlg);
    50. }
    51. PROGBAR_SetValue(hdProgressBar, j);
    52. if (j == 100) {
    53. j = 0;
    54. } else {
    55. j += 5;
    56. }
    57. }
    58. }
    Display All
    </if>

    The post was edited 2 times, last by kashyap.gada ().