No response to WM_KEY after change to window design

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

    • No response to WM_KEY after change to window design

      Hi All,

      I have small program which has been working fine, it consists of 6 windows, whose opening and closing is controlled by custom touch buttons and using GUI_StoreKeyMsg.
      The windows now contain no buttons but listbox and text information which are controlled by external switches. From I have determined it appears to Focus problem, WM_KEY is not getting fired. Please what is the simplest way to resolve this

      Kind Regards

      MikeZ
    • Hi Sven,

      Thanks for your response. I had just added button which did nothing more than deselect the Listbox and program now worked as before, closing and opening a new window. I can alter the item selected in the Listbox, which I am doing with an external switch, but i should manually de-focus it before sending the key messages. Would the latter do the job of the deselect Listbox button I added. What commands are used for setting focus manually? thanks.

      Kind Regards

      MikeZ
    • Hi Sven,

      I do not know how to manually unfocus the list box without the redundant Button, with the Button I can use the command BUTTON_SetFocussable()
      before sending the key messages, but it is not pretty. Is there an equivalent command for the Listbox.

      Kind Regards

      MikeZ
    • Hi,

      You can also send the WM_KEY message directly to a window/widget. This way you dont't have to bother about focus.

      Try the example below. There I have created a listbox and set up a message which gets send to the LISTBOX. The Data.p member of the message struct points to a WM_KEY_INFO structure which holds information about the key beeing pressed. You should make sure that after every pressed event (PressedCnt == 1) a release event has to occur. Either send it directly after the pressed event or when the hardware button gets released.

      C Source Code

      1. #include "DIALOG.h"
      2. #include <stdio.h>
      3. /*********************************************************************
      4. *
      5. * Static data
      6. *
      7. **********************************************************************
      8. */
      9. static const char * _apString[] = {
      10. "Item 0",
      11. "Item 1",
      12. "Item 2",
      13. "Item 3",
      14. "Item 4",
      15. "Item 5",
      16. "Item 6",
      17. "Item 7",
      18. "Item 8",
      19. "Item 9",
      20. "Item 10",
      21. "Item 11",
      22. "Item 12",
      23. "Item 13",
      24. "Item 14",
      25. "Item 15",
      26. NULL
      27. };
      28. /*********************************************************************
      29. *
      30. * Static code
      31. *
      32. **********************************************************************
      33. */
      34. /*********************************************************************
      35. *
      36. * _cbBk
      37. */
      38. static void _cbBk(WM_MESSAGE * pMsg) {
      39. switch (pMsg->MsgId) {
      40. case WM_PAINT:
      41. GUI_SetBkColor(GUI_BLACK);
      42. GUI_Clear();
      43. break;
      44. default:
      45. WM_DefaultProc(pMsg);
      46. break;
      47. }
      48. }
      49. /*********************************************************************
      50. *
      51. * Public code
      52. *
      53. **********************************************************************
      54. */
      55. /*********************************************************************
      56. *
      57. * MainTask
      58. */
      59. void MainTask(void) {
      60. WM_MESSAGE Message;
      61. WM_KEY_INFO Info;
      62. WM_HWIN hListbox;
      63. GUI_Init();
      64. WM_MULTIBUF_Enable(1);
      65. WM_SetCallback(WM_HBKWIN, _cbBk);
      66. hListbox = LISTBOX_CreateEx(10, 10, 80, 120, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTBOX0, _apString);
      67. Message.Data.p = &Info;
      68. Message.hWin = hListbox;
      69. Message.hWinSrc = 0;
      70. Message.MsgId = WM_KEY;
      71. while (1) {
      72. GUI_Delay(1000);
      73. Info.Key = GUI_KEY_DOWN;
      74. Info.PressedCnt = 1;
      75. WM_SendMessage(hListbox, &Message);
      76. Info.PressedCnt = 0;
      77. WM_SendMessage(hListbox, &Message);
      78. }
      79. }
      80. /*************************** End of file ****************************/
      Display All
      Regards,
      Sven
    • Hi Sven,

      Thanks for your response, I will try it out. I am very new to this type so still learning, the messages from the external touch buttons are to close the current window and open new one, what you are proposing is send to message to the Listview widget and process it in its callback function, am I correct in the this interpretation?

      Kind Regards

      MikeZ
    • Hi Sven/All,

      Just to add little to my last message, it appears that the list box is not getting re-drawn incorrectly and appears blacked out , even so pressing one of the current external touch buttons the window changes to correct one in all cases. I created the windows in GUIBuilder. I have tested the custom Listbox callback on one window only, the rest of the window is drawn correctly. The custom callback only handles the WM_CODE and WM_IMAGE (not sure of WM_IMAGE details), I figured that all other LISTBOX activities would be handled by the main callback function of the window by default.

      if anyone sees anyone sees anything glaringly obvious wrong or missing feel free to point it out.

      Kind Regards

      MikeZ

      My custom callback is as follows:

      static void _cbBk(WM_MESSAGE * pMsg) {
      switch (pMsg->MsgId) {
      case WM_PAINT:
      GUI_SetBkColor(GUI_BLACK); // This and the following line have made no difference to outcome
      GUI_Clear();
      break;
      case WM_KEY:
      switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) {
      case win1Code:// window1
      //OpenWindow1();
      RED_LED_TOGGLE();
      break;
      case win2Code:// window2
      BLUE_LED_TOGGLE();
      GUI_EndDialog(pMsg->hWin, 0);
      OpenWindow2();
      break;
      case win3Code:// window3
      BLUE_LED_TOGGLE();
      GUI_EndDialog(pMsg->hWin, 0);
      OpenWindow3();
      break;
      case win4Code:// window4
      BLUE_LED_TOGGLE();
      GUI_EndDialog(pMsg->hWin, 0);
      openWindow4();
      break;
      case win5Code: // window5
      BLUE_LED_TOGGLE();
      GUI_EndDialog(pMsg->hWin, 0);
      OpenWindow5();
      break;
      }
      break;
      default:
      //_cbDialog(pMsg);
      WM_DefaultProc(pMsg);
      break;
      }

      setup using WM_SetCallback(hItem, _cbBk); where hitem is the handle to the list box.
    • Hi Sven/All,

      I sorted out the problem, I had misunderstood the process of setting up a custom callback and all the steps involved. There is an excellent related example on the forum CloseDropdownOnEscape.c that is very helpful together with the relevant section in the user manual.

      Kind Regards

      MikeZ