在CDialog中关闭滚动条后如何停止有白色背景?

问题描述 投票:0回答:1

我的对话框(在资源编辑器中)已打开调整大小和最大化/最小化。

但是,如果我发现我不需要此功能,因为它们的显示屏尺寸足够大,我想将其关闭。

所以我这样做了:

int CResizingDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    const CDC* pDC = GetDC();
    if (pDC != nullptr)
    {
        const int iHorz = pDC->GetDeviceCaps(HORZRES);
        const int iVert = pDC->GetDeviceCaps(VERTRES);

        bool showHorz = true;
        bool showVert = true;

        if (lpCreateStruct->cx < iHorz)
        {
            // Remove the WS_HSCROLL style to disable the horizontal scroll bar
            ModifyStyle(WS_HSCROLL, 0);
            showHorz = false;
        }

        if (lpCreateStruct->cy < iVert)
        {
            // Remove the WS_VSCROLL style to disable the vertical scroll bar
            ModifyStyle(WS_VSCROLL, 0);
            showVert = false;
        }

        if (!showHorz && !showVert && m_bModalWindow)
        {
            // Remove the WS_THICKFRAME style rtc to disable resizing
            ModifyStyle(WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0);
        }
    }

    if (__super::OnCreate(lpCreateStruct) == -1)
        return -1;

    return 0;
}

它有效,但是看:

enter image description here

我现在在右侧/底部有两个白色矩形,我在其中关闭了滚动条。我们该如何解决这个问题?

visual-c++ mfc dialog scrollbar
1个回答
0
投票

我需要打电话给

SetWindowPos
,如下所示:

int CResizingDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    const CDC* pDC = GetDC();
    if (pDC != nullptr)
    {
        const int iHorz = pDC->GetDeviceCaps(HORZRES);
        const int iVert = pDC->GetDeviceCaps(VERTRES);

        bool showHorz = true;
        bool showVert = true;

        if (lpCreateStruct->cx < iHorz)
        {
            // Remove the WS_HSCROLL style to disable the horizontal scroll bar
            ModifyStyle(WS_HSCROLL, 0);
            showHorz = false;
        }

        if (lpCreateStruct->cy < iVert)
        {
            // Remove the WS_VSCROLL style to disable the vertical scroll bar
            ModifyStyle(WS_VSCROLL, 0);
            showVert = false;
        }

        if (!showHorz && !showVert && m_bModalWindow)
        {
            // Remove the WS_THICKFRAME style etc to disable resizing
            ModifyStyle(WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, WS_DLGFRAME);
        }

        // Apply new frame styles (important for cache update)
        SetWindowPos(nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
    }

    if (__super::OnCreate(lpCreateStruct) == -1)
        return -1;

    return 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.