if(Dialog.DoModal() == IDOK) 把IDOK改成Button1的ID号问题

CyckSDN 2012-05-16 05:09:06
if(Dialog.DoModal() == IDOK)
{
//代码段
}
为什么把IDOK改成Button1的ID号就不行了呢?
我调试:
把IDOK改成Button1的ID或者Button1的函数最后加上OnOK()结果都没成功
何为????
...全文
13952 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
yutouing 2013-07-03
  • 打赏
  • 举报
回复
引用 7 楼 CyckSDN 的回复:
谢谢各位的指点: 我想我表达的不是很明确 需求如下: 当我新建一个对话框Dialog1时,就会默认产生两个按钮“确定”“取消”。 现在我新建一个按钮“Button1”对应ID号“IDC_Button1” 然后创建Dialog2,在Dialog2中想实现如下功能 CDialog1 Dlg; if(Dlg.DoModal() == IDC_Button1) { //代码段 } 如上却没有达到预期目的 我知道这样是可以的 CDialog1 Dlg; if(Dlg.DoModal() == IDOK) { //代码段 } 我现在想用这种方法实现 CDialog1 Dlg; if(Dlg.DoModal() == IDC_Button1) { //代码段 } 请高手指点应该如何做??? 尽量具体点……谢谢!!!
你想输入的这些代码都是在函数OnButton1这个响应事件里的吧,因而当你点击button1的时候其实就已经进入这个函数了,而Dlg.DoModal()的返回值只有IDOK和IDCANCLE即当你点击完button1的时候只会返回这两个值,因而需要是IDOK。 应该很清楚了吧。。
xzh1995 2013-07-03
  • 打赏
  • 举报
回复
同问 , 我也想知道
  • 打赏
  • 举报
回复
引用 17 楼 schlafenhamster 的回复:
OnButton1() { EndDialog(IDC_BUTTON1); }
+1 An int value that specifies the value of the nResult parameter that is passed to the CDialog::EndDialog method, which is used to close the dialog box. The return value is –1 if the function cannot create the dialog box, or IDABORT if some other error occurs.
tttyanfeng 2012-09-20
  • 打赏
  • 举报
回复
同问 !
schlafenhamster 2012-09-19
  • 打赏
  • 举报
回复
OnButton1()
{
EndDialog(IDC_BUTTON1);

}
schlafenhamster 2012-09-19
  • 打赏
  • 举报
回复
试试 :EndDialog(BOTTON1);
「已注销」 2012-09-19
  • 打赏
  • 举报
回复
同一13楼。MFC 封装了 EndDialog,不够自由了。要是用 EndDialog 想返回什么都可以。
许文君 2012-09-13
  • 打赏
  • 举报
回复
你把Domodal的 return value 和 ONCOMMAND消息搞混了
xiaohuh421 2012-09-13
  • 打赏
  • 举报
回复
EndDialog对适合楼主需求.
首先在能保证对话框资源能正确释放的前提下,使用EndDialog函数即可.
在按钮的响应函数中,调用EndDialog, 并传入按钮的ID号即可.

具体过程, 如果写过 Win32 窗口程序的,应该就能明白了.
shilaosan 2012-09-13
  • 打赏
  • 举报
回复
同问!!!
CyckSDN 2012-05-19
  • 打赏
  • 举报
回复
前辈们DSMN说:
Remarks

Call this member function to invoke the modal dialog box and return the dialog-box result when done. This member function handles all interaction with the user while the dialog box is active. This is what makes the dialog box modal; that is, the user cannot interact with other windows until the dialog box is closed.

If the user clicks one of the pushbuttons in the dialog box, such as OK or Cancel, a message-handler member function, such as OnOK or OnCancel, is called to attempt to close the dialog box. The default OnOK member function will validate and update the dialog-box data and close the dialog box with result IDOK, and the default OnCancel member function will close the dialog box with result IDCANCEL without validating or updating the dialog-box data. You can override these message-handler functions to alter their behavior.

在这里:You can override these message-handler functions to alter their behavior.该如何理解呢???
wutongsana 2012-05-18
  • 打赏
  • 举报
回复
LZ不明白返回的不是IDOK就是IDCANCEL
_free 2012-05-18
  • 打赏
  • 举报
回复
CDialog1 中定义一个
int m_nType;
_free 2012-05-18
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
谢谢各位的指点:
我想我表达的不是很明确
需求如下:
当我新建一个对话框Dialog1时,就会默认产生两个按钮“确定”“取消”。
现在我新建一个按钮“Button1”对应ID号“IDC_Button1”
然后创建Dialog2,在Dialog2中想实现如下功能
CDialog1 Dlg;
if(Dlg.DoModal() == IDC_Button1)
{
//代码段
} ……
[/Quote]


这样足可以满足你想要的需求吧

CDialog1 Dlg;
if(Dlg.DoModal() == IDOK)
{
//代码段
if(dlg.m_nType == IDC_Button1)
{
}
}

CyckSDN 2012-05-18
  • 打赏
  • 举报
回复
谢谢各位的指点:
我想我表达的不是很明确
需求如下:
当我新建一个对话框Dialog1时,就会默认产生两个按钮“确定”“取消”。
现在我新建一个按钮“Button1”对应ID号“IDC_Button1”
然后创建Dialog2,在Dialog2中想实现如下功能
CDialog1 Dlg;
if(Dlg.DoModal() == IDC_Button1)
{
//代码段
}
如上却没有达到预期目的
我知道这样是可以的
CDialog1 Dlg;
if(Dlg.DoModal() == IDOK)
{
//代码段
}
我现在想用这种方法实现
CDialog1 Dlg;
if(Dlg.DoModal() == IDC_Button1)
{
//代码段
}
请高手指点应该如何做???
尽量具体点……谢谢!!!
诶呦 2012-05-16
  • 打赏
  • 举报
回复
Example
void CTstApp::OnAppAbout()
{
// Construct the dialog box by passing the
// identifier of the dialog template resource.
CDialog aboutDlg(IDD_ABOUTBOX);

// Create and show the dialog box.
int nRet = –1;
nRet = aboutDlg.DoModal();

// Handle the return value from DoModal.
switch ( nRet )
{
case –1:
AfxMessageBox("Dialog box could not be created!");
break;
case IDABORT:
// Do something.
break;
case IDOK:
// Do something.
break;
case IDCANCEL:
// Do something.
break;
default:
// Do something.
break;
};
}

jianghandaxue 2012-05-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
DoModal的返回值是退出时的id号,即IDOK或IDCancel

Button1的函数最后加上OnOK()
退出号还是IDOK
[/Quote]

up
sky_lily_1985 2012-05-16
  • 打赏
  • 举报
回复
这个是例外,要死记住的,只要知道怎么用就OK了
ouyh12345 2012-05-16
  • 打赏
  • 举报
回复
看msdn:
Return Value

An int value that specifies the value of the nResult parameter that was passed to the CDialog::EndDialog member function, which is used to close the dialog box. The return value is –1 if the function could not create the dialog box, or IDABORT if some other error occurred, in which case the Output window will contain error information from GetLastError.
CyckSDN 2012-05-16
  • 打赏
  • 举报
回复
这个问题不简单
加载更多回复(1)

16,547

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧