现在的位置: 首页 > 综合 > 正文

mfc 无模态(非模式)对话框的创建和关闭

2013年08月07日 ⁄ 综合 ⁄ 共 768字 ⁄ 字号 评论关闭

MSDN中这样描述:
If you wish to create a modeless dialog, call Createin the constructor of your dialog class.
When you implement a modeless dialog box, always override the OnCancel member function and callDestroyWindow from within itDon't call the base class CDialog::OnCancel,
because it calls EndDialog, which will make the dialog box invisible but will not destroy it. You should also override PostNcDestroy for modeless dialog boxes in order to delete this,
since modeless dialog boxes are usually allocated with new. Modal dialog boxes are usually constructed on the frame and do not need PostNcDestroy cleanup.

1.创建示例:
CXDialog *pDialog=new CXDialog();
pDialog->Create(CXDialog::IDD);
pDialog->ShowWindow(SW_SHOW);
 
2.关闭示例:
void CXDialog::PostNcDestroy()
{
    CDialog::PostNcDestroy();
    delete this;
}
void CXDialog::OnCancel()
{
    DestroyWindow();
}

抱歉!评论已关闭.