再探MFC(四)创建对话框

本文介绍了如何使用Visual C++创建非模式对话框,并详细说明了其与模式对话框的区别。文章提供了具体步骤,包括资源视图中添加对话框模板、为对话框添加类以及在消息处理函数中调用相应方法来显示对话框。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值