C++ 不在模式模式下显示对话框窗体

C++ 不在模式模式下显示对话框窗体,c++,visual-c++,mfc,C++,Visual C++,Mfc,我有对话表。要从我的应用程序调用它,我使用以下代码: BOOL CpointMFC2App::InitInstance() { CWinApp::InitInstance(); Dialog dlg1; dlg1.txt= "NotificationText"; int r= dlg.DoModal(); return r; } 现在我不习惯使用模态模式——我想让程序在不等待用户输入的情况下运行。如何在非模态模式下显示dlg1 对话形式: #in

我有对话表。要从我的应用程序调用它,我使用以下代码:

BOOL CpointMFC2App::InitInstance()
{
    CWinApp::InitInstance();
    Dialog dlg1;
    dlg1.txt= "NotificationText";
    int r= dlg.DoModal();
        return r;
}
现在我不习惯使用模态模式——我想让程序在不等待用户输入的情况下运行。如何在非模态模式下显示dlg1

对话形式:

#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();
}

要创建非模态对话框,必须调用对话框的create函数。在对话框类的构造函数中执行此操作。然后您必须从InitInstance返回TRUE以保持程序运行

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

搜索关于无模式对话框…即使将对话框更改为无模式,当
CpointMFC2App::InitInstance()
返回时,也不能让对话框挂起,因为
dlg1
将超出范围并被销毁,因此对话框将崩溃