调整无模式属性表的大小

时间:2016-03-15 04:18:31

标签: c++ visual-c++ mfc

我有一个派生自CPropertysheet的类。它有两个属性页面。我让这张纸无模式。但是无法使用鼠标拖动进行大小调整。如何使propertiesysheet成为可调整大小的?

1 个答案:

答案 0 :(得分:5)

对于模态属性表,请参阅注释部分中的链接。对于无模式版本,请使用WS_THICKFRAME创建属性表。这足以使对话框可调整大小。例如:

propSheet->Create(this, WS_THICKFRAME | 
    WS_VISIBLE | WS_SYSMENU | WS_POPUP | WS_VISIBLE | WS_CAPTION);

要处理调整大小,请添加以下成员:

class CMyPropertySheet:public CPropertySheet
{
    CRect save_rc;//used in OnSize
    CRect minimum_rc;//used in OnGetMinMaxInfo
    BOOL OnInitDialog();
    void OnSize(UINT nType, int cx, int cy);
    void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);
    ...
};

重载OnInitDialog如下:

BOOL CMyPropertySheet::OnInitDialog()
{
    //override for modeless:
    m_bModeless = FALSE;
    m_nFlags |= WF_CONTINUEMODAL;
    BOOL bResult = CPropertySheet::OnInitDialog();
    m_bModeless = TRUE;
    m_nFlags &= ~WF_CONTINUEMODAL;

    //save rectangles for resizing
    GetClientRect(&save_rc); //save the old rect for resizing
    GetClientRect(&minimum_rc); //save the original rect for OnGetMinMaxInfo

    return bResult;
}

其余部分在MSDN示例中进行了解释:

void CMyPropertySheet::OnSize(UINT nType, int cx, int cy)
{
    CPropertySheet::OnSize(nType, cx, cy);

    if(nType == SIZE_MINIMIZED)
        return;

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

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

    //count how many childs are in window
    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))
    {
        CRect r;
        child->GetWindowRect(&r);
        ScreenToClient(&r);
        if (child->SendMessage(WM_GETDLGCODE) & DLGC_BUTTON)
        {
            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
        {
            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);
}

void CMyPropertySheet::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
    lpMMI->ptMinTrackSize.x = minimum_rc.Width();
    lpMMI->ptMinTrackSize.y = minimum_rc.Height();
    CPropertySheet::OnGetMinMaxInfo(lpMMI);
}

同时将ON_WM_SIZEON_WM_GETMINMAXINFO添加到邮件地图