在启动前隐藏一个MFC DoModal对话框

实现在启动对话框前将DoModal对话框隐藏掉

1、在对话框中添加WM_WINDOWPOSCHANGING消息处理

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);
}
2、调用ShowWindows()重新显示对话框

m_visible = TRUE;
ShowWindow(SW_SHOW);


参考链接:

http://stackoverflow.com/questions/8255106/hiding-an-mfc-dialog-box

http://forums.codeguru.com/showthread.php?231065-MFC-Dialog-How-to-start-your-dialog-application-in-hidden-mode


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