How to close a window a pass a message to another window

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

  • How to close a window a pass a message to another window

    I'm using emWin libraries on a NXP board with a single-task (polling loop).

    I have a visible/active window (Main Window) that covers all the display and a button inside. When the user press the button, I'd like to create and show another window (Slave Window), created on-the-fly in WM_NOTIFICATION_RELEASED message. The Slave Window covers the entire display and it should be on top of the Main Window.

    Source Code

    1. static void
    2. cbBackgroundWin(WM_MESSAGE *pMsg)
    3. {
    4. WM_HWIN hWin = pMsg->hWin;
    5. switch(pMsg->MsgId) {
    6. case WM_NOTIFY_PARENT: {
    7. switch(pMsg->Data.v) {
    8. case WM_NOTIFICATION_RELEASED:
    9. hDialog = dialog_entercode_create(hWin, code, sizeof(code) - 1);
    10. WM_ShowWindow(hDialog);
    11. break;
    12. }
    13. break;
    14. }
    15. case WM_USER:
    16. ?????
    17. break;
    18. default:
    19. WM_DefaultProc(pMsg);
    20. }
    21. }
    Display All


    dialog_entercode_create() creates and returns the handle of the newly created Slave Window. It isn't shown, so the call WM_ShowWindow(hDialog). When finished, the user press a button on Slave Window and the effect should be to delete Slave Window and automatically show again the Main Window.
    I tried to send an application-defined message (WM_USER) from the callback function of the Slave Window to the Main Window. In the WM_USER code of the Main Window, I tried to call WM_DeleteWindow(hDialog), but the application crashes. I think because the messages aren't send through a queue mechanism, but inside the WM_SendMessage(). So, when the Main Window calls WM_DeleteWindow(), the Slave Window is yet active and its callback is running so it can't be deleted.

    I can call WM_HideWindow() instead of WM_DeleteWindow(), but I'd like to completely deallocate the Slave Window after the user has finished using it.

    The problem is similar to a non-blocking Dialog window, but I couldn't understand how it works with Dialogs feature of emWin. Could I call GUI_EndDialog() with a custom window not created with GUI_CreateDialogBox()?
  • Hello,

    WM_DELETE is the last message sent to a window just before it gets deleted. WM_NOTIFY_PARENT / WM_WM_NOTIFICATION_CHILD_DELETED is the last notification regarding a certain window sent to its parent window just before the child window gets deleted. I assume you want to react to one of those messages in order to let the parent window know about the child being deleted.

    Please note that newly created windows are not shown by default. Either the create flag WM_CF_SHOW is used at creation or the function WM_ShowWindow() is called after the window was created.

    Best regards,
    Adrian
  • "WM_DELETE is the last message sent to a window just before it gets
    deleted. WM_NOTIFY_PARENT / WM_WM_NOTIFICATION_CHILD_DELETED is the last
    notification regarding a certain window sent to its parent window just
    before
    the child window gets deleted. I assume you want to react to one of
    those messages in order to let the parent window know about the child
    being deleted."
    I try to reformulate the question again. I have two windows: Main Window and Aux Window. Both have a button.
    Main Button (button on Main Window) creates and shows the Aux Window, overwriting the Main Window. The Aux button (the button in the Aux Window) closes the Aux Window and communicates to the Main Window the event.

    In WM_NOTIFICATION_PARENT / WM_NOTIFICATION_RELEASED of Aux Window, I send an application defined message (WM_USER) to Main Window. I tried to call WM_DeleteWindow(Aux_Window) from there, but I can't. I think because Main Window callback is called from Aux Window callback that can't be self-deleted.

    So the question is: how to delete a window from inside its callback?
  • Hello,

    Deleting a window from inside a callback function should actually work. In general it is the intended way to perform actions from inside callback functions when using the Window Manager.

    Could you please verify the correct window handle is passed to the function WM_Delete()?

    Best regards,
    Adrian