关闭基于对话框的应用程序(退出)的最佳选择是什么? [英] What is the best option to close a dialog based application (Exit) !?
本文介绍了关闭基于对话框的应用程序(退出)的最佳选择是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我想知道什么是关闭基于对话框的应用程序的最佳选择,因为我对这些选项感到困惑:
Hello,
I want to know what is the best option to close a dialog based application, because I am really confused about these options:
SendMessage(WM_CLOSE);
PostMessage(WM_CLOSE);
DestroyWindow();
OnOK();
OnCancel();
PostQuitMessage(0);
或其他任何......
感谢您的理解。
or whatever else...
Thank you for your understanding.
推荐答案
这取决于您在申请中的位置:
在主对话框中,您可以使用:
It depend on where you are in the application :
in the main dialog, you can use :
EndDialog(code)
在另一个模态对话框中,当你回到主对话框方法时,你应该使用DoModal方法的返回值来停止你的应用程序。
in an other modal dialog, you should use the returned value of the DoModal method to stop or not your application when you are back in a main dialog method.
void CMainDialog::OnButtonClick()
{
CSubDialog dlg;
if(dlg.DoModal()==IDOK)
EndDialog(IDOK);
}
,将特定消息发布到主对话框并在其中执行操作。
in a modeless dialog, post a specific message to your main dialog and do action in it.
// To Insert in message handlers
ON_MESSAGE(WM_USER,CMainDialog::OnUserMessage)
// To post the message: AfxGetMainWnd()->PostMessage(WM_USER);
LRESULT CMainDialog::OnUserMessage(WPARAM wParam, LPARAM lParam)
{
// To do: CleanUp
EndDialog(IDOK);
}
这篇关于关闭基于对话框的应用程序(退出)的最佳选择是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文