MFC 运行时隐藏对话框窗口(无闪烁)

转:http://blog.163.com/pirates_fish/blog/static/1833331502011102215626741/

本人推荐三种:

一、初始化

BOOL CHideWndDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 ....

 // TODO: Add extra initialization her

  ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);//从任务栏中去掉.
  SetWindowPos(&wndTop,0,0,0,0,NULL);

  return TRUE; 

}

二、初始化

BOOL CHideWndDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 ....

 // TODO: Add extra initialization her

  ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);//从任务栏中去掉.
  WINDOWPLACEMENT wp;
  wp.length=sizeof(WINDOWPLACEMENT);
  wp.flags=WPF_RESTORETOMAXIMIZED;
  wp.showCmd=SW_HIDE;
  SetWindowPlacement(&wp);

  return TRUE; 

}

三、类视图中重写DefWindowProc

LRESULT CTrayDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
 // TODO: 在此添加专用代码和/或调用基类
 ShowWindow(SW_HIDE);
 return CDialog::DefWindowProc(message, wParam, lParam);
}

你可能感兴趣的:(C++)