Hiding an MFC dialog box

后端 未结 3 1455
再見小時候
再見小時候 2021-02-06 12:50

Ok so I am using this code to hide the taskbar icon of a dialog based MFC application(VC++). The taskbar icon and the dialog box hide whenever I click on the cross or the close

3条回答
  •  一向
    一向 (楼主)
    2021-02-06 13:25

    If you show your dialog using CDialog::DoModal() the framework will make sure your dialog is shown. There is only one way to prevent a modal dialog from being shown:

    BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
        ON_WM_WINDOWPOSCHANGING()
    END_MESSAGE_MAP()
    
    BOOL CHiddenDialog::OnInitDialog()
    {
        CDialog::OnInitDialog();
        m_visible = FALSE;
    
        return TRUE;
    }
    
    void CHiddenDialog::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 
    {
        if (!m_visible)
            lpwndpos->flags &= ~SWP_SHOWWINDOW;
    
        CDialog::OnWindowPosChanging(lpwndpos);
    }
    

提交回复
热议问题