Modeless modal CDialog
-
Hi CPians! I have a MFC Dlg app, that should be able to fire up an unlimited amount of dialogs when clicking on one button (e.g. one dialog per click). In the
OnClickButton
handler, if i run my code that way :CMyDialog mydlg;
mydlg.DoModal();the main dialog freezes after the first child dialog is started (of course, that's the way modal dialog are meant to work). If I do it this way :
CMyDialog mydlg;
mydlg.Create(...);
mydlg.Show();the dialog is closed as soon as I leave the
OnClickButton
, that is almost instantly, since mydlg is a local variable in that function. So what I intend to do is launch the dialog modal in a working thread, but this semms to be a bit paradoxical to me. Is it any better solution, or is this the ultimate one ? Thanks a lot ~RaGE(); -
Hi CPians! I have a MFC Dlg app, that should be able to fire up an unlimited amount of dialogs when clicking on one button (e.g. one dialog per click). In the
OnClickButton
handler, if i run my code that way :CMyDialog mydlg;
mydlg.DoModal();the main dialog freezes after the first child dialog is started (of course, that's the way modal dialog are meant to work). If I do it this way :
CMyDialog mydlg;
mydlg.Create(...);
mydlg.Show();the dialog is closed as soon as I leave the
OnClickButton
, that is almost instantly, since mydlg is a local variable in that function. So what I intend to do is launch the dialog modal in a working thread, but this semms to be a bit paradoxical to me. Is it any better solution, or is this the ultimate one ? Thanks a lot ~RaGE();Rage wrote: CMyDialog mydlg;mydlg.Create(...);mydlg.Show(); the dialog is closed as soon as I leave the onclickButton, that is almost instantly, since mydlg is a local variable in that function. why don't you declare CMyDialog as member variable or global variable or static variable, that will work exactly as you intend. C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
-
Hi CPians! I have a MFC Dlg app, that should be able to fire up an unlimited amount of dialogs when clicking on one button (e.g. one dialog per click). In the
OnClickButton
handler, if i run my code that way :CMyDialog mydlg;
mydlg.DoModal();the main dialog freezes after the first child dialog is started (of course, that's the way modal dialog are meant to work). If I do it this way :
CMyDialog mydlg;
mydlg.Create(...);
mydlg.Show();the dialog is closed as soon as I leave the
OnClickButton
, that is almost instantly, since mydlg is a local variable in that function. So what I intend to do is launch the dialog modal in a working thread, but this semms to be a bit paradoxical to me. Is it any better solution, or is this the ultimate one ? Thanks a lot ~RaGE();You may use:
CMyDialog *pmydlg=new CMyDialog;
pmydlg->Create(...);
pmydlg->Show();to create the modeless dialog who's
PostNcDestroy
should look like this:void CMyDialog::PostNcDestroy()
{
// your stuff...
CDialog::PostNcDestroy();
delete this;
} -
Hi CPians! I have a MFC Dlg app, that should be able to fire up an unlimited amount of dialogs when clicking on one button (e.g. one dialog per click). In the
OnClickButton
handler, if i run my code that way :CMyDialog mydlg;
mydlg.DoModal();the main dialog freezes after the first child dialog is started (of course, that's the way modal dialog are meant to work). If I do it this way :
CMyDialog mydlg;
mydlg.Create(...);
mydlg.Show();the dialog is closed as soon as I leave the
OnClickButton
, that is almost instantly, since mydlg is a local variable in that function. So what I intend to do is launch the dialog modal in a working thread, but this semms to be a bit paradoxical to me. Is it any better solution, or is this the ultimate one ? Thanks a lot ~RaGE(); -
Rage wrote: CMyDialog mydlg;mydlg.Create(...);mydlg.Show(); the dialog is closed as soon as I leave the onclickButton, that is almost instantly, since mydlg is a local variable in that function. why don't you declare CMyDialog as member variable or global variable or static variable, that will work exactly as you intend. C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
mailMonty wrote: why don't you declare CMyDialog as member variable or global variable or static variable, that will work exactly as you intend. Because I do not know how many of them I will need (see in my post, you fire up a dlg every time you click on a button). So declaring them as global would require a dynamical global array of dlgs :~ ~RaGE();
-
You may use:
CMyDialog *pmydlg=new CMyDialog;
pmydlg->Create(...);
pmydlg->Show();to create the modeless dialog who's
PostNcDestroy
should look like this:void CMyDialog::PostNcDestroy()
{
// your stuff...
CDialog::PostNcDestroy();
delete this;
} -
in your button event,you should like this: CMyDialog mydlg=new CMyDialog; mydlg.Create(...); mydlg.Show(); in the class of CMyDialog you should add a function CMyDialog::PostNCDestroy() { delete this; }
-
Rage wrote: CMyDialog mydlg;mydlg.Create(...);mydlg.Show(); the dialog is closed as soon as I leave the onclickButton, that is almost instantly, since mydlg is a local variable in that function. why don't you declare CMyDialog as member variable or global variable or static variable, that will work exactly as you intend. C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
-
Thanks rechi, I had already thought about something like this, i missed the existence of
PostNcDestroy
. Thanks again. ~RaGE();