How do I close and open a new dialog in MS VC++ (MFC).
I know how to open on using .DoModal().
I want the same thing to happen as follows... (as in VB)
Code:Form2. Show
Unload Form1
Printable View
How do I close and open a new dialog in MS VC++ (MFC).
I know how to open on using .DoModal().
I want the same thing to happen as follows... (as in VB)
Code:Form2. Show
Unload Form1
dlg1.DoModal()
dlg2.DoModal()
when DoModal returns, the dialog is not visible anymore
No. I don't want to open the second form in Modal mode.
I used MFC APP Wizard and set the project to use dialogs.
In the first default Dialog that VC++ creates, I added a button. I added a new dialog resource. And in the BN_Clicked event of the button in the first dialog, I am doing the following...
In VB the above statement would be...Code:CSecondDlg dlg2;
dlg2.DoModal();
But I want...Code:Private Sub cmdButton_Click()
Form2.Show vbModal, Me
End Sub
I am a newbie in VC++. I have more knowledge on VB than VC++.Code:Private Sub cmdButton_Click()
Form2.Show 'Unload Form1
Unload Me
End Sub
You want the second dialog to show and the first one to disappear right?
Why not give the button in the first dialog the id IDOK and simply do this in the InitInstance method:
All other methods are complicated.Code:if(dlg1.DoModal() == IDOK)
dlg2.DoModal();
BTW you should learn the API before MFC.
Thanks. I'll just check it out.
OK I got it. But when I open the new dialog, the title does not appear in the taskbar.
This is how I did it...
Also,Code://Class created in this header file using Class Wizard
#include "SecondDlg.h"
//First Dialog
void CFirstDlg::OnOK()
{
CSecondDlg::OnOK();
CSecondDlg Dlg2;
Dlg2.DoModal();
}
If I enter the above code in InitInstance event of the first file; ie...
...I get an error. What am I doing wrong? Or is there something that I am not doing?Code://As written initially by MS VC++
CFirstDlg Dlg;
m_pMainWnd &Dlg;
int nResponse=Dlg.DoModal();
If (nResponse==IDOK)
{
CSecondDlg Dlg2;
Dlg2.DoModal();
}
elseif (nResponse==IDCancel)
{
}
return FALSE;
m_pMainWnd &Dlg;
You forgot the =
Don't add a OnOK handler, the default one is enough.
And add this line:
CSecondDlg Dlg2;
m_pMainWnd = &Dlg2;
Dlg2.DoModal();
Finally I got it. Thankyou.
But I would really appreciate it, if you could spend 2 minutes to make the same program as above in your style and attach it.
I am not satisfied with the way I have done it.
I had some problems with it, it's not as easy as I thought.
This is the code I created, it works. There need to be two dialogs, one with a class called CDlgmfcDlg, the other with a class called CDlgTwo.
The code needs to be in InitInstance.Code:WNDCLASS wc;
::ZeroMemory(&wc, sizeof(WNDCLASS));
wc.hInstance = AfxGetApp()->m_hInstance;
wc.lpfnWndProc = WP;
wc.lpszClassName = "DM";
HWND hDummyMain = CreateWindow("DM", "Multiple Dialog Demo", WS_POPUP, 0, 0, 0, 0, NULL, NULL, wc.hInstance, NULL);
m_pMainWnd = CWnd::FromHandle(hDummyMain);
CDlgmfcDlg dlg(CWnd::FromHandle(hDummyMain));
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Next
CDlgTwo dlg2(CWnd::FromHandle(hDummyMain));
dlg2.DoModal();
}
DestroyWindow(hDummyMain);
PostQuitMessage(0);
Thanks dude :)