CodeRider
CodeRider

Reputation: 1814

Resizing a modeless property sheet

I have a class derived from CPropertysheet. It has two property pages in it. I have made the sheet modeless. But resizing using the mouse drag is not possible. How to make the propertysheet a resizable one?

Upvotes: 1

Views: 2117

Answers (1)

Barmak Shemirani
Barmak Shemirani

Reputation: 31599

For modal property sheet see links in comment section. For modeless version, create the property sheet with WS_THICKFRAME. This is enough to make the dialog resizable. For example:

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

To handle the resizing, add the following members:

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);
    ...
};

Overload OnInitDialog as follows:

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;
}

The rest of it is explained in MSDN example:

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);
}

Also add ON_WM_SIZE and ON_WM_GETMINMAXINFO to message map

Upvotes: 5

Related Questions