Results 1 to 10 of 10

Thread: Opening and Closing dialogs in MS VC++

  1. #1

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    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

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562
    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

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    Smile

    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

  6. #6

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562
    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

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  8. #8

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    Smile 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

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  10. #10

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562
    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
  •  



Click Here to Expand Forum to Full Width