If we have an existing project one needs to do the following steps to add an non-modal dialog.
Example Project:
ModelessDialog.zip (45,5 KiB)
class CSecondDialogApp : public CWinApp { public: CSecondDialogApp(); DlgSecond* m_pDlgSecond; // Überschreibungen public: virtual BOOL InitInstance(); // Implementierung DECLARE_MESSAGE_MAP() }; extern CSecondDialogApp theApp;
with m_pDlgSecond the member variable of the new dialog.
Also add the header file with #include "DlgSecond.h" to the same file.
void CSecondDialogDlg::OnBnClickedButtonShowSecondDialog() { if (theApp.m_pDlgSecond != NULL) { theApp.m_pDlgSecond->SetForegroundWindow(); theApp.m_pDlgSecond->SetFocus(); } else { theApp.m_pDlgSecond = new DlgSecond; theApp.m_pDlgSecond->Create(DlgSecond::IDD); // Ausgabe initialisieren theApp.m_pDlgSecond->ShowWindow(SW_SHOW); } }
CSecondDialogDlg::~CSecondDialogDlg() { if (theApp.m_pDlgSecond != NULL) { delete [] theApp.m_pDlgSecond; } }