您的位置:首页 > 其它

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

2013-08-11 23:12 246 查看
①、模态对话框的创建: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;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: