Ani*_*amy 1 c++ windows mfc messagebox
我有一个奇怪的问题.请考虑以下情形:
关于事情如何发生的伪代码:(请在这里忽略语法正确性)
MainWindowClass mainObj;
void MainWindowClass::OnSomeButtonClick()
{
SomeDialogClass someDialogObj;
someDialogObj.DoModal();
}
int MainWindowClass::doTask()
{
// Do work
if(ERROR)
{
MessageBox("Yikes! Something went wrong.", "Error", MB_OK);
return ERROR;
}
}
///////////////////////////////////////////////////////////////////
// Meanwhile, in another file,
extern MainWindowClass mainObj;
void SomeDialogClass::OnCancel()
{
// Do all cleanup and close dialog
}
int SomeDialogClass::workerThreadFunc()
{
return mainObj.doTask();
}
int SomeDialogClass::DoModal()
{
AfxBeginThread(workerThreadFunc);
// Do all other work and then wait for the worker thread
}
Run Code Online (Sandbox Code Playgroud)
我的问题是双重的:
我认为使用模态对话框的一个主要原因是它能够防止焦点转到父对话框.然而,当显示该错误消息框时,我可以愉快地单击该对话框,然后单击"取消"并假装错误消息框从未显示.
它应该将错误情况发送回UI线程,而不是让您的工作线程调出一个模态消息框.我对MFC和多线程的体验是,在同一个线程中处理所有UI会使事情变得更简单,并消除这些类型的错误.有两个线程可能同时提出模态对话框是一个麻烦.
| 归档时间: |
|
| 查看次数: |
1036 次 |
| 最近记录: |