MFC 应用程序 Dialog基于使用 propertyPage,DoModal() for a CDialog 不打开任何对话框
MFC application DialogBased using propertyPage, DoModal() for a CDialog don't open any Dialog
在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"));
}
相关文章:
- "error: no matching function for call to"构造函数错误
- 表示"accepting anything for this template argument" C++概念的通配符
- 如何在C++中从两个单独的for循环中添加两个数组
- 在Linux for Windows上编译C++代码时出错
- 调用专用模板时出错"no matching function for call to [...]"
- 为什么我的for循环不能正确获取argv
- 为什么我不能在 FOR LOOP 中使用 i/10,C++?
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 在基于范围的for循环中使用结构化绑定声明
- 通过for循环使用用户输入填充列表
- 使用for循环检查数组中的重复项
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 正在使用for循环创建QScatterSerie
- Python中的for循环与C++有何不同
- std::memory_order for std::atomic:<T>:wait
- 在更改for循环的第三部分后,未使用for循环结果
- 在 for 循环中查找问题时遇到困难
- 嵌套for循环C++的问题(初学者)
- MFC 应用程序 Dialog基于使用 propertyPage,DoModal() for a CDialog 不打开任何对话框