模态与非模态对话框 两个对话框之间值的传递

①、模态对话框的创建:CDialog::DoModal
      不用释放资源
②、非模态对话框的创建:CDialog::Create
    >:  MyDialog dlg;  静态存储区域:全局变量  与 DestroyWindow(); 函数配合使用释放资源
 
MyDialog dlg;
void CLessonOneDlg::OnBnClickedButton1()
{
dlg.Create(ID_MY_DIALOG,this);
dlg.ShowWindow(SW_SHOW);
}
 
 
void MyDialog::OnOK()
{
// TODO: Add your specialized code here and/or call the base class
MessageBox(_T("OnOK"));
DestroyWindow();
//CDialog::OnOK();

 
 >:  堆中申请内存: DestroyWindow()和PostNcDestroy()函数配合使用
 
        MyDialog *dlg = new MyDialog();
    dlg->Create(ID_MY_DIALOG,this);
    dlg->ShowWindow(SW_SHOW);
  -------------------------------------------------------------
void MyDialog::OnCancel()
{    
    DestroyWindow();
    //CDialog::OnCancel();
}
void MyDialog::PostNcDestroy()
{
    delete this;
    //CDialog::PostNcDestroy();
}


③、两个对话框之间值的传递
①、全局变量法:  CString str;  extern CString str;
②、主对话框法:AfxGetMainWnd();  CLessonOneDlg *dlg1 = (CLessonOneDlg*)AfxGetMainWnd();
③、父窗口法:GetParent();CLessonOneDlg *dlg1 = (CLessonOneDlg*)GetParent();
④、成员变量、成员函数法;   CLessonOneDlg *oneDlg;
--------------------- 
作者:jmcai520 
来源:CSDN 
原文:https://blog.csdn.net/jmcai520/article/details/9907121 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/zb774095236/article/details/84953279
今日推荐