MFC折叠一块区域

在Dlg.h里定义:

CRect m_rectLarge; //大区域
CRect m_rectSmall; //小区域
在Dlg.cpp初始化处:
GetWindowRect(&m_rectLarge);						//全部区域
GetDlgItem(IDC_STATIC_Segment)->GetWindowRect(&m_rectSmall);// IDC_STATIC_Segment,Picture控件的ID
OnBnClickedButtonSegment();//设置初始区域显示,否则包含扩展区域

添加按钮,picture控件,其中picture控件是用来作为分割区域的分界线的

按钮中:

void CXXXXDlg::OnBnClickedButtonSegment()
{
	// TODO: 在此添加控件通知处理程序代码
    CString str;

    if (GetDlgItemText(IDC_BUTTON_Segment, str), str == _T(">>"))
        SetDlgItemText(IDC_BUTTON_Segment, _T("<<"));
    else
        SetDlgItemText(IDC_BUTTON_Segment, _T(">>"));

    CRect rtSmall;
    rtSmall.SetRectEmpty();
    if (rtSmall.IsRectEmpty())
    {
        rtSmall.left = m_rectLarge.left;
        rtSmall.top = m_rectLarge.top;
        rtSmall.right = m_rectSmall.right;
        rtSmall.bottom = m_rectLarge.bottom;
    }
    if (str == "<<")
    {
        SetWindowPos(NULL, 0, 0, rtSmall.Width(), rtSmall.Height(), SWP_NOMOVE | SWP_NOZORDER);
    }
    else
    {
        SetWindowPos(NULL, 0, 0, m_rectLarge.Width(), m_rectLarge.Height(), SWP_NOMOVE | SWP_NOZORDER);
    }
}

效果图:

初始化时:

MFC折叠一块区域_第1张图片

点击按钮后:其中竖线为picture控件

MFC折叠一块区域_第2张图片


你可能感兴趣的:(MFC)