nav-left cat-right
Matthias Pospiech > Programming > C++ > MFC > Add non modal dialog to project

Add non modal dialog to project

If we have an existing project one needs to do the following steps to add an non-modal dialog.

Example Project: (45,5 KiB)
  1. Add a new dialog to the project and add a class for that dialog
  2. Add a member variable for the dialog to the application class.
    If our project is called ‘SecondDialog’ the application class would then look like this
    class CSecondDialogApp : public CWinApp
    	DlgSecond* m_pDlgSecond;
    // Überschreibungen
    	virtual BOOL InitInstance();
    // Implementierung
    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.

  3. Add an Button (or Menu entry) to the project which shall show the dialog
    This function should then have the following content to open the dialog when the button is clicked
    void CSecondDialogDlg::OnBnClickedButtonShowSecondDialog()
    	if (theApp.m_pDlgSecond != NULL) {
    	else {		
    		theApp.m_pDlgSecond = new DlgSecond;
    		// Ausgabe initialisieren		
  4. Make sure the variable is deleted
    	if (theApp.m_pDlgSecond != NULL) 
    		delete [] theApp.m_pDlgSecond;

Einen Kommentar schreiben

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *


Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

WP-SpamFree by Pole Position Marketing