c++ - 显示最初隐藏的无模型对话框

标签 c++ winapi visual-c++ mfc

我有无模型子对话框。在资源属性中可见标志设置为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/

相关文章:

c++ - 本地分配的内存可以用于将来使用吗?

c++ - 要自定义消息框,我应该挂接消息框还是使用 CreateWindowEx 来创建一个模仿?

c# - 从代码设置桌面背景颜色

c++ - Visual Studio 2013 : fatal error C1083: Cannot open include file: 'winsock2.h' : No such file or directory

windows - 读取随身碟时 CreateFile() 失败,错误代码为 32

php.net 的 PHP 开始标签

c++ - 在C++中用<<声明一个int

c++ - main 在 pthread 之后不继续

c++ - C++中是否可以继承operator()?

c++ - 在 C++ 中创建字符串时出错