Question

I have simple application that has one MFC dialog based form as main window. Now I need to create form (dialog based is ok) that will be available in whole application lifetime. I'm planning to display status information when will be needed and hide it when no need. How to declare and create that form to be showed not in modal mode, but like independent another form. Main form might be hidden in system tray sometimes, but status for should remain on desktop.

Application creates main dialog form:

BOOL CpointMFC2App::InitInstance()
{
...
CpointMFC2Dlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
...
}

Main 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();
}
Was it helpful?

Solution

Either create the dialog with CreateDialog. Than the dialog is modeless, but still needs a working message loop. This should be the normal way. You can hide and show the dialog, or destroy it and recreate it anytime you want.

There is another way, depending on how you want to use this dialog. You can start a second UI frame, and launch the dialog either modal or modeless there. This dialog has the advantage to be always responsible even the main thread is busy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top