嘗試運行簡單的MFC應用程序,但由於程序終止而關閉,假設我需要在單獨的線程中運行對話框,但無法解決問題。啓動時關閉的MFC應用程序
這裏是到目前爲止的代碼:
CWinApp theApp;
using namespace std;
int main(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
HMODULE hModule = ::GetModuleHandle(NULL);
theApp.InitApplication();
theApp.InitInstance();
theApp.Run();
AfxWinTerm();
if (hModule != NULL)
{
// initialize MFC and print and error on failure
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
MyDialog *mdlg = new MyDialog();
mdlg->Create(IDD_MDLG, theApp.m_pMainWnd);
mdlg->ShowWindow(true);
}
}
else
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
nRetCode = 1;
}
return nRetCode;
}
必須有簡單的東西,我可以做從終止保持程序,只是不知道如何?
看着這一點,但我的班(從一個CDialog繼承)沒有成員「DoModel」? – user3047190
如果這是MFC CDialog,那麼它肯定確實有DoModal(通過繼承):http://msdn.microsoft.com/pl-pl/library/619z63f5.aspx – marcinj
是的我是一個白癡,我得到一個調試斷言失敗: //無法在已構建爲無模式的對話框上調用DoModal \t ASSERT(m_hWnd == NULL); – user3047190