Menu

Modeless Dialogbox Error

PeterPan
2007-02-11
2015-02-04
  • PeterPan

    PeterPan - 2007-02-11

    I only created modeless dialogbox project as project wizard.
    And executed program(ctrl+F5).
    And I pushed ESC button.
    The program was close.
    But I heard a error biff.
    This situation appeared when I clicked ok button, cancel button and pushed Enter key.
    But disappeared when I clicked X button that is located non-client area. And Modal Dialog Project.

    I use VC6 and WTL 7.1.
    Is this bug?

     
    • Nenad Stefanovic

      Hello,

      Very interesting issue. I was ready to say that I can't reproduce it, but then I remembered similar issues on Vista. When I tried running the project on Vista, I was able to reproduce the problem.

      Here is what is happening: On Vista, a custom message (if I remember correctly, from the Theme code) is posted to dialog after it is destroyed. That goes to PreTranslateMessage and calls IsDialogMessage and then asserts on IsWindow() call. Because the dialog window is gone and app is shutting down, assert causes the whole (main) thread to end, which is what you can see in the debugger.

      Is this a serious problem: No, it is not. It happens only in the debug build, so the release build has no problems.

      How to fix this: Easier way is to add a call to IsWindow before calling IsDialogMessage in CMainDlg::PreTranslateMessage. The full fix would be to add OnDestroy handler. Since OnCreate calls pLoop->AddMessageFilter(this); and pLoop->AddIdleHandler(this);, then in OnDestroy we should call pLoop->RemoveMessageFilter(this); and pLoop->RemoveIdleHandler(this);

      This will be fixed in the App Wizard generated code to include OnDestroy handler with above calls for all project types.

      Cheers,
      Nenad

       
  • Erhy

    Erhy - 2015-01-22

    Thank you for these helpful sentences.
    My app with a modeless Dialog (child of a window)
    always crashed when the dialog was destroyed.

    Now all works.

    Thank you so much!

     

    Last edit: Erhy 2015-01-22
  • Nenad Stefanovic

    I am glad to hear that!

    Cheers,
    Nenad

     

Log in to post a comment.