C++ MFC应用程序DialogBased使用propertyPage,对于CDDialog don';不要打开任何对话框

C++ MFC应用程序DialogBased使用propertyPage,对于CDDialog don';不要打开任何对话框,c++,visual-studio-2010,winapi,mfc,dialog,C++,Visual Studio 2010,Winapi,Mfc,Dialog,在VS2013中,我创建了一个基于对话框的MFC应用程序。 我修改项目是为了在应用程序开始时使用PropertyPage和Propertysheet,因此,它不启动CDialog,而是启动我的PropertyPage 之后,我创建了一个对话框,类关联(from::CdialogEx)。 我想在点击按钮后打开此对话框 在我的按钮点击后,我会: CMyDialog myDialog; myDialog.DoModal(); #include "stdafx.h" #include "KenoApp

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

之后,我创建了一个对话框,类关联(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();
我没有任何错误消息,但是,我没有在屏幕上显示我的对话框

可能是因为这个对话框没有子对象没有

有人能帮我吗

非常感谢

致以最良好的祝愿

尼克松

编辑:

这是我的切入点:

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();
之后,在我的属性页上:

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()关闭了我的应用程序。

你能发布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"));
}

你能发布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"));
}

快速修复:在应用程序的
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 ...

上面的代码假设PropertySheet和对话框将在应用程序的InitInstance()内依次启动。在您提供了更多信息之后,似乎这不是您想要的方式,因此上述代码不适用于您的问题。在使用我的建议之前,请将代码还原为原始代码。

快速修复:在应用程序的
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 ...


上面的代码假设PropertySheet和对话框将在应用程序的InitInstance()内依次启动。在您提供了更多信息之后,似乎这不是您想要的方式,因此上述代码不适用于您的问题。在使用我的建议之前,请将您的代码还原为原始代码。

能否尝试将对话框显示为非模态对话框?否,如何执行此操作?我尝试使用ShowWindow()方法,但我有一个断言错误!在以下位置尝试代码:Trying和error(请参见顶部);)您是否已查看以确保代码正在查找对话框资源?当找不到资源时,对话框创建通常会失败。能否尝试将对话框显示为无模式对话框?否,如何执行此操作?我尝试使用ShowWindow()方法,但我有一个断言错误!在以下位置尝试代码:Trying和error(请参见顶部);)您是否已查看以确保代码正在查找对话框资源?当找不到资源时,对话框创建通常会失败。您好,我是tred,但是在Creat()上,我有一个断言错误。我在第一个初始线程上附加了错误消息。在
Create(10000,this)中更改
10000
对话框模板资源的ID号。告诉我们此位置的断言类型。WindowsShow的断言类型?断言(::IsWindow(m_hWnd)| |(m_pCtrlSite!=NULL));AfxWin2.inl中的CWnd::GetSafeHwnd()似乎返回false。您好,我是tred,但是在Create()上,我有一个断言错误。我在第一个初始线程上附加了错误消息。在
Create(10000,这个)中更改
10000
对话框模板资源的ID号。告诉我们此位置的断言类型。WindowsShow的断言类型?断言(::IsWindow(m_hWnd)| |(m_pCtrlSite!=NULL));AfxWin2.inl中的CWnd::GetSafeHwnd()似乎返回false。我尝试了您的解决方案。删除行“m_pMainWnd=&pps”,并在DoModal()之前添加行“app.m_pMainWnd=&myDialog”,并在DoModal()上关闭我的应用程序!没有错误消息,但请关闭应用程序@WalterFabioSimoni-Propertysheet和对话框启动的顺序是什么,是否与我建议的代码中的顺序相同,一个接一个?或者您正在尝试在Propertysheet内启动对话框?m_pMainWnd应该是应用程序的唯一主窗口。将其设置到应用程序类后,一旦此m_pMainWnd句柄无效/被破坏,应用程序将自行终止。@WalterFabioSimoni-上述代码假定将在应用程序的InitInstance()内依次启动PropertySheet和对话框。在您提供了更多信息之后,似乎这不是您想要的方式,因此上述代码不适用于您的问题。在使用我的建议之前,请将您的代码还原为原始代码。@WalterFabioSimoni-实际上,我以您实现的方式使用自己的虚拟PropertySheet/Dialog类测试了您的代码,在按PropertySheet按钮激活对话框时,我没有遇到任何问题。我认为您的dialog类可能有一些bug,阻止了它的创建。您应该单独测试对话框以隔离问题,并确认可以/无法创建该对话框,并且问题是/不是由属性表引起的。这可以通过用对话框替换属性表并在调试模式下运行来解决问题。任何重要的事情,我都已经解决了!怎样?我将对话框样式设置为DS_NOFAILCREATE。没关系!但是…为什么创建失败了?我的对话框中只有一个控件,它是一个按钮!我试过你的解决办法。删除行“m_pMainWnd=&pps”,并在DoModal()之前添加行“app.m_pMainWnd=&myDialog”,并在DoModal()上关闭我的应用程序!没有错误消息,但请关闭应用程序@WalterFabioSimoni-Propertysheet和对话框启动的顺序是什么,是否与我建议的代码中的顺序相同,一个接一个?或者您正在尝试在Propertysheet内启动对话框?m_pMainWnd应该是应用程序的唯一主窗口。将其设置到应用程序类后,应用程序将