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?
Display All
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
- /** Dialog's handle. */
- static WM_HWIN g_wdw_hd = -1;
- typedef struct
- {
- int foo;
- int boo;
- } internal_data_t;
- static internal_data_t g_internal_data = {0, 0};
- static void WdwCb(WM_MESSAGE* pMsg)
- {
- switch (pMsg->MsgId)
- {
- case WM_CREATE:
- {
- }
- break;
- case WM_INIT_DIALOG:
- {
- }
- break;
- case WM_DELETE:
- {
- memset(&g_internal_data, 0, sizeof(g_internal_data));
- }
- break;
- }
- }
- WM_HWIN EXAMPLE_DLG_Create(WM_HWIN parent, int x, int y)
- {
- if(g_wdw_hd >= 0)
- { return -1; }
- g_wdw_hd = GUI_CreateDialogBox( g_wdw_info, GUI_COUNTOF(g_wdw_info), WdwCb, parent, x, y);
- return g_wdw_hd;
- }
- int EXAMPLE_DLG_Destroy(void)
- {
- if(g_wdw_hd <= -1)
- { return 0; }
- GUI_EndDialog(g_wdw_hd, 0);
- g_wdw_hd = -1;
- return 1;
- }