how to simultaneously show 2 dialogs
-
I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:
BOOL CDlg1::OnInitDialog()
{
...
dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
dlg2.ShowWindow(SW_SHOW);
...
}But this doesn't work.
-
I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:
BOOL CDlg1::OnInitDialog()
{
...
dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
dlg2.ShowWindow(SW_SHOW);
...
}But this doesn't work.
-
I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:
BOOL CDlg1::OnInitDialog()
{
...
dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
dlg2.ShowWindow(SW_SHOW);
...
}But this doesn't work.
A dialog, i.e. a window shown as modal, by definition is unique within a process, as it grabs you, your mouse and keyboard until you dismiss it. If you want two dialogs, you need two processes. Or you switch to modeless windows, which aren't dialogs at all. But then other forms of the same process could also be brought to the foreground and operated on. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
A dialog, i.e. a window shown as modal, by definition is unique within a process, as it grabs you, your mouse and keyboard until you dismiss it. If you want two dialogs, you need two processes. Or you switch to modeless windows, which aren't dialogs at all. But then other forms of the same process could also be brought to the foreground and operated on. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
If you want two dialogs, you need two processes.
This isn't true. It's possible and quite common for a modal dialog to have a button (or some other mechanism) which brings up another "nested" (not nested in a parent-child sense) modal dialog. Both dialogs are modal and shown at the same time although while the nested one exists the parent one is disabled.
Steve
-
I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:
BOOL CDlg1::OnInitDialog()
{
...
dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
dlg2.ShowWindow(SW_SHOW);
...
}But this doesn't work.
define dlg2 as a member varibale of CDlg1.
CDlg2 * m_pDlg2;
BOOL CDlg1::OnInitDialog()
{
// ...
m_pDlg2 = new CDlg2();
m_pDlg2->Create(IDD_DIALOG2, this);
m_pDlg2->ShowWindow(SW_SHOW);
// ...
}void CDlg1::OnDestroy()
{
CDialog::OnDestroy();// TODO: Add your message handler code here if(m\_pDlg2) delete m\_pDlg2; m\_pDlg2 = NULL;
}
modified on Thursday, October 28, 2010 4:17 AM
-
define dlg2 as a member varibale of CDlg1.
CDlg2 * m_pDlg2;
BOOL CDlg1::OnInitDialog()
{
// ...
m_pDlg2 = new CDlg2();
m_pDlg2->Create(IDD_DIALOG2, this);
m_pDlg2->ShowWindow(SW_SHOW);
// ...
}void CDlg1::OnDestroy()
{
CDialog::OnDestroy();// TODO: Add your message handler code here if(m\_pDlg2) delete m\_pDlg2; m\_pDlg2 = NULL;
}
modified on Thursday, October 28, 2010 4:17 AM
Why bother using
new
anddelete
and the pointerm_pDlg2
? In general I'd lose thenew
anddelete
(and in this case theOnDestroy
handler too) and embedCDlg2
directly:class CDlg1 : /* Stuff removed */
{
// ... Stuff removed ...
CDlg2 m_Dlg2;
// ... Stuff removed ...
};
BOOL CDlg1::OnShowOtherDialog()
{
// ...
m_Dlg2.Create(IDD_DIALOG2, this);
m_Dlg2.ShowWindow(SW_SHOW);
// ...
}Steve
-
Luc Pattyn wrote:
If you want two dialogs, you need two processes.
This isn't true. It's possible and quite common for a modal dialog to have a button (or some other mechanism) which brings up another "nested" (not nested in a parent-child sense) modal dialog. Both dialogs are modal and shown at the same time although while the nested one exists the parent one is disabled.
Steve
You're right of course, however that still leaves only one accessible dialog, not what the OP wants. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I'm now coding with VC++2008. I wanna show 2 dialogs at the same time. So how to achieve it? Thanks in advance. In fact I've tried the following:
BOOL CDlg1::OnInitDialog()
{
...
dlg2.Create(IDD_DIALOG2, this); // where dlg2 is defined as a private CDlg2 varibale of CDlg1 in its header file
dlg2.ShowWindow(SW_SHOW);
...
}But this doesn't work.
If you don't need 2 dialogs at the same time but you need them both displayable, then you're speaking about something like a tabbed dialog: each tab will show a dialog. I've a sample of doing this at the demo app that is in the article A Standard Multithreaded Dynamic Queue. Otherwise you want to investigate modeless dialogs.
-
Why bother using
new
anddelete
and the pointerm_pDlg2
? In general I'd lose thenew
anddelete
(and in this case theOnDestroy
handler too) and embedCDlg2
directly:class CDlg1 : /* Stuff removed */
{
// ... Stuff removed ...
CDlg2 m_Dlg2;
// ... Stuff removed ...
};
BOOL CDlg1::OnShowOtherDialog()
{
// ...
m_Dlg2.Create(IDD_DIALOG2, this);
m_Dlg2.ShowWindow(SW_SHOW);
// ...
}Steve
Good advice, en,, I prefer to use pointer..
-
Good advice, en,, I prefer to use pointer..
I prefer to avoid using the heap when it's not necessary: It's faster, safer and helps minimise heap fragmentation.
Steve