我有无模型子对话框。在资源属性中可见标志设置为true。(根据我在资源属性中可见标志的要求应该为true)。
我想在最初显示时以编程方式隐藏对话框。
我使用下面的代码覆盖了 presubclasswindow 并删除了 WS_VISIBLE 标志,但对话框并未隐藏。
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);
}
}
请任何人帮助我实现我的要求
最佳答案
您还可以覆盖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()
仅当您不希望它显示对话框时才启用此覆盖。确保禁用覆盖,否则永远不会显示对话框。
dlg.m_override_showwindow = true;
dlg.Create(...);
dlg.m_override_showwindow = false;
MessageBox(L"Test...");
dlg.ShowWindow(SW_SHOW);
关于c++ - 显示最初隐藏的无模型对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39771342/