显示最初隐藏的无模型对话框 [英] Show modelless dialog initially hidden
问题描述
我有无模型子对话框.在资源属性中,可见标志设置为true.(根据我在资源属性中的要求,可见标志应为true).
I have modelless child dialog. In resource properties Visible flag is set as true.(As per my requirement in resource properties visible flag should be true).
我想在最初显示时以编程方式隐藏对话框.
I want to programmatically hide the dialog while initially displaying.
我重写了presubclasswindow,并使用下面的代码删除了WS_VISIBLE标志,但是对话框没有被隐藏.
I overrided the presubclasswindow and removed the WS_VISIBLE flag using below code but the dialog is not getting hidden.
void CAddressChildDlg::PreSubclassWindow()
{
CWnd::PreSubclassWindow();
if (::IsWindow(m_hWnd))
{
LONG lStyle = GetWindowLong(m_hWnd, GWL_STYLE);
lStyle &= ~WS_VISIBLE;
SetWindowLong(m_hWnd, GWL_STYLE, lStyle);
}
}
请任何人帮助我达到我的要求
Please anyone help me to achieve my requirement
推荐答案
您还可以覆盖ON_WM_WINDOWPOSCHANGING
class CMyDialog : public CDialog
{
public:
bool m_override_showwindow;
//initialize somewhere ...
void OnWindowPosChanging(WINDOWPOS* wpos)
{
if (m_override_showwindow)
wpos->flags &= ~SWP_SHOWWINDOW;
CDialog::OnWindowPosChanging(wpos);
}
DECLARE_MESSAGE_MAP()
...
};
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_WM_WINDOWPOSCHANGING()
...
END_MESSAGE_MAP()
仅当您不希望其显示对话框时才启用此替代.确保禁用替代,否则将永远不会显示对话框.
Enable this override only when you don't want it to show the dialog. Make sure to disable the override otherwise dialog is never shown.
dlg.m_override_showwindow = true;
dlg.Create(...);
dlg.m_override_showwindow = false;
MessageBox(L"Test...");
dlg.ShowWindow(SW_SHOW);
这篇关于显示最初隐藏的无模型对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!