怎样让一个基于对话框的MFC程序一启动就不可见。也就是隐藏对话框。
谢谢! 问题点数:20、回复次数:4Top
1 楼Skt32(荒城之月)回复于 2003-05-03 23:33:08 得分 0
ShowWindow(SW_HIDE)Top
2 楼tigerfox(风之力:=Doing.浪淘沙)回复于 2003-05-03 23:57:06 得分 20
Starting a modal dialog hidden
You often hear people complain that despite putting a ShowWindow(SW_HIDE) in their OnInitDialog their modal dialog still starts up in a shown state. The 2problem here is that when CDialog::OnInitDialog() finishes it will call S2howWindow(SW_SHOW). Thus your dialog box is again made visisble. But then as, is to be expected, people have worked around this. Here is what you need to do.
Add a BOOL member to your dialog class and call it something, say visible.
Now in your dialog constructor set visible to false.
visible = false;
Now you need to override WM_WINDOWPOSCHANGING. You might have to change your message filtering options to have this message show up in the Class Wizard.
void CTest_deleteDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
if(!visible)
lpwndpos->flags &= ~SWP_SHOWWINDOW;
CDialog::OnWindowPosChanging(lpwndpos);
}
That's it. Now your modal dialog actually starts up in a hidden state. And when you want to make it visible this is what you need to do.
visible = true;
ShowWindow(SW_SHOW);
come from http://www.codeproject.com/dialog/dlgboxtricks.aspTop




