MFC 대화 상자 기반 창 응용 프로그램이 있습니다. 기본 대화 상자 양식 작성은 아래 코드와 같습니다. 별도의 스레드에서 실행되는 일부 코드가 있으며 때로는 대화 상자 창에 메시지를 보내야합니다. 이를 위해 창 핸들러가 필요합니다.대화 상자 창 핸들러 가져 오기
줄 MyAppDlg.GetSafeHwnd()는 0을 반환합니다. 왜? 대화 상자 창 핸들러를 얻는 방법? 작동하지 않습니다 - 대화가 DoModal
로 생성되기 전에
BOOL CMyApp::InitInstance()
{
CWinApp::InitInstance();
// Activate "Windows Native" visual manager for enabling themes in MFC controls
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
startAll(NULL);
CMyAppDlg MyAppDlg;
m_pMainWnd = &MyAppDlg;
m_pActiveWnd = &MyAppDlg;
AuthMsgHWND = MyAppDlg.GetSafeHwnd();
INT_PTR nResponse = MyAppDlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n");
TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}