dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Problem when invoking a modeless dialog from a property page

  1. #1
    Join Date
    Jun 2001
    Posts
    45

    Problem when invoking a modeless dialog from a property page

    Hello!!

    I have a property page which invokes a modeless dialog. The modeless dialog gets invoked alright, but when you close the property page the modeless dialog just gets killed!!!... Neither the 'PostNcDestroy()' nor the 'OnCancel()' of the modeless dialog gets called. I have tried to specify the parent of the modeless dialog to NULL, GetDesktopWindow().. but no success. I do not understand if I change the parent of the modeless dialog to NULL, how does it know it has been invoked from a property page and it is closed when the property page is closed.

    If I call the modeless dialog from any dialog say dialogA which is not a property page, then even after dialogA is closed the modeless dialog still remain. This is what is required by me. But I cannot see this behaviour when the modeless dialog comes fom the property page..


    I am baffled.. Calling on expert's help and advice.

    regards,
    SvS

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,560

    Re: Problem when invoking a modeless dialog from a property page

    Could you post the small project reproducing this problem?
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2001
    Posts
    45

    Re: Problem when invoking a modeless dialog from a property page

    I tried to create a sample application in which the modeless dialog is invoked from property page, but it behave as I wanted.. So I guess its something to do with the MMC which is frustrating me.
    Let me explain more about my exact env.
    I have a snapin which plugs into mmc. In this MFC snapin I have a propertypage popped up. Now in MMC the property pages are modeless. Invoking a modeless dialog from this property page brings the dialog fine... so far so good... Now if I try to close the property page the modeless dialog closes too.
    I tried to mask the fact that the modeless dialog has been invoked from the property page by resetting the parent of the modeless dialog to NULL. But no success.

    Please help.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,560

    Re: Problem when invoking a modeless dialog from a property page

    What is "MMC"? Is it a Microsoft Management Console?
    Is your code (and the resources) in a DLL?
    Victor Nijegorodov

  5. #5
    Join Date
    Jun 2001
    Posts
    45

    Re: Problem when invoking a modeless dialog from a property page

    yes. That is right about MMC. Mine is a dll...

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,560

    Re: Problem when invoking a modeless dialog from a property page

    Well, did you ever see such a message box when you tried to close Event Viewer main window while Event Properties dialod was displayed?
    ---------------------------
    Microsoft Management Console
    ---------------------------
    You must close all dialog boxes before you can close Event Viewer.
    ---------------------------
    OK
    ---------------------------
    I guess (only guess, since I have no idea how it works internally!) this message box is displayed to prevent some "bad things" that may happen if this dialog won't be closed before closing the main window. Perhaps, dll is expected to be freed just after closing the main window?
    Victor Nijegorodov

  7. #7
    Join Date
    Jun 2001
    Posts
    45

    Re: Problem when invoking a modeless dialog from a property page

    Thank you so much for looking into this..
    Actually the property page, modeless dialog are all inside my snapin plugin dll.
    So its not like we are closing mmc and we should be asking to close the property page..
    The property page is itself modeless.. so it will allow other dialogs to exist with it.. but it (property page) should allow other dialogs to stay even after it is destroyed irrespective whether other modeless dialogs are invoked from it or not... Did I clarify it well?
    The point is a modeless diaog will destroy itself if it get the postncdestroy message... But when you close the property page does not send any message to this modeless dialog.. no WM_CLOSE, no WM_NCDESTROY.. nothing.. The property page just mercilessly kills the poor modeless dialog with no clues whatsoever.. I even tried to start SPY++ to see which events the modeless dialog gets when the property page is closed... but I could not see any messages which the modeless dialog got.. .. Any pointers in any direction which can help me find out what exactly happens or which event is sent to the modeless dialog which causes it to close.. without even calling its destructor...

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,560

    Re: Problem when invoking a modeless dialog from a property page

    Well, to close the modeless dialog the DestroyWindow API is usually used.
    But this function is supposed to send WM_DESTROY and WM_NCDESTROY messages to the window it currently destroys, so it's not clear what happens with your dialog that you don't see any WM_NCDESTROY message.
    Victor Nijegorodov

  9. #9
    Join Date
    Nov 2007
    Posts
    613

    Re: Problem when invoking a modeless dialog from a property page

    Most likely you store the dialog's window handle (or the CDialog object if you use MFC) in a variable that is a local variable to the property page. When the property page is closed, all its local variables go out of scope, they are deleted and any window they reffer is destroyed.
    Store your window handle (or CWnd object) in variable that can survive the closing of the property page (may be a global variable).

  10. #10
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Problem when invoking a modeless dialog from a property page

    Since you mention MMC. MMC is basically just a bunch of DLL's that get loaded.
    If your main dialog thread returns, the dll is unloaded and this takes everything else with it. Windows is smart enough to figure out some windows have a windows procedure that is no longer available so it just removes the windows. It can't properly close the windows since the windows procedure that should take care of that is gone.

    You can have modeless dialogs in MMC, but you can't have modeless dialogs that continue living when your entry point dies, you can only achieve that kind of behaviour by launching a separate executable that will host the modeless dialog, but then you'll be having some issues making the MMC snapin communicate with the modeless dialog.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)