①、模态对话框的创建: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;
|