调整无模式属性表的大小 [英] Resizing a modeless property sheet

查看:91
本文介绍了调整无模式属性表的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从CPropertysheet派生的类.它具有两个属性页.我已经使工作表变得无模式了.但是无法使用鼠标拖动来调整大小.如何使属性表可调整大小?

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?

推荐答案

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

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

重载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示例中进行了解释:

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

还要在邮件地图中添加ON_WM_SIZEON_WM_GETMINMAXINFO

Also add ON_WM_SIZE and ON_WM_GETMINMAXINFO to message map

这篇关于调整无模式属性表的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆