我在基于对话框的程序中新加入了一个窗体,请问我该如何使单击第一个窗体上的按钮时显示第二个窗体,有就是我该如何加载第二个窗体?

解决方案 »

  1.   

    CDialog2 dlg2;
    dlg2.DoModal();
      

  2.   

    # include "Dialog2.h"CDialog2 dlg;
    dlg.DoModal();
      

  3.   

    CDialog::DoModal 
    virtual int DoModal( );
    Return ValueAn int value that specifies the value of the nResult parameter that was passed to the CDialog::EndDialog member function, which is used to close the dialog box. The return value is –1 if the function could not create the dialog box, or IDABORT if some other error occurred.
    整数值,指定了传递给CDialog::EndDialog 的nResult参数值。该函数用于关闭对话框。如果函数不能创建对话框,则返回-1;如果出现其它错误,则返回IDABORT。 Res
    Call this member function to invoke the modal dialog box and return the dialog-box result when done. This member function handles all interaction with the user while the dialog box is active. This is what makes the dialog box modal; that is, the user cannot interact with other windows until the dialog box is closed.调用该成员函数使用模态对话框并返回对话框结果。当对话框处于活动状态时,该函数处理与用户的交互。这使得对话框是模态的,使用户在关闭对话框之前不能与其它窗口交互。 If the user clicks one of the pushbuttons in the dialog box, such as OK or Cancel, a message-handler member function, such as OnOK or OnCancel, is called to attempt to close the dialog box. The default OnOK member function will validate and update the dialog-box data and close the dialog box with result IDOK, and the default OnCancel member function will close the dialog box with result IDCANCEL without validating or updating the dialog-box data. You can override these message-handler functions to alter their behavior.如果用户单击了对话框中的按钮,如OK或Cancel,那么消息处理函数如OnOK或OnCancel被调用,从而关闭对话框。缺省的OnOK成员函数会对对话框数据进行有效性检验和更新,并关闭它得到结果IDOK。缺省OnCancel函数关闭对话框得到结果IDCANCEL,而不对对话框数据检验或更新,可以覆盖这些消息函数并改变它们的行为。 Note   PreTranslateMessage is now called for modal dialog box message processing.目前PreTransMessage被调用来处理模态对话框的消息。
      

  4.   

    1.打开模式对话框:
     #include "Dialog2.h"  CDialog2 dlg;
      dlg.DoModal();2.打开非模对话框
     #include "Dialog2.h"
      CDialog2 *pDlg2 = new CDialog2();
      pDlg2->create(...);
      pDlg2->ShowWindow(SW_SHOW);
      
      

  5.   

    #include "Dialog2.h"在Dialog1.h中添加
    CDialog2 m_pDlg;
    在按钮响应函数中添加
    m_pDlg = new CDialog2(this);
    m_pDlg->Create(CDialog::IDD,this);
    m_pDlg->ShowWindow(SW_SHOW);
      

  6.   

    笔误m_pDlg->Create(CDialog2::IDD,this);