1
votes

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:

  1. User triggers process
  2. Application shows the dialog
  3. 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();
}
1
Start a thread and do the processing there.Jabberwocky
Run your task in a thread. You can start the thread in the WM_INITDIALOG handler to ensure the dialog handle will be available when the thread finishes and you want to close the dialog.Andy Brown
@MichaelWalz my processing is done inside a separate thread already, but CmodguiApp::_notify_task_start(); and CmodguiApp::_notify_task_end(); must be called in that threadmanatttta
Make your dialog modal and start the thread in OnInitDialog.Jabberwocky
@manatttta: What about a TopMost Modal dialog?hypheni

1 Answers

1
votes

Try the following approach:

  1. Call the

    _processing_dialog->DoModal();

  2. On the Process dialog class do it wherever appropriate:

    AfxGetApp()->GetMainWnd()->SendMessage(WM_YOUR_USER_MESSAGE)

  3. On the main window class message map, add

    ON_MESSAGE(WM_YOUR_USER_MESSAGE, YourUserMessageHandlerFunction)

  4. Implement the YourUserMessageHandlerFunction(). Now you have retaken the handling at the main window.