[英]A Dialog derived from CDialog returns -1 after DoModal (MFC/C++)
[英]MFC application DialogBased using propertyPage, DoModal() for a CDialog don't open any Dialog
在VS2013中,我創建了一個基於對話框的MFC應用程序。 我修改了該項目,以便在應用程序的開頭使用PropertyPage和Propertysheet,因此,它不會啟動CDialog,而是啟動了我的propertypage。
之后,我創建了一個Dialog,並且該類與(from :: CdialogEx)關聯。 我想在單擊按鈕后打開此對話框。
在我的按鈕單擊后,我執行以下操作:
CMyDialog myDialog;
myDialog.DoModal();
我沒有任何錯誤消息,但是,我沒有在屏幕上顯示我的對話框。
可能是因為此對話框沒有子代嗎?
有人可以幫我嗎?
非常感謝,
最好的祝福,
Nixeus
編輯:
這是我的切入點:
#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()內部依次依次啟動PropertySheet和Dialog。 從您那里獲得更多信息之后,看來這不是您想要的方式,因此上面的代碼不適用於您的問題。 在使用我的建議之前,請先將代碼還原為原始代碼。
您可以發布myDialog.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"));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.