MFC隐藏主对话框无闪烁

MFC隐藏主对话框无闪烁
    创建一个新类用来隐藏主对话框闪烁问题

    注释下段代码:
 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      }

你可能感兴趣的:(MFC隐藏主对话框无闪烁)