Multiple windows handling on button click event

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

    • Multiple windows handling on button click event

      I am able to create different dialog boxes but what I am trying to do is that I need to create 2 windows and when I press the button in window 1 then window 2 should be displayed and vice-versa. I went through example codes but could not find anything that does what I want. Any help would be appreciated.
    • Hi,

      Something like this (attached)?

      I create one window with a button. On button release I create a second window and delete the first. The second window has also a button. On press I create the first one again and delete the second one.

      Regards,
      Sven
      Files
      • Example.zip

        (753 Byte, downloaded 472 times, last: )
      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.
    • This works fine but what I am trying to do is following:

      1. My display is 640x480 and I want to create first page (GUI_BLUE) with full display size. A button on this page, when pressed, would take me to another page (GUI_RED).
      2. Button on second page, when pressed, takes me back to the BLUE page.

      Can this be achieved by WM_SetFocus() when button is pressed?

      Since the display size is 640x480, I think I would have to create a display of XSize 640*2. I am not sure about this though.
    • I have attached my code as well as output after making some changes to your code.

      When I debug this code, I get the following result:

      1. The code starts with the display showing a small red window with the button named "Select Win2".
      2. When I press "Select Win2" button, I get a green window (fully covers the display since I have passed LCD_GetXSize() and LCD_GetYSize() as arguments) with a button named "Select Win1".
      3. When I press "Select Win1" button, I get a red window which again fully covers the display due to the above mentioned reason.
      4. The display then toggles between these red and green windows on button press.

      This is not what I want.

      I want the code to display a window with "Select Win2" button as my starting point. Then the windows should change on button press. I hope I am clear with my end result.
      Images
      • Output.jpg

        536.18 kB, 2,826×2,120, viewed 455 times
      Files
      • ButtonPress.7z

        (859 Byte, downloaded 453 times, last: )
    • C Source Code

      1. #include "DIALOG.h"
      2. /*********************************************************************
      3. *
      4. * Externals
      5. *
      6. **********************************************************************
      7. */
      8. /*********************************************************************
      9. *
      10. * Types
      11. *
      12. **********************************************************************
      13. */
      14. static void _cbWinB(WM_MESSAGE * pMsg);
      15. static void _cbWinC(WM_MESSAGE * pMsg);
      16. /*********************************************************************
      17. *
      18. * Defines
      19. *
      20. **********************************************************************
      21. */
      22. /*********************************************************************
      23. *
      24. * Static data
      25. *
      26. **********************************************************************
      27. */
      28. /*********************************************************************
      29. *
      30. * Static code
      31. *
      32. **********************************************************************
      33. */
      34. /*********************************************************************
      35. *
      36. * _cbWinA
      37. */
      38. static void _cbWinA(WM_MESSAGE * pMsg) {
      39. int NCode;
      40. int Id;
      41. BUTTON_Handle hButton;
      42. GUI_RECT Rect;
      43. switch (pMsg->MsgId) {
      44. case WM_CREATE:
      45. hButton = BUTTON_CreateEx(10, 10, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
      46. BUTTON_SetText(hButton, "Go To Page 2");
      47. break;
      48. case WM_NOTIFY_PARENT:
      49. Id = WM_GetId(pMsg->hWinSrc);
      50. NCode = pMsg->Data.v;
      51. switch(Id) {
      52. case GUI_ID_BUTTON0:
      53. switch(NCode) {
      54. case WM_NOTIFICATION_RELEASED:
      55. WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWinB, 0);
      56. WM_DeleteWindow(pMsg->hWin);
      57. break;
      58. }
      59. break;
      60. }
      61. break;
      62. case WM_PAINT:
      63. GUI_SetBkColor(GUI_RED);
      64. GUI_SetColor(GUI_BLACK);
      65. GUI_Clear();
      66. GUI_SetFont(GUI_FONT_32B_ASCII);
      67. GUI_GetClientRect(&Rect);
      68. GUI_DispStringInRect("Page 1", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
      69. break;
      70. default:
      71. WM_DefaultProc(pMsg);
      72. break;
      73. }
      74. }
      75. /*********************************************************************
      76. *
      77. * _cbWinB
      78. */
      79. static void _cbWinB(WM_MESSAGE * pMsg) {
      80. int NCode;
      81. int Id;
      82. BUTTON_Handle hButton;
      83. GUI_RECT Rect;
      84. switch (pMsg->MsgId) {
      85. case WM_CREATE:
      86. hButton = BUTTON_CreateEx(10, 10, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
      87. BUTTON_SetText(hButton, "Go To Page 3");
      88. break;
      89. case WM_NOTIFY_PARENT:
      90. Id = WM_GetId(pMsg->hWinSrc);
      91. NCode = pMsg->Data.v;
      92. switch(Id) {
      93. case GUI_ID_BUTTON0:
      94. switch(NCode) {
      95. case WM_NOTIFICATION_RELEASED:
      96. WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWinC, 0);
      97. WM_DeleteWindow(pMsg->hWin);
      98. break;
      99. }
      100. break;
      101. }
      102. break;
      103. case WM_PAINT:
      104. GUI_SetBkColor(GUI_GREEN);
      105. GUI_SetColor(GUI_BLACK);
      106. GUI_Clear();
      107. GUI_SetFont(GUI_FONT_32B_ASCII);
      108. GUI_GetClientRect(&Rect);
      109. GUI_DispStringInRect("Page 2", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
      110. break;
      111. default:
      112. WM_DefaultProc(pMsg);
      113. break;
      114. }
      115. }
      116. /*********************************************************************
      117. *
      118. * _cbWinC
      119. */
      120. static void _cbWinC(WM_MESSAGE * pMsg) {
      121. int NCode;
      122. int Id;
      123. BUTTON_Handle hButton;
      124. GUI_RECT Rect;
      125. switch (pMsg->MsgId) {
      126. case WM_CREATE:
      127. hButton = BUTTON_CreateEx(10, 10, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
      128. BUTTON_SetText(hButton, "Go To Page 1");
      129. break;
      130. case WM_NOTIFY_PARENT:
      131. Id = WM_GetId(pMsg->hWinSrc);
      132. NCode = pMsg->Data.v;
      133. switch(Id) {
      134. case GUI_ID_BUTTON0:
      135. switch(NCode) {
      136. case WM_NOTIFICATION_RELEASED:
      137. WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWinA, 0);
      138. WM_DeleteWindow(pMsg->hWin);
      139. break;
      140. }
      141. break;
      142. }
      143. break;
      144. case WM_PAINT:
      145. GUI_SetBkColor(GUI_BLUE);
      146. GUI_SetColor(GUI_BLACK);
      147. GUI_Clear();
      148. GUI_SetFont(GUI_FONT_32B_ASCII);
      149. GUI_GetClientRect(&Rect);
      150. GUI_DispStringInRect("Page 3", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
      151. break;
      152. default:
      153. WM_DefaultProc(pMsg);
      154. break;
      155. }
      156. }
      157. /*********************************************************************
      158. *
      159. * _cbBk
      160. */
      161. static void _cbBk(WM_MESSAGE * pMsg) {
      162. switch (pMsg->MsgId) {
      163. case WM_PAINT:
      164. GUI_SetBkColor(GUI_BLACK);
      165. GUI_Clear();
      166. break;
      167. default:
      168. WM_DefaultProc(pMsg);
      169. break;
      170. }
      171. }
      172. /*********************************************************************
      173. *
      174. * Public code
      175. *
      176. **********************************************************************
      177. */
      178. /*********************************************************************
      179. *
      180. * MainTask
      181. */
      182. void MainTask(void) {
      183. // GUI_Init();
      184. // WM_MULTIBUF_Enable(1);
      185. WM_SetCallback(WM_HBKWIN, _cbBk); //Makes sure the window will be redrawn
      186. WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWinA, 0);
      187. while (1) {
      188. GUI_Delay(100);
      189. }
      190. }
      191. /*************************** End of file ****************************/
      Display All
      I modified the code and now it works as I want. I have commented GUI_Init() and WM_MULTIBUF_Enable(1) because I am already calling them in main.c.

      Thank you Shoenen!

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

    • I do it differently. Is it legal?

      tskGUI
      ...
      // Screen numbering
      //enum {W_SETTINGS, W_WPRIMCH1, W_WPRIMCH2, W_WTIME, W_MAX};
      // Current screen number. Declaring the function of creating a dialog.
      int16_t NScreen = W_SETTINGS;
      WM_HWIN (*pCreateWin[W_MAX])() =
      {
      CreateWSettings, CreateWPrimCh1, CreateWPrimCh2, CreateWTime,
      };
      WM_HWIN hCurWin = NULL;

      ...

      // Declare a callback routine on a blank screen
      WM_SetCallback(WM_GetDesktopWindowEx(0), _cbBk);
      // start GUI
      //hCurWin = CreateWSettings();
      hCurWin = pCreateWin[NScreen]();
      WM_ShowWindow(hCurWin);
      // Show the main menu
      WM_Exec();
      CleanDisplay(0xC0000000);
      // Gui background Task
      while(1)
      {
      GUI_Exec(); // Do the background work ... Update windows etc.)
      osDelay(10);
      }
      ....
      static void _cbBk(WM_MESSAGE * pMsg)
      {
      uint32_t NCode/*, Id*/;
      switch (pMsg->MsgId)
      {
      case WM_PAINT:
      break;
      case WM_NOTIFY_PARENT:
      //Id = WM_GetId(pMsg->hWinSrc);
      NCode = pMsg->Data.v;
      switch (NCode)
      {
      case WM_NOTIFICATION_CHILD_DELETED:
      if(NScreen < 0) NScreen = 0;
      if(NScreen > W_MAX) NScreen = 0;
      hCurWin = pCreateWin[NScreen]();
      WM_ShowWindow(hCurWin);
      break;
      default:
      break;
      }
      break;
      default:
      WM_DefaultProc(pMsg);
      }
      }

      ......

      The screen is rendered as a dialog. Like that...

      WM_HWIN CreateWPrimCh1(void) {
      WM_HWIN hWin;

      hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      return hWin;
      }

      ....
      The transition by the button is carried out as follows.

      case ID_BUTTON_BACK: // Notifications sent by 'Back'
      switch(NCode) {
      case WM_NOTIFICATION_RELEASED:
      NScreen = W_SETTINGS;
      GUI_EndDialog(pMsg->hWin, 0);
      WM_HideWindow(hCurWin);
      WM_Exec();
      break;
      }
      break;

      ....