Wednesday, July 14, 2010

Calling One Dialog Box From Another--VC++

  1. Visual C++ 2010
  2. Create a new MFC Application named Primary1
  3. Create it as Dialog Based
4.Set the Dialog Title to Calling One Dialog Box From Another

  1. Click Finish
  2. To add another dialog box, on the main menu, click Project -> Add Resource...
  3. In the Add Resource dialog box, double-click Dialog
  4. Change the ID of the new dialog to IDD_SECOND_DLG and its Caption to Second
  5. Right-click the dialog box and click Add Class...
  6. Set the Class Name to CSecondDlg and base it on CDialog
  7. Click Finish
  8. From the Class View, double-click the IDD_PRIMARY1_DIALOG
  9. Using the Toolbox, add a Button to the dialog box and change its properties as follows:
    Caption: Second
    ID: IDC_SECOND_BTN
  10. Double-click the new Second button and implement its event as follows:
    // Primary1Dlg.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "Primary1.h"
    #include "Primary1Dlg.h"
    #include ".\primary1dlg.h"
    #include "SecondDlg.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    
    // CPrimary1Dlg dialog
    
    
    . . . No Change
    
    // The system calls this function to obtain
    // the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CPrimary1Dlg::OnQueryDragIcon()
    {
    return static_cast(m_hIcon);
    }
    
    void CPrimary1Dlg::OnBnClickedSecondBtn()
    {
    // TODO: Add your control notification handler code here
    CSecondDlg Dlg;
    
    Dlg.DoModal();
    /*
    
    CDialog::DoModal
    Call this member function to invoke the modal dialog box and return the dialog-box result when done.
    */
    }
  11. Test the application

No comments:

Post a Comment