Re: [問題] 請問console程式如何調用MFC

看板C_and_CPP作者 (Hallowed be my name)時間15年前 (2010/09/20 20:30), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《Gaiger (交換關聯)》之銘言: 現在是這樣的 遇到一些thread control的問題。 我讓 console部份盡量簡節: 就呼叫個 CreateDLG()的 函數,這函數是在DLL中的程式唯一接口, 在MFC DLL部份 CreateDLG如下: #include "stdafx.h" #include "Resource.h" #include "MFCDlg.h" #include "CreateDLG.h" #include "MFC.h" __declspec(dllexport) BOOL CreateDLG(void) { CMFCApp theApp ; theApp.InitInstance(); AFX_MANAGE_STATE(AfxGetStaticModuleState()); return TRUE; }/*BOOL*/ 就是呼叫主要的 CMFCApp CMFCApp的InitInstance為: BOOL CMFCApp::InitInstance() { BOOL suc = CWinApp::InitInstance(); CMFCDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); return 0; return FALSE; }/*InitInstance*/ 其他部份全是創建對話框時自帶的程式碼。 這樣可以跑出個對話框,但程式馬上掛掉。 在下發現是掛在 Dlg 的OnPaint裡: void CMFCDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); /*運行完這行就死*/ } } 在下想是不是Thread的問題,因為這行是不能注消掉的, 不然就不會更新這對話框了。 試了很久還是不知道怎辦啊。。 有大大能幫我一下嗎,謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.120.158.204 ※ 編輯: Gaiger 來自: 59.120.158.204 (09/20 20:30)
文章代碼(AID): #1CbrFQeI (C_and_CPP)
文章代碼(AID): #1CbrFQeI (C_and_CPP)