manatttta
manatttta

Reputation: 3124

MFC create Modeless dialog that does not lose focus

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();
}

Upvotes: 1

Views: 775

Answers (1)

sergiol
sergiol

Reputation: 4335

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.

Upvotes: 1

Related Questions