0

这是我OnSize调整属性表大小的方法:

void CResizingMFCPropertySheet::OnSize(UINT nType, int cx, int cy)
{
    CMFCPropertySheet::OnSize(nType, cx, cy);

    if (!GetActivePage()) return;
    if (!GetTabControl()) return;

    if (nType == SIZE_MINIMIZED)
        return;

    int dx = cx - save_rc.Width();
    int dy = cy - save_rc.Height();

    int count = 0;
    for (CWnd *child = GetWindow(GW_CHILD); child; child = child->GetWindow(GW_HWNDNEXT))
        count++;

    HDWP hDWP = ::BeginDeferWindowPos(count);

    for (CWnd *child = GetWindow(GW_CHILD); child; child = child->GetWindow(GW_HWNDNEXT))
    {
        bool move = false;

        //If you add child controls manually, you want to move not resize
        if(child == &m_lblResize && m_lblResize.GetSafeHwnd() != nullptr)
            move = true;

        CRect r;
        child->GetWindowRect(&r);
        ScreenToClient(&r);

        if (move || child->SendMessage(WM_GETDLGCODE) & DLGC_BUTTON)
        {
            //move the main buttons and the child controls
            r.left += dx;
            r.top += dy;
            ::DeferWindowPos(hDWP, child->m_hWnd, 0, r.left, r.top, 0, 0,
                SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
        }
        else
        {
            //this must be a child window, resize it
            r.right += dx;
            r.bottom += dy;
            ::DeferWindowPos(hDWP, child->m_hWnd, 0, 0, 0, r.Width(), r.Height(),
                SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
        }
    }

    ::EndDeferWindowPos(hDWP);
    GetClientRect(&save_rc);
    Invalidate(TRUE);
}

但是,如果我像这样更改属性表的外观和感觉:

SetIconsList(IDB_MAINT_DB_LARGE, 32);
SetLook(CMFCPropertySheet::PropSheetLook_OutlookBar);

然后我调整我的属性表的大小:

展望栏

我们如何调整OnSize以单独保留 Outlook 栏的宽度?我们只需要调整高度。

有此问题和相关答案,但 Microsoft 知识库文章答案中的链接不起作用。无论哪种方式,OnSize都需要自定义才能PropSheetLook_OutlookBar正确呈现。不知何故 ...

更新

根据 Spy,它是一个工具栏:

间谍结果

4

1 回答 1

2

我做的第一件事是将其添加到我的调整大小类标题中:

protected:
    CWnd* InitNavigationControl() override;
private:
    CWnd * m_pNavigationControl;

然后,我将其添加到源文件中:

CWnd* CResizingMFCPropertySheet::InitNavigationControl()
{
    m_pNavigationControl = CMFCPropertySheet::InitNavigationControl();

    return m_pNavigationControl;
}

最后,我调整了OnSize方法:

void CResizingMFCPropertySheet::OnSize(UINT nType, int cx, int cy)
{
    CMFCPropertySheet::OnSize(nType, cx, cy);

    if (!GetActivePage()) return;
    if (!GetTabControl()) return;

    if (nType == SIZE_MINIMIZED)
        return;

    int dx = cx - save_rc.Width();
    int dy = cy - save_rc.Height();

    int count = 0;
    for (CWnd *child = GetWindow(GW_CHILD); child; child = child->GetWindow(GW_HWNDNEXT))
        count++;

    HDWP hDWP = ::BeginDeferWindowPos(count);
    for (CWnd *child = GetWindow(GW_CHILD); child; child = child->GetWindow(GW_HWNDNEXT))
    {
        bool move = false;

        //If you add child controls manually, you want to move not resize
        if(child == &m_lblResize && m_lblResize.GetSafeHwnd() != nullptr)
            move = true;

        CRect r;
        child->GetWindowRect(&r);
        ScreenToClient(&r);

        if (move || child->SendMessage(WM_GETDLGCODE) & DLGC_BUTTON)
        {
            //move the main buttons and the child controls
            r.left += dx;
            r.top += dy;
            ::DeferWindowPos(hDWP, child->m_hWnd, 0, r.left, r.top, 0, 0,
                SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
        }
        else
        {
            if (child->GetSafeHwnd() == m_pNavigationControl->GetSafeHwnd())
            {
                r.bottom += dy;
                ::DeferWindowPos(hDWP, child->m_hWnd, nullptr,
                    r.left, r.top, r.Width(), r.Height(),
                    SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
            }
            else
            {
                //this must be a child window, resize it
                r.right += dx;
                r.bottom += dy;
                ::DeferWindowPos(hDWP, child->m_hWnd, 0, 0, 0, r.Width(), r.Height(),
                    SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
            }
        }
    }

    ::EndDeferWindowPos(hDWP);
    GetClientRect(&save_rc);
    Invalidate(TRUE);
}

如您所见,我们能够针对导航控件的处理程序进行测试。所以结果:

酒吧

于 2018-06-23T12:27:44.630 回答