vico
vico

Reputation: 18171

Show dialog form not in modal mode

I have dialog form. To call it from my application I use code:

BOOL CpointMFC2App::InitInstance()
{
    CWinApp::InitInstance();
    Dialog dlg1;
    dlg1.txt= "NotificationText";
    int r= dlg.DoModal();
        return r;
}

And now I don't wont to have modal mode - I would like to let program go without waiting user input. How to make my dlg1 show in non modal mode?

Dialog form:

#include "stdafx.h"
#include "pointMFC2.h"
#include "Dialog.h"
#include "afxdialogex.h"


// Dialog dialog

IMPLEMENT_DYNAMIC(Dialog, CDialogEx)

Dialog::Dialog(CWnd* pParent /*=NULL*/)
    : CDialogEx(Dialog::IDD, pParent)
{

}

Dialog::~Dialog()
{
}

void Dialog::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(Dialog, CDialogEx)
    ON_BN_CLICKED(IDOK, &Dialog::OnBnClickedOk)
END_MESSAGE_MAP()


// Dialog message handlers
BOOL Dialog::OnInitDialog() 
{
        CDialogEx::OnInitDialog();
        SetWindowText(txt);
        return TRUE;
}

void Dialog::OnBnClickedOk()
{
    // TODO: Add your control notification handler code here
    CDialogEx::OnOK();
}

Upvotes: 0

Views: 447

Answers (1)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10415

To create a nonmodal dialog you have to call the dialog's Create function. Do this in the constructor of your dialog class. Then you must return TRUE from InitInstance to keep the program running.

m_pMainWnd = new Dialog();
return TRUE; // Run MFC message pump

Upvotes: 1

Related Questions