MFC 应用程序 Dialog基于使用 propertyPage,DoModal() for a CDialog 不打开任何对话框

MFC application DialogBased using propertyPage, DoModal() for a CDialog don't open any Dialog

本文关键字:CDialog for 对话框 任何 Dialog 应用程序 于使用 propertyPage DoModal MFC      更新时间:2023-10-16

在VS2013中,我创建了一个基于对话的MFC应用程序。我修改了项目,以便在应用程序开始时使用 PropertyPage 和 Propertysheet,因此,它不会启动 CDialog,而是启动我的属性页。

之后,我创建了一个对话框,并且类关联(from::CdialogEx)。我想在单击按钮后打开此对话框。

在我的按钮点击背后,我确实:

CMyDialog myDialog;
myDialog.DoModal();

我没有任何错误消息,但是,我没有在屏幕上显示我的对话框。

也许是因为这个对话框没有孩子没有?

有人可以帮我吗?

多谢

此致敬意

尼克塞斯

编辑:

这是我的切入点:

#include "stdafx.h"
#include "KenoApp.h"
#include "KenoDlg.h"
#include "GenerationDlg.h"
#include "KenoSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CKenoApp
BEGIN_MESSAGE_MAP(CKenoApp, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()

// construction CKenoApp
CKenoApp::CKenoApp()
{
}

// Seul et unique objet CKenoApp
CKenoApp theApp;

// initialisation de CKenoApp
BOOL CKenoApp::InitInstance()
{
    AfxEnableControlContainer();
    // Standard initialization
#ifdef _AFXDLL
        // Call this when using MFC in a shared DLL
#else
    Enable3dControlsStatic();   // Call this when linking to MFC statically
#endif
    CKenoSheet KenoSheet;
    KenoSheet.SetTitle(L"Keno Helper v1.1");
    CGenerationDlg Generation;
    CKenoDlg KenoDlg;
    KenoSheet.AddPage(&KenoDlg);
    KenoSheet.AddPage(&Generation);
    //m_pMainWnd = &KenoSheet;
    int nResponse = KenoSheet.DoModal();
    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
}

之后,在我的财产页面上:

CAboutDlg myDialog;
theApp.m_pMainWnd = &myDialog;
myDialog.DoModal();

我的问题是,DoModal() 关闭了我的应用程序。

快速修复:在应用程序的InitInstance()

CMyPropSheet pps(_T("My Property Sheet"), NULL, 0);
//m_pMainWnd = &pps;        // *** remark away this line if you have it
int nResponse = pps.DoModal();
// do response ...
CTestDlg dlg;
m_pMainWnd = &dlg;          // this line is a must have
nResponse = dlg.DoModal();
// do response ...

上面的代码假设属性表和对话框将在应用程序的 InitInstance() 中依次启动。在收到更多信息后,似乎这不是您想要的方式,因此上面的代码不适用于您的问题。请在使用我的建议之前将您的代码恢复为原始代码。

你能发布myDialog.DoModal();通话的结果吗?

您可以尝试以下代码段:

模 态:

CMyDialog myDialog = new CMyDialog();
if(myDialog != NULL)
{
    BOOL ret = myDialog->Create(10000, this);
    if(!ret)
        AfxMessageBox(_T("Error creating Dialog"));
    myDialog->ShowWindow(SW_SHOW);
}
else
{
    AfxMessageBox(_T("Error Creating Dialog Object"));
}