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:
- User triggers process
- Application shows the dialog
- Application starts the process function
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();
}
WM_INITDIALOG
handler to ensure the dialog handle will be available when the thread finishes and you want to close the dialog. – Andy Brown