在网上搜索了很久, 没找到满意的, 后来到google用英文答案, 终于找到一个方法, 真是想见恨晚,,, 有两种方法:
第一种:
增加一个成员变量m_Visible 到 对话框类 并在构造函数里初始化为FALSE 重载消息处理函数 OnWindowPosChanging.第二种:
- void CTestDlg::OnWindowPosChanging( WINDOWPOS* lpwndpos )
- {
- if ( !m_bVisible )
- lpwndpos->flags &= ~SWP_SHOWWINDOW ;
- CDialog::OnWindowPosChanging(lpwndpos);
- }
- Add a function to show/hide the app.
- void CTestDlg::DisplayWindow( BOOL bShow )
- {
- if ( bShow )
- {
- m_bVisible = TRUE;
- ShowWindow( SW_SHOWNORMAL );
- }
- else
- {
- m_bVisible = FALSE;
- ShowWindow( SW_HIDE );
- }
- }
- Post a user defined message in OnInitDialog, and position the dialog
- off-screen. In the processing of the user defined message hide the
- window, and when you want to display it you can reposition
- it and show it. Here's the general idea:
- BEGIN_MESSAGE_MAP(CMindlgDlg, CDialog)
- //{{AFX_MSG_MAP(CMindlgDlg)
- ...
- //}}AFX_MSG_MAP
- ON_MESSAGE( WM_APP+1, OnAppMsg )
- END_MESSAGE_MAP()
- BOOL CMindlgDlg::OnInitDialog()
- {
- ...
- // TODO: Add extra initialization here
- SetWindowPos( NULL, -1000, -1000, 0, 0,
- SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
- PostMessage( WM_APP+1 );
- return TRUE;
- }
- LRESULT CMindlgDlg::OnAppMsg(WPARAM, LPARAM)
- {
- ShowWindow( SW_HIDE );
- return 0;
- }