Modeless Dialog Box
-
I need to create a modeless dialog but when I use Create() the dialog quickly appears and disappears. As an expirement I tried cerating a quick dialog-based app using the C++ wizard and created a button that brings up the about box (as created by the wizard) without using DoModal. Does anyone know how to do this please? It's quite frustrating.
-
I need to create a modeless dialog but when I use Create() the dialog quickly appears and disappears. As an expirement I tried cerating a quick dialog-based app using the C++ wizard and created a button that brings up the about box (as created by the wizard) without using DoModal. Does anyone know how to do this please? It's quite frustrating.
If you could post the code how you are creating the modeless dialog box may be that would pin point the prob. any ways here how i would create the modeless dialog.
CMydialog *pDialog;
pDialog = new CMydialog;
pDialog->Create(CMyDialog::IDD);
pDialog->ShowWindow(SW_SHOW);
MSN Messenger. prakashnadar@msn.com
-
If you could post the code how you are creating the modeless dialog box may be that would pin point the prob. any ways here how i would create the modeless dialog.
CMydialog *pDialog;
pDialog = new CMydialog;
pDialog->Create(CMyDialog::IDD);
pDialog->ShowWindow(SW_SHOW);
MSN Messenger. prakashnadar@msn.com
-
I need to create a modeless dialog but when I use Create() the dialog quickly appears and disappears. As an expirement I tried cerating a quick dialog-based app using the C++ wizard and created a button that brings up the about box (as created by the wizard) without using DoModal. Does anyone know how to do this please? It's quite frustrating.
well your problem might be as it seems from the description : You are creating the dialog variable in the OnButtonXXX() function, and when you create the modeless dialog, means CreateDialog returns at that very moment, and so does your funtion ( after calling ::ShowWindow(...)). And when your function ends, scope of your dialog ends (this is the reason for flashing, it creates, then ShowWindow() gets called and then scope ends. :( ), Try to make the variable outside the function (class variable or global), and try the same code, hopefully it will work. Regards, Bilal Anjum
-
Your code works fine. It was exactly the same as mine only you used a pointer to a dialog and I used an instance directly. Doesn't really make much sense to me but as long as it works, I'm happy right now ;-) Thanks for your help.
But do remember that the dialog object is created using new so there should be a corresponding delete as well. usally the modeless dialogs are self deleteing, you put
delete this
in OnDestroy event.
MSN Messenger. prakashnadar@msn.com
-
well your problem might be as it seems from the description : You are creating the dialog variable in the OnButtonXXX() function, and when you create the modeless dialog, means CreateDialog returns at that very moment, and so does your funtion ( after calling ::ShowWindow(...)). And when your function ends, scope of your dialog ends (this is the reason for flashing, it creates, then ShowWindow() gets called and then scope ends. :( ), Try to make the variable outside the function (class variable or global), and try the same code, hopefully it will work. Regards, Bilal Anjum
-
But do remember that the dialog object is created using new so there should be a corresponding delete as well. usally the modeless dialogs are self deleteing, you put
delete this
in OnDestroy event.
MSN Messenger. prakashnadar@msn.com
Mr.Prakash wrote: ...in OnDestroy event. Actually, the
this
pointer should be deleted inPostNcDestroy()
.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
Your code works fine. It was exactly the same as mine only you used a pointer to a dialog and I used an instance directly. Doesn't really make much sense to me but as long as it works, I'm happy right now ;-) Thanks for your help.
Don't forget to override the
OnCancel()
member function and callDestroyWindow()
from within it. Don’t call the base classCDialog::OnCancel()
, because it callsEndDialog()
, which will make the dialog box invisible but will not destroy it.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
Mr.Prakash wrote: ...in OnDestroy event. Actually, the
this
pointer should be deleted inPostNcDestroy()
.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)