使用Windows MFC C++.我有一个第三方应用程序,它在我的CWinApp派生类中调用用户定义的方法.在InitInstance()之后调用此方法.如果此方法中存在错误,则抛出异常并捕获到try/catch块中,我想从catch块退出应用程序.什么是规范和正确的退出方式?
更新:
Serge我认为是正确的,在InitInstance()中返回false是退出应用程序的正确方法.但是,现在假设我想从CDialog派生类的OnInitDialog()处理程序退出,这是正确的方法.
更新2
对我来说,我发现调用PostMessage(WM_CLOSE)是我的非模态CDialog派生类的最佳方法.我试过的所有其他戒烟方法都会在某些情况下引发一些例外情况.
这是我如何使用它的一个例子:
BOOL SomeDialog::OnInitDialog()
{
CDialog::OnInitDialog();
::OleInitialize(nullptr);
try
{
// ...load settings file here
}
catch(...)
{
PostMessage(WM_CLOSE);
return TRUE;
}
// return TRUE unless you set the focus to a control
return TRUE;
}
Run Code Online (Sandbox Code Playgroud)