1、
分割控件类:CSplitterControl
SplitterControl.h
SplitterControl.cpp
2、创建对象、增加资源
class xx
{
...
private:
CSplitterControl m_wndSplitter1; // 上下分割 IDC_SPLITTER_TOP 分割线资源更改资源可见属性为不可见,防止出现2条线
void DoResize1(int delta);
CSplitterControl m_wndSplitter2; // 左右分割 IDC_SPLITTER_LEFT
void DoResize2(int delta);
}
3、初始化
BOOL CT1Dlg::OnInitDialog()
{
...
// TODO: Add extra initialization here
{//m_wndSplitter1
CRect rc;
CWnd* pWnd;
pWnd = GetDlgItem(IDC_SPLITTER_TOP);
pWnd->GetWindowRect(rc);
ScreenToClient(rc);
m_wndSplitter1.Create(WS_CHILD | WS_VISIBLE, rc, this, IDC_SPLITTER_TOP);
CRect rc2;
GetDlgItem(IDOK)->GetWindowRect(&rc2);
ScreenToClient(&rc2);
CRect rc3;
GetDlgItem(IDCANCEL)->GetWindowRect(&rc3);
ScreenToClient(&rc3);
m_wndSplitter1.SetRange(rc2.bottom, rc3.top);
}
{// m_wndSplitter2
CRect rc;
CWnd* pWnd;
pWnd = GetDlgItem(IDC_SPLITTER_LEFT);
pWnd->GetWindowRect(rc);
ScreenToClient(rc);
m_wndSplitter2.Create(WS_CHILD | WS_VISIBLE, rc, this, IDC_SPLITTER_LEFT);
CRect rc2;
GetDlgItem(IDC_BUTTON1)->GetWindowRect(&rc2);
ScreenToClient(&rc2);
CRect rc3;
GetDlgItem(IDC_BUTTON2)->GetWindowRect(&rc3);
ScreenToClient(&rc3);
m_wndSplitter2.SetRange(rc2.right+1, rc3.left-1);
}
return TRUE; // return TRUE unless you set the focus to a control
}
LRESULT CT1Dlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if (message == WM_NOTIFY)
{
if (wParam == IDC_SPLITTER_TOP)
{
SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
DoResize1(pHdr->delta);
}
else if (wParam == IDC_SPLITTER_LEFT)
{
SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
DoResize2(pHdr->delta);
}
}
return CDialog::DefWindowProc(message, wParam, lParam);
}
void CT1Dlg::DoResize1(int delta)
{
CSplitterControl::ChangeHeight(GetDlgItem(IDC_BUTTON1),delta);
CSplitterControl::ChangeHeight(GetDlgItem(IDC_BUTTON2), -delta, CW_BOTTOMALIGN);
Invalidate();
2021-09-28 18:16:58
17KB
vc
1