[SOLVED]Child window: NOTIFICATION RELEASED

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

    • [SOLVED]Child window: NOTIFICATION RELEASED

      HI,

      I am working on Multiple windows and have problems being able to get it to function correctly. I hope someone here can guide me.
      1. I have two windows currently.
      2. Window 1- Parent window with a settings button.
      3. Pressing the settings button opens up child window.
      4. Window 2- Child window consists of three buttons.

      Question: I am pressing the button in child window, I don't understand how to control this? where will the control be passed to? Parent window? or the WM_NOTIFICATION_RELEASED in the child window? I have tried both of these and don't seem to understand what's going on.

      I have seen sample codes where there is only one button and reaction to the touch of the button changes the text on the button. Did not have any luck while I followed the same logic. I am also attaching the code I am currently working on.

      C Source Code

      1. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      2. extern void DrawBMPExternalMemory();
      3. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] =
      4. {
      5. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0},
      6. { BUTTON_CreateIndirect, "Tools", GUI_ID_BUTTON5, 50, 193, 40, 40, 0, 0, 0 },
      7. };
      8. /*********************************************************************
      9. * Tools Callback
      10. **********************************************************************/
      11. static void _cbTools(WM_MESSAGE * pMsg)
      12. {
      13. switch (pMsg->MsgId)
      14. {
      15. case WM_PAINT:
      16. if(BUTTON_IsPressed(pMsg->hWin))
      17. {
      18. DrawBMPExternalMemory("GearDown.bmp");
      19. }
      20. else
      21. {
      22. DrawBMPExternalMemory("GearUp.bmp");
      23. }
      24. break;
      25. default:
      26. BUTTON_Callback(pMsg); // The original callback
      27. break;
      28. }
      29. }
      30. static void _cbCreateToolsScreen(WM_MESSAGE * pMsg)
      31. {
      32. BUTTON_Handle hButton1, hButton2, hButton3;
      33. int NCode;
      34. int Id;
      35. WM_HWIN hDlg;
      36. WM_PID_STATE_CHANGED_INFO * pInfo;
      37. hDlg = pMsg->hWin;
      38. switch (pMsg->MsgId)
      39. {
      40. case WM_CREATE:
      41. hButton1 = BUTTON_CreateEx(25, 50, 220, 45, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_BUTTON8);
      42. BUTTON_SetText(hButton1, "O2 Cell calibration");
      43. hButton2 = BUTTON_CreateEx(25, 110, 220, 45, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_BUTTON9);
      44. BUTTON_SetText(hButton2, "TouchScreen calibration");
      45. break;
      46. case WM_PAINT:
      47. //
      48. // Draw the background. This is quite important because otherwise we would still see the child window although it gets deleted.
      49. // With this drawing the background wouldn't "know" how to draw itself.
      50. //
      51. GUI_SetBkColor(GUI_BLACK);
      52. GUI_Clear();
      53. break;
      54. case WM_PID_STATE_CHANGED:
      55. Id = WM_GetId(pMsg->hWinSrc);
      56. NCode = pMsg->Data.v;
      57. switch (NCode)
      58. {
      59. pInfo = (WM_PID_STATE_CHANGED_INFO *)pMsg->Data.p;
      60. if (pInfo)
      61. {
      62. GUI_DispStringAt("Pressed", 10,10);
      63. if(Id == GUI_ID_BUTTON8)
      64. {
      65. GUI_SetBkColor(GUI_RED);
      66. }
      67. }
      68. }
      69. break;
      70. // USER START (Optionally insert additional message handling)
      71. // USER END
      72. default:
      73. WM_DefaultProc(pMsg);
      74. break;
      75. }
      76. }
      77. /*********************************************************************
      78. *
      79. * _cbDialog
      80. */
      81. static void _cbDialog(WM_MESSAGE * pMsg)
      82. {
      83. static WM_HWIN hWin;
      84. WM_HWIN hItem;
      85. int NCode;
      86. int Id;
      87. BUTTON_Handle hButton;
      88. TEXT_Handle hText1;
      89. TEXT_Handle hText2;
      90. hItem = pMsg -> hWin;
      91. switch (pMsg->MsgId)
      92. {
      93. case WM_INIT_DIALOG:
      94. WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(GUI_BEIGE_BACKGROUND));
      95. break;
      96. case WM_NOTIFY_PARENT:
      97. Id = WM_GetId(pMsg->hWinSrc);
      98. NCode = pMsg->Data.v;
      99. switch (NCode)
      100. {
      101. case WM_NOTIFICATION_RELEASED: // React only if released
      102. hItem = WM_GetDialogItem(pMsg->hWin, ID_WINDOW_0);
      103. if(Id == GUI_ID_BUTTON5)// ToolsScreen
      104. {
      105. hWin = WM_CreateWindowAsChild(0, 0, 320, 240, pMsg->hWin, WM_CF_SHOW, _cbCreateToolsScreen, 0);
      106. }
      107. }
      108. break;
      109. default:
      110. WM_DefaultProc(pMsg);
      111. }
      112. }
      113. /*********************************************************************
      114. *
      115. * Public code
      116. *
      117. **********************************************************************
      118. */
      119. /*********************************************************************
      120. *
      121. * MainTask
      122. */
      123. void BitmapOnButton(void)
      124. {
      125. //
      126. // Use memory devices for all windows
      127. //
      128. #if GUI_SUPPORT_MEMDEV
      129. WM_SetCreateFlags(WM_CF_MEMDEV);
      130. WM_EnableMemdev(WM_HBKWIN);
      131. #endif
      132. WM_SetDesktopColor(GUI_BLACK);
      133. while (1)
      134. {
      135. GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbDialog, 0, 0, 0);
      136. GUI_Delay(10);
      137. }
      138. }
      139. /*************************** End of file ****************************/
      Display All

      Really appreciate any help at this point.

      Best regards,
      BMD
    • Hi,

      WM_NOTIFY_PARENT messages will always be sent to the widget's parent window. So if a button gets clicked, the WM_NOTIFY_PARENT message goes to the button's parent.

      You can then check the pMsg->Data.v value for the notification code. For example, if it is WM_NOTIFICATION_RELEASED, it means a click on that widget has been released.

      I've attached a simple example that demonstrates this, hopefully this will help you understand the mechanism better.

      Best regards,

      Florian
      Files
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Hi Florian,

      Thank you for the quick response.
      I am unable to see what's in the file you attached. It's a different extension I have never seen before. Could you please check and send it again.

      Best Regards,
      BMD
    • Hi,

      .zip should work for you.

      Best regards,

      Florian
      Files
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.