请问个有关问题,如何改变 DoModal 的返回值
请教个问题,怎么改变 DoModal 的返回值 ?
新建个对话框资源,把上面的“确定”“取消”按钮删了。自己添加个按钮(ID_Btn),给对话框添加类 TestModal。
void TestModal::OnBnClickedBtn()
{
EndDialog (10); //期望能返回 10
}
在 view 类随便找个能触发的地方,写上:
TestModal wnd;
int result = wnd.DoModal();
来测试 DoModal 返回值,但这窗口关不了,为什么?只能点左上角关闭,但返回2
在 MSDN 上看到下面话,所以做上面的测试下,不知是哪弄错了?
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.
===========================
void EndDialog(
int nResult
);
This member function returns nResult as the return value of DoModal.
------解决方案--------------------
EndDialog可以实现关闭的功能的呀。你确定你的代码执行到了,
------解决方案--------------------
在按钮事件里调用CDialog::OnOK()返回IDOK,调用CDialog::OnCancel()返回IDCANCEL
------解决方案--------------------
EndDialog (10)是对非模态对话框而言的,DoModal却弹出了一个模态对话框。
------解决方案--------------------
你要想修改返回值只要重载一个OnOK,修改它的返回值应该可以
------解决方案--------------------
http://topic.****.net/t/20040924/16/3406311.html
------解决方案--------------------
照你说的,做了下可以的呀。对话框关闭了,返回10。
新建个对话框资源,把上面的“确定”“取消”按钮删了。自己添加个按钮(ID_Btn),给对话框添加类 TestModal。
void TestModal::OnBnClickedBtn()
{
EndDialog (10); //期望能返回 10
}
在 view 类随便找个能触发的地方,写上:
TestModal wnd;
int result = wnd.DoModal();
来测试 DoModal 返回值,但这窗口关不了,为什么?只能点左上角关闭,但返回2
在 MSDN 上看到下面话,所以做上面的测试下,不知是哪弄错了?
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.
===========================
void EndDialog(
int nResult
);
This member function returns nResult as the return value of DoModal.
------解决方案--------------------
EndDialog可以实现关闭的功能的呀。你确定你的代码执行到了,
------解决方案--------------------
在按钮事件里调用CDialog::OnOK()返回IDOK,调用CDialog::OnCancel()返回IDCANCEL
------解决方案--------------------
EndDialog (10)是对非模态对话框而言的,DoModal却弹出了一个模态对话框。
------解决方案--------------------
你要想修改返回值只要重载一个OnOK,修改它的返回值应该可以
------解决方案--------------------
http://topic.****.net/t/20040924/16/3406311.html
------解决方案--------------------
照你说的,做了下可以的呀。对话框关闭了,返回10。