码迷,mamicode.com
首页 > 编程语言 > 详细

再探MFC(四)创建对话框

时间:2015-04-02 16:31:47      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

以点击菜单弹出非模式对话框为例.

技术分享

 

step1

资源视图添加对话框模板.重命名对话框资源ID.

 

step2

选中对话框,右键菜单点击添加类.

 

step3

在菜单项的消息处理函数中

CDialogAddContactdlg;

INT_PTR nResponse =dlg.DoModal();

if (nResponse ==IDOK)

{

 

}

else if (nResponse== IDCANCEL)

{

 

}

 


可以通过DoModel创建模式对话框,通过Create创建非模式对话框.Remarks解释了两种对话框类型.Dialog boxes are of two types: modal andmodeless. A modal dialog box must be closed by the user before the applicationcontinues. A modeless dialog box allows the user to display the dialog box andreturn to another task without canceling or removing the dialog box.

 

如何关闭对话框?Remarks介绍如下.

A modal dialog boxcloses automatically when the user presses the OK or Cancel buttons or whenyour code calls the EndDialog member function.

 

When you implement amodeless dialog box, always override the OnCancel member function and callDestroyWindow from within it. Don‘t call the base class CDialog::OnCancel,because it calls EndDialog, which will make the dialog box invisible but willnot destroy it. You should also override PostNcDestroy for modeless dialogboxes in order to delete this, since modeless dialog boxes are usuallyallocated with new. Modal dialog boxes are usually constructed on the frame anddo not need PostNcDestroy cleanup.

 

https://msdn.microsoft.com/en-us/library/132s802t.aspx

再探MFC(四)创建对话框

标签:

原文地址:http://blog.csdn.net/soliddream66/article/details/44832819

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!