Re: Closing modeless dialogs



Modeless dialogs are one of the places where you typically have to actually allocate on
the heap. Creating one during InitInstance is a bit dangerous, because the message pump
is not yet working.

As already pointed out, you don't use OnOK to close a modeless dialog; in fact, you have
to override it and remove its body, as you also have to do for OnCancel.

If you get assertions, your program is wrong, and you have to fix it. But note that what
you are showing here is a compiler warning; you have not said what the assertion is, what
file it occurs in, what line it is on, and what version of VS you are using.
joe

On Tue, 11 Mar 2008 16:52:46 +0100, Torsten Hensel
<Hensz@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi!
I created a simple dialog-based application. Then I created a modeless
dialog in MyApp::InitInstance - the dialog object is created on the
stack. Displaying the dialog works (I call Create() first and then
ShowWindow(SW_SHOW)). But when I close the dialog using either
DestroyWindow() or CDialog::OnOK() I get the following warning (and
assertions):
Warning: calling DestroyWindow in CDialog::~CDialog --
OnDestroy or PostNcDestroy in derived class will not be called.
Warning: calling DestroyWindow in CWnd::~CWnd; OnDestroy or
PostNcDestroy in derived class will not be called.

Btw. when I use OnOK I get only two assertions, with DestroyWindow I get
three.

I searched for those warnings in google, and I searched for modeless
dialogs in general. The only thing I found was to implement the
PostNcDestroy function with delete this; But this should only be
necessary when creating the dialog object on the heap...

What can I do to prevent this warning? I don't have any idea!

Best regards,
Torsten
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Closing modeless dialogs
    ... if you are just looping in the routine and using the dialog to display information during the loop I can't see where you would have a problem. ... If I wanted a modeless dialog to stay open for the life of my application I would make the dialog object a member of my mainframe class and create functions there to start, show, hide, and end the dialog. ... No warnings, no assertions, and I didn't change anything in my code. ... But when I close the dialog using either DestroyWindowor CDialog::OnOKI get the following warning: ...
    (microsoft.public.vc.mfc)
  • Re: dialogs Form.FormClosed is not run
    ... only modeless dialogs are difficult. ... It's true that because of the way a modal dialog is used, the code almost always instantiates it within the same block of code that will display it, but there's no requirement that you do so. ... In the cases where some other code needs to interact with the form, it is almost always the case that I'm dealing with a different class that I can just pass the form reference to for it to keep track of as long as it needs to. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Closing modeless dialogs
    ... Then I created a modeless dialog in MyApp::InitInstance - the dialog object is created on the stack. ... But when I close the dialog using either DestroyWindow() or CDialog::OnOKI get the following warning: ... OnDestroy or PostNcDestroy in derived class will not be called. ...
    (microsoft.public.vc.mfc)
  • Re: Creating Modeless Dialogs continually causing application to grow
    ... The example code that I provided was just a quick modification to a modeless ... void CModelessDemoDlg::OnBnClickedButton1 ... I need to use modeless dialogs due to the nature of the application I am ... the SLIGHTEST CLUE about the class of its parent. ...
    (microsoft.public.vc.mfc)
  • Re: Processing in a modeless dialog
    ... The use of modeless dialogs and the structure of the message pump is not the ... but as you cant use TranslateMessage ... longer get WM_CHAR messages going to the callback procedure.This means I ...
    (microsoft.public.vc.language)