模态对话框的隐藏

在网上搜索了很久, 没找到满意的, 后来到google用英文答案, 终于找到一个方法, 真是想见恨晚,,, 有两种方法:

第一种:

增加一个成员变量m_Visible 到 对话框类 并在构造函数里初始化为FALSE
重载消息处理函数 OnWindowPosChanging.

 
 
[cpp] view plain cop
  1. void CTestDlg::OnWindowPosChanging( WINDOWPOS* lpwndpos )  
  2. {  
  3. if ( !m_bVisible )  
  4. lpwndpos->flags &= ~SWP_SHOWWINDOW ;  
  5.   
  6. CDialog::OnWindowPosChanging(lpwndpos);  
  7. }  
  8.   
  9. Add a function to show/hide the app.  
  10.   
  11. void CTestDlg::DisplayWindow( BOOL bShow )  
  12. {  
  13. if ( bShow )  
  14. {  
  15. m_bVisible = TRUE;  
  16. ShowWindow( SW_SHOWNORMAL );  
  17. }  
  18. else  
  19. {  
  20. m_bVisible = FALSE;  
  21. ShowWindow( SW_HIDE );  
  22. }  
  23. }  
第二种:
  1. Post a user defined message in OnInitDialog, and position the dialog  
  2. off-screen. In the processing of the user defined message hide the  
  3. window, and when you want to display it you can reposition  
  4. it and show it. Here's the general idea:  
  5.   
  6. BEGIN_MESSAGE_MAP(CMindlgDlg, CDialog)  
  7. //{{AFX_MSG_MAP(CMindlgDlg)  
  8. ...  
  9. //}}AFX_MSG_MAP  
  10. ON_MESSAGE( WM_APP+1, OnAppMsg )  
  11. END_MESSAGE_MAP()  
  12.   
  13. BOOL CMindlgDlg::OnInitDialog()  
  14. {  
  15. ...  
  16.   
  17. // TODO: Add extra initialization here  
  18. SetWindowPos( NULL, -1000, -1000, 0, 0,  
  19. SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );  
  20.   
  21. PostMessage( WM_APP+1 );  
  22.   
  23. return TRUE;  
  24. }  
  25.   
  26. LRESULT CMindlgDlg::OnAppMsg(WPARAMLPARAM)  
  27. {  
  28. ShowWindow( SW_HIDE );  
  29. return 0;  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值