Reputation: 3124
I want to create a dialog in MFC that, once it shows up, it can't lose focus. This is for blocking the user access to the main SDI window, while it is processing data. The flow is something similar to:
I can't do this with a Modal dialog, because the DoModal()
function doesn't return until the dialog closes, so this will never trigger the step 3.
How can this be done?
Edit
These are the functions for notifying a task start and task end:
void CmodguiApp::_notify_task_start() {
_processing_dialog->DoModal();
}
void CmodguiApp::_notify_task_end() {
_processing_dialog->EndDialog(1);
}
This is the code triggering a task process:
void trigger_task(std::function<void()> f) {
CmodguiApp::_notify_task_start();
f();
CmodguiApp::_notify_task_end();
}
Upvotes: 1
Views: 775
Reputation: 4335
Try the following approach:
Call the
_processing_dialog->DoModal();
On the Process dialog class do it wherever appropriate:
AfxGetApp()->GetMainWnd()->SendMessage(WM_YOUR_USER_MESSAGE)
On the main window class message map, add
ON_MESSAGE(WM_YOUR_USER_MESSAGE, YourUserMessageHandlerFunction)
Implement the YourUserMessageHandlerFunction()
. Now you have retaken the handling at the main window.
Upvotes: 1