Create and delete multilayer dialogs

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

    • Create and delete multilayer dialogs

      Hello,

      I've already used emWin (STemWin in particular) to create single layer dialogs without any problem.
      Usually I create single .c files for each single GUI page (which consists of a main dialog) and to change from a page to another one I delete the previous one with GUI_EndDialog() in the following way:

      Source Code

      1. static WM_HWIN hWinMain, hWinAlarms;
      2. WM_HWIN hItem;
      3. //========================================================
      4. // Main page creation
      5. //========================================================
      6. hWinMain = GUI_CreateDialogBox(_aWinMainDialogCreate, GUI_COUNTOF(_aWinMainDialogCreate), _cbDialogWinMain, WM_GetDesktopWindowEx(0), 0, 0);
      7. ...
      8. //========================================================
      9. //Redrawing operations
      10. //========================================================
      11. ...
      12. WM_Exec();
      13. //========================================================
      14. //A page change is needed, prepare data (ID of the dialog window)
      15. //========================================================
      16. hItem = WM_GetDialogItem(hWinMain, IDGUIMAIN_WINDOW);
      17. WM_EnableWindow(hItem);
      18. //========================================================
      19. //Save current dialog which will become the previous one
      20. //========================================================
      21. // (g_GUI.hPrevDialog is declared as WM_HWIN type)
      22. g_GUI.hPrevDialog = hWinMain;
      23. WM_Exec();
      24. //========================================================
      25. //Next page is the alarms one, create it
      26. //========================================================
      27. hWinAlarms = GUI_CreateDialogBox(_aWinAlarmsDialogCreate, GUI_COUNTOF(_aWinAlarmsDialogCreate), _cbDialogWinAlarms, WM_GetDesktopWindowEx(0), 0, 0);
      28. //========================================================
      29. //End the previous dialog
      30. //========================================================
      31. GUI_EndDialog (g_GUI.hPrevDialog, 0);
      32. g_GUI.hPrevDialog = 0;
      33. WM_Exec();
      Display All

      I tried to do the same with a two layer dialog following the same principle:

      Source Code

      1. static WM_HWIN hWinMain_Layer_0, hWinMain_Layer_1, hWinAlarms;
      2. WM_HWIN hItem;
      3. //========================================================
      4. // Main page creation, this time with two layers
      5. //========================================================
      6. hWinMain_Layer_0 = GUI_CreateDialogBox(_aWinMainDialogCreate_Layer_0, GUI_COUNTOF(_aWinMainDialogCreate_Layer_0), _cbDialogWinMain_Layer_0, WM_GetDesktopWindowEx(0), 0, 0);
      7. hWinMain_Layer_1 = GUI_CreateDialogBox(_aWinMainDialogCreate_Layer_1, GUI_COUNTOF(_aWinMainDialogCreate_Layer_1), _cbDialogWinMain_Layer_1, WM_GetDesktopWindowEx(1), 0, 0);
      8. ...
      9. //========================================================
      10. //Redrawing operations
      11. //========================================================
      12. ...
      13. WM_Exec();
      14. //========================================================
      15. //A page change is needed, prepare data
      16. //========================================================
      17. hItem = WM_GetDialogItem(hWinMain_Layer_0, IDGUIMAIN_WINDOW_LAYER_0);
      18. WM_EnableWindow(hItem);
      19. hItem = WM_GetDialogItem(hWinMain_Layer_1, IDGUIMAIN_WINDOW_LAYER_1);
      20. WM_EnableWindow(hItem);
      21. //========================================================
      22. //Save current dialogs which will become the previous ones
      23. //========================================================
      24. g_GUI.hPrevDialog_Layer_0 = hWinMain_Layer_0;
      25. g_GUI.hPrevDialog_Layer_1 = hWinMain_Layer_1;
      26. WM_Exec();
      27. //========================================================
      28. //Next page is the alarms one, create it
      29. //========================================================
      30. hWinAlarms = GUI_CreateDialogBox(_aWinAlarmsDialogCreate, GUI_COUNTOF(_aWinAlarmsDialogCreate), _cbDialogWinAlarms, WM_GetDesktopWindowEx(0), 0, 0);
      31. //========================================================
      32. //End the previous dialogs
      33. //========================================================
      34. GUI_EndDialog (g_GUI.hPrevDialog_Layer_0 , 0);
      35. GUI_EndDialog (g_GUI.hPrevDialog_Layer_1 , 0);
      36. g_GUI.hPrevDialog_Layer_0 = 0;
      37. g_GUI.hPrevDialog_Layer_1 = 0;
      38. WM_Exec();
      Display All

      This works for a while but gets stuck (memory fault) after some (variable number, not a repetitive number!) of page changes at the last WM_Exec() instruction.
      Without the line:

      Source Code

      1. GUI_EndDialog (g_GUI.hPrevDialog_Layer_1 , 0);
      it doesn't get stuck but obviously the old layer #1 stays on the screen (since it's visible).
      There shouldn't be problems related to memory space since I'm using an external memory for the different buffer frame layers.

      Could anybody suggest me a different working way to switch between these kind of dialogs or tell me what I'm doing wrong?

      Thank you!

      Regards,
      Mark