且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

隐藏MFC对话框

更新时间:2023-02-11 22:20:43

如果你使用 CDialog :: DoModal()显示你的对话框将显示您的对话框。只有一种方法可防止显示模态对话:

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);
}