創建一個新類用來隱藏主對話框閃爍問題
注釋下段代碼:
1 CPrinterMonitorExDlg dlg;
2 m_pMainWnd = &dlg;
3 INT_PTR nResponse = dlg.DoModal();
4 if (nResponse == IDOK)
5 {
6 // TODO: Place code here to handle when the dialog is
7 // dismissed with OK
8 }
9 else if (nResponse == IDCANCEL)
10 {
11 // TODO: Place code here to handle when the dialog is
12 // dismissed with Cancel
13 }
替換成:
1 CMainDialog dlg; //新類對象
2 m_pMainWnd = &dlg;
3 dlg.Create(CMainDialog::IDD);
4 dlg.ShowWindow(SW_HIDE);
5 dlg.RunModalLoop();
用對話框隱藏等待程序,在xp系統下會出現一個問題,就是:如果程序是system權限啟動,第一次注銷機器正常,但第二次注銷時就會出現注銷失敗的情況。隱藏的對話框在注銷時無法被關閉。
可以用事件等待來代替上面的程序。
1 CEvent m_evtWait;
2 if (WAIT_FAILED == ::WaitForSingleObject(m_evtWait, INFINITE))
3 {
4 DWORD wError = GetLastError();
5 LOG("WaitForSingleObject函數出現錯誤,錯誤代碼:%d,程序退出", wError);
6 return FALSE;
7 }
posted on 2012-04-10 16:02
王海光 閱讀(603)
評論(0) 編輯 收藏 引用 所屬分類:
MFC