Issues with GUI_EndDialog and WM_DELETE

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

  • Issues with GUI_EndDialog and WM_DELETE

    I am using the following structure on my dialogs. But after some tests in debugging the code, I've noticed that the WM_DELETE doesn't appear to execute right after a GUI_EndDialog. It appears that emWin only marks the dialog to be deleted in a near future. When is the best moment to clear the dialog internal data in order to be sure that all data is ready to be used the next time the dialog is opened? Even when the dialog is deleted and created in a very short interval.
    I am worried about re-opening a dialog before the event WM_DELETE be received and having the internal data messed up.
    Is it a better idea to clear the internal data on the event WM_CREATE?

    C Source Code

    1. /** Dialog's handle. */
    2. static WM_HWIN g_wdw_hd = -1;
    3. typedef struct
    4. {
    5. int foo;
    6. int boo;
    7. } internal_data_t;
    8. static internal_data_t g_internal_data = {0, 0};
    9. static void WdwCb(WM_MESSAGE* pMsg)
    10. {
    11. switch (pMsg->MsgId)
    12. {
    13. case WM_CREATE:
    14. {
    15. }
    16. break;
    17. case WM_INIT_DIALOG:
    18. {
    19. }
    20. break;
    21. case WM_DELETE:
    22. {
    23. memset(&g_internal_data, 0, sizeof(g_internal_data));
    24. }
    25. break;
    26. }
    27. }
    28. WM_HWIN EXAMPLE_DLG_Create(WM_HWIN parent, int x, int y)
    29. {
    30. if(g_wdw_hd >= 0)
    31. { return -1; }
    32. g_wdw_hd = GUI_CreateDialogBox( g_wdw_info, GUI_COUNTOF(g_wdw_info), WdwCb, parent, x, y);
    33. return g_wdw_hd;
    34. }
    35. int EXAMPLE_DLG_Destroy(void)
    36. {
    37. if(g_wdw_hd <= -1)
    38. { return 0; }
    39. GUI_EndDialog(g_wdw_hd, 0);
    40. g_wdw_hd = -1;
    41. return 1;
    42. }
    Display All
  • Hi,

    You are right, Calling GUI_EndDialog() will mark the dialog as 'to be deleted'. Next time you enter WM_Exec() (e.g. calling GUI_Delay() in a main loop) the dialog gets deleted. To be on the save side you can reset the data on WM_CREATE. This should be the first message a window receives.

    Regards,
    Sven
    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.