当前位置: 首页 > article >正文

domodal返回值问题

转自:https://blog.csdn.net/shuilan0066/article/details/5775383

查了很多资料,都说DoModal()返回值为OK或CANCEL键的ID, 其实,这种说法是错误的,只不过是因为大部分关闭方法是通过OK与CANCLE关闭的

MSDN是这样说明其返回值的

If successful, the value of the nRetCode parameter specified in the call toEndDialog; otherwise, -1.

如果操作成功,其返回值为由EndDialog指定的nRetCode的值,而此参数nRetCode的含义为关闭对话框所采用的方式

也就是说,在关闭此模态对话框时,其返回值为关闭对话框时所采用的方式

因此它只在对话框关闭时才返回相关参数值

默认对话框关闭方式有2种:OnOK();    OnCancel()

当使用OnOK()函数关闭对话框时,返回值为IDOK

当使用OnCancel()函数关闭对话框时,返回值为IDCANCEL,返回值与ID无关

比如一个按钮的ID为IDC_BUTTON1在此按钮的处理函数中添加关闭对话框方式: OnOk(),则 点击此按钮时,对话框返回值为IDOK,除此两种默认关闭方式外,还可用EndDialog(int nRetCode)设定自定义的关闭方式

如下例子:

EndDialog(  int nResult   
);  Parameters  nResult  Contains the value to be returned from the dialog box to the caller of DoModal.  Remarks  This member function returns nResult as the return value of DoModal. You must use the EndDialog function to complete processing whenever a modal dialog box is created.  You can call EndDialog at any time, even in OnInitDialog, in which case you should close the dialog box before it is shown or before the input focus is set.  EndDialog does not close the dialog box immediately. Instead, it sets a flag that directs the dialog box to close as soon as the current message handler returns.  Example  /* MyWnd.cpp */  
#include "MyDialog.h"  void CMyWnd::ShowDialog()  
{  CMyDialog myDlg;  int nRet = myDlg.DoModal();  if ( nRet == IDOK || nRet == 5  )  AfxMessageBox("Dialog closed successfully");  
}  /* MyDialog.cpp */  
void CMyDialog::OnSomeAction()  
{  // Do something  int nRet = 5; // Just any value would do!  EndDialog(nRet); // This value is returned by DoModal!  // Do something  return; // Dialog closed and DoModal returns only here!  
}  

在工程中遇到这样的问题一个模态对话框 有三个按钮分别是ONOK()   ONCANCEL() EndDialog(0XFF)

但是发现 当按模态对话框右上角的叉号关闭对话框时,总是跳到ONCANCEL()关闭对话框时相同的处理方

推断:   点击叉后 它默认也是ONCANCEL关闭窗口

解决方法:  因为叉响应WM_COLOSE消息 因此为它创建一个关闭方式

void WeiKuangKe::OnClose()  
{  // TODO: Add your message handler code here and/or call default     int nRet=5;  EndDialog(nRet);  }  
http://www.lryc.cn/news/2415837.html

相关文章:

  • 【芯核架构】听你说你很了解ARM?
  • winrar4.0 注册码 key
  • Spring定时任务的几种实现
  • 心灵指南 刘墉 第三辑 肯定自己 笔记
  • 传说中的800句记7000词
  • 如何汉化vs2010、VS015、vs2017、VS019、v2022
  • 杂记
  • 缓存溢出
  • Linux USB 驱动实验
  • 用户行为分析
  • CodeGear Delphi 2007 for Win32 专业版下载地址及安装、破解方法
  • VBScript基础,变量,函数,流程
  • android布局layout,Android布局(layout)
  • Vmware17.5.1安装CentOS-Stream-9 【超超详细图文安装教程】
  • Django项目实战----接入第三方QQ登录绑定用户
  • 站外SEO应该怎么做?
  • 华为ct3100在entware上安装debian环境且在debian中安装samba过程
  • Blog主流程序整理(转)
  • Ubuntu7.04安装全实录
  • 3ds Max 2019: Advanced Materials 3ds Max 2019:材质高级教程 Lynda课程中文字幕
  • 数据库原理实验二 数据库管理 实验报告
  • 2007年度全国国际旅行社100强名单
  • wpe使用方法(详细)(--新加秒10图)(10号继续可用)
  • 黑莓9520拆机过程
  • 吴宗宪主持妙语
  • 处理器架构 (十四) arm1176 微架构下 各芯片的不同
  • Behance 大神推荐2019 年所有设计领域的最新趋势!
  • 试用 smartdraw 2010 方便快捷的图表工具
  • push notification
  • GB28181转SIP网关的优势