MFC:创建无模式对话框而不显示
我正在尝试创建一个简单的无模式对话框,该对话框是从 CWinApp 派生的 InitInstance() 函数创建的。
BOOL CMyApp::InitInstance()
{
...
m_pMyDialog = new CMyDialog();
m_pMyDialog->Create(CMyDialog::IDD);
...
retrun TRUE;
}
我已在资源编辑器中创建了对话框模板,并且 WS_VISIBLE 位未设置。我的目的是避免显示对话框,直到我显式调用 ShowWindow(SW_SHOW),但由于某种原因,对 Create 的调用显示了该对话框。
我尝试将 OnInitDialog() 的返回值更改为 FALSE,但这不起作用。
我什至尝试调用ModifyStyle()以防其他东西设置WS_VISIBLE位。
int CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
ModifyStyle(WS_VISIBLE, 0);
return 0;
}
那也行不通。在所有情况下,在我调用“创建”后,都会显示对话框,这不是我所读到的它应有的工作方式。
I'm trying to create a simple modeless dialog box which I'm creating from my CWinApp derived InitInstance() function.
BOOL CMyApp::InitInstance()
{
...
m_pMyDialog = new CMyDialog();
m_pMyDialog->Create(CMyDialog::IDD);
...
retrun TRUE;
}
I've created the dialog template in the resource editor and the WS_VISIBLE bit is unset. My intention is to avoid showing the dialog until I explicitly call ShowWindow(SW_SHOW) but for some reason the call to Create displays the dialog.
I've tried to change the return value of OnInitDialog() to FALSE but that doesn't work.
I've even tried to call ModifyStyle() in case something else is setting the WS_VISIBLE bit.
int CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
ModifyStyle(WS_VISIBLE, 0);
return 0;
}
That doesn't work either. In all cases, after I call Create the dialog is displayed which isn't how I've read it should work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在 AnimateWindow() 上,它导致对话框过早显示。
The problem was with AnimateWindow() which was causing the dialog to display prematurely.