Convert modal dialogs to modeless
- In your header file define a CWinThread-derived class...
class CDialogThread : public CWinThread
virtual BOOL InitInstance();
- Put this in your implementation file (where CSomeDialog is a conventional dialog class defined the usual way).
- To create an instance of your (now-modeless) modal dialog, do this...
AfxBeginThread ( RUNTIME_CLASS(CDialogThread) );
- You can end the dialog the normal way by calling CDialog::EndDialog(), CDialog::OnCancel() or CDialog::OnOK(). All those special caveats about modeless dialogs (like "don't call EndDialog") no longer apply with this approach.
- One point to note is the return of 'FALSE' from the InitInstance() override. This tells MFC that the thread didn't start successfully, so MFC does our cleanup for us! Note that by this time the dialog has already returned and we're through with the thread. This is the same thing MFC-generated code does in the InitInstance() of dialog-based applications.