【发布时间】:2014-04-07 10:22:18
【问题描述】:
我有对话框。要从我的应用程序中调用它,我使用代码:
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();
}
【问题讨论】:
-
搜索无模式对话框...
-
即使你把对话框改成无模式,你也不能让对话框在
CpointMFC2App::InitInstance()返回时挂起,因为dlg1会超出范围并被销毁,所以你的对话框会崩溃
标签: c++ visual-c++ mfc