xref: /MusicPlayer2/MusicPlayer2/HorizontalSplitter.h (revision 60368c71d22f8ce822b7ef88733e1a9eff53d268)
1 #pragma once
2 //来自 https://blog.csdn.net/mary288267/article/details/123483656
3 
4 // CHorizontalSpliter
5 
6 //用于响应布局变化的回调函数,调用RegAdjustLayoutCallBack以注册此回调函数
7 //rect 分割条的矩形区域
8 typedef void(*pfAdjustLayout)(CRect rect);
9 
10 class CHorizontalSplitter : public CStatic
11 {
12 	DECLARE_DYNAMIC(CHorizontalSplitter)
13 
14 public:
15 	CHorizontalSplitter();
16 	virtual ~CHorizontalSplitter();
17 
18     //设置移动分割条过程中对话框两侧的最小距离
19     void SetMinWidth(int left, int right);
20     //分割条左侧的控件ID
21     BOOL AttachCtrlAsLeftPane(DWORD idCtrl);
22     //分割条右侧的控件ID
23     BOOL AttachCtrlAsRightPane(DWORD idCtrl);
24     //拆离分割条左右两侧的控件
25     BOOL DetachAllPanes();
26     //根据分割条位置,调整对话框上所有控件位置
27     void AdjustLayout();
28 
29     //注册响应布局变化的回调函数。如果调用了此函数,则分割条位置改变时,分割条两侧的控件大小将不再自动调整,
30     //而是调用注册的回调函数,由回调函数处理两侧控件的调整。
31     //通过此函数注册响应布局变化的回调函数后,将不再需要调用AttachCtrlAsLeftPane和AttachCtrlAsRightPane函数。
32     void RegAdjustLayoutCallBack(pfAdjustLayout pFunc);
33 
34 protected:
35     //分割条可以移动的范围
36     BOOL GetMouseClipRect(LPRECT rcClip, CPoint point);
37     afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
38     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
39     afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
40     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
41     DECLARE_MESSAGE_MAP()
42 
43 private:
44     CRect m_rcOrgRect;
45     CRect m_rcOldRect;
46     CWnd* m_pParent;
47     CPoint m_pPointStart;
48 
49     int m_iLeftMin, m_iRightMin;
50     CDWordArray m_idLeft, m_idRight;
51     pfAdjustLayout m_pAdjLayoutFunc{};
52 
53 public:
54     afx_msg void OnPaint();
55     virtual void PreSubclassWindow();
56 };
57 
58 
59