|
-
Mar 2nd, 2002, 09:40 AM
#1
Thread Starter
Fanatic Member
Opening and Closing dialogs in MS VC++
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
THE TIME/WEATHER IS 
Don't know how to use APIs or have problem with them,
Download API-Guide & API-Viewer from http://www.allapi.net
-
Mar 2nd, 2002, 10:56 AM
#2
dlg1.DoModal()
dlg2.DoModal()
when DoModal returns, the dialog is not visible anymore
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 3rd, 2002, 08:04 AM
#3
Thread Starter
Fanatic Member
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...
Code:
CSecondDlg dlg2;
dlg2.DoModal();
In VB the above statement would be...
Code:
Private Sub cmdButton_Click()
Form2.Show vbModal, Me
End Sub
But I want...
Code:
Private Sub cmdButton_Click()
Form2.Show 'Unload Form1
Unload Me
End Sub
I am a newbie in VC++. I have more knowledge on VB than VC++.
THE TIME/WEATHER IS 
Don't know how to use APIs or have problem with them,
Download API-Guide & API-Viewer from http://www.allapi.net
-
Mar 4th, 2002, 09:41 AM
#4
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:
Code:
if(dlg1.DoModal() == IDOK)
dlg2.DoModal();
All other methods are complicated.
BTW you should learn the API before MFC.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 5th, 2002, 09:19 AM
#5
Thread Starter
Fanatic Member
Thanks. I'll just check it out.
THE TIME/WEATHER IS 
Don't know how to use APIs or have problem with them,
Download API-Guide & API-Viewer from http://www.allapi.net
-
Mar 7th, 2002, 10:16 AM
#6
Thread Starter
Fanatic Member
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...
Code:
//Class created in this header file using Class Wizard
#include "SecondDlg.h"
//First Dialog
void CFirstDlg::OnOK()
{
CSecondDlg::OnOK();
CSecondDlg Dlg2;
Dlg2.DoModal();
}
Also,
If I enter the above code in InitInstance event of the first file; ie...
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;
...I get an error. What am I doing wrong? Or is there something that I am not doing?
THE TIME/WEATHER IS 
Don't know how to use APIs or have problem with them,
Download API-Guide & API-Viewer from http://www.allapi.net
-
Mar 7th, 2002, 12:15 PM
#7
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();
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 9th, 2002, 08:38 AM
#8
Thread Starter
Fanatic Member
Finally...
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.
THE TIME/WEATHER IS 
Don't know how to use APIs or have problem with them,
Download API-Guide & API-Viewer from http://www.allapi.net
-
Mar 10th, 2002, 07:02 AM
#9
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.
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);
The code needs to be in InitInstance.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 11th, 2002, 09:49 AM
#10
Thread Starter
Fanatic Member
Thanks dude
THE TIME/WEATHER IS 
Don't know how to use APIs or have problem with them,
Download API-Guide & API-Viewer from http://www.allapi.net
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|