【问题标题】:Show dialog form not in modal mode显示不在模态模式下的对话框表单
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-20
    • 2015-08-20
    • 2021-12-01
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多