MFC SplitterWnd
CSplitterWnd是一个特殊的框架窗口,它分割的每个窗口都被相同的或者不同的视图所填充。当窗口被切分后用户可以使用鼠标移动切分条来调整窗口的相对尺寸。
其定义如下:
/////////////////////////////////////////////////////////////////////////////
// Splitter Window
#define SPLS_DYNAMIC_SPLIT 0x0001
#define SPLS_INVERT_TRACKER 0x0002 // obsolete (now ignored)
class CSplitterWnd : public CWnd
{
DECLARE_DYNAMIC(CSplitterWnd)
// Construction
public:
CSplitterWnd();
// Create a single view type splitter with multiple splits
BOOL Create(CWnd* pParentWnd,
int nMaxRows, int nMaxCols, SIZE sizeMin,
CCreateContext* pContext,
DWORD dwStyle = WS_CHILD | WS_VISIBLE |
WS_HSCROLL | WS_VSCROLL | SPLS_DYNAMIC_SPLIT,
UINT nID = AFX_IDW_PANE_FIRST);
// Create a multiple view type splitter with static layout
BOOL CreateStatic(CWnd* pParentWnd,
int nRows, int nCols,
DWORD dwStyle = WS_CHILD | WS_VISIBLE,
UINT nID = AFX_IDW_PANE_FIRST);
virtual BOOL CreateView(int row, int col, CRuntimeClass* pViewClass,
SIZE sizeInit, CCreateContext* pContext);
// Attributes
public:
int GetRowCount() const;
int GetColumnCount() const;
// information about a specific row or column
void GetRowInfo(int row, int& cyCur, int& cyMin) const;
void SetRowInfo(int row, int cyIdeal, int cyMin);
void GetColumnInfo(int col, int& cxCur, int& cxMin) const;
void SetColumnInfo(int col, int cxIdeal, int cxMin);
// for setting and getting shared scroll bar style
//设置和获取共享的滚动条风格
DWORD GetScrollStyle() const;//获取共享的滚动条风格
void SetScrollStyle(DWORD dwStyle);//设置共享的滚动条风格
// views inside the splitter
//分割器内的视图
CWnd* GetPane(int row, int col) const;//获取窗格(Pane)
BOOL IsChildPane(CWnd* pWnd, int* pRow, int* pCol);//判断是否子窗格
BOOL IsChildPane(CWnd* pWnd, int& row, int& col); // obsolete
int IdFromRowCol(int row, int col) const;
BOOL IsTracking(); // TRUE during split operation
// Operations
public:
virtual void RecalcLayout(); // call after changing sizes
//重载函数:改变大小后调用,来重绘窗格或整个分割器
// Overridables
protected:
// to customize the drawing
enum ESplitType { splitBox, splitBar, splitIntersection, splitBorder };
virtual void OnDrawSplitter(CDC* pDC, ESplitType nType, const CRect& rect);
virtual void OnInvertTracker(const CRect& rect);
public:
// for customizing scrollbar regions
virtual BOOL CreateScrollBarCtrl(DWORD dwStyle, UINT nID);
// for customizing DYNAMIC_SPLIT behavior
virtual void DeleteView(int row, int col);//删除指定的视图
virtual BOOL SplitRow(int cyBefore);
virtual BOOL SplitColumn(int cxBefore);
virtual void DeleteRow(int rowDelete);
virtual void DeleteColumn(int colDelete);
// determining active pane from focus or active view in frame
//确定从焦点或活动视图帧活动窗格
virtual CWnd* GetActivePane(int* pRow = NULL, int* pCol = NULL);//获取活动窗格
virtual void SetActivePane(int row, int col, CWnd* pWnd = NULL);//设置活动窗格
protected:
CWnd* GetActivePane(int& row, int& col); // obsolete
public:
// high level command operations - called by default view implementation
//高级别命令操作 - 调用默认视图执行
virtual BOOL CanActivateNext(BOOL bPrev = FALSE);
virtual void ActivateNext(BOOL bPrev = FALSE);
virtual BOOL DoKeyboardSplit();
// synchronized scrolling
//同步滚动
virtual BOOL DoScroll(CView* pViewFrom, UINT nScrollCode,
BOOL bDoScroll = TRUE);
virtual BOOL DoScrollBy(CView* pViewFrom, CSize sizeScroll,
BOOL bDoScroll = TRUE);
// Implementation
public:
virtual ~CSplitterWnd();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// implementation structure
struct CRowColInfo
{
int nMinSize; // below that try not to show
int nIdealSize; // user set size
// variable depending on the available size layout
int nCurSize; // 0 => invisible, -1 => nonexistant
};
protected:
// customizable implementation attributes (set by constructor or Create)
//可定制的实现属性(由构造函数设置或创建)
CRuntimeClass* m_pDynamicViewClass;
int m_nMaxRows, m_nMaxCols;
// implementation attributes which control layout of the splitter
//其中控制分级的布局实施的属性
//分隔栏的大小
int m_cxSplitter, m_cySplitter; // size of splitter bar
//在分离器的任一侧的空间
int m_cxBorderShare, m_cyBorderShare; // space on either side of splitter
//窗格之间的空间量
int m_cxSplitterGap, m_cySplitterGap; // amount of space between panes
//在客户区边界
int m_cxBorder, m_cyBorder; // borders in client area
// current state information当前状态信息
int m_nRows, m_nCols;
BOOL m_bHasHScroll, m_bHasVScroll;
CRowColInfo* m_pColInfo;
CRowColInfo* m_pRowInfo;
// Tracking info - only valid when 'm_bTracking' is set
BOOL m_bTracking, m_bTracking2;
CPoint m_ptTrackOffset;
CRect m_rectLimit;
CRect m_rectTracker, m_rectTracker2;
int m_htTrack;
// implementation routines
BOOL CreateCommon(CWnd* pParentWnd, SIZE sizeMin, DWORD dwStyle, UINT nID);
virtual int HitTest(CPoint pt) const;
virtual void GetInsideRect(CRect& rect) const;
virtual void GetHitRect(int ht, CRect& rect);
virtual void TrackRowSize(int y, int row);
virtual void TrackColumnSize(int x, int col);
virtual void DrawAllSplitBars(CDC* pDC, int cxInside, int cyInside);
virtual void SetSplitCursor(int ht);
CWnd* GetSizingParent();
// starting and stopping tracking
virtual void StartTracking(int ht);
virtual void StopTracking(BOOL bAccept);
// special command routing to frame
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
//{{AFX_MSG(CSplitterWnd)
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnMouseMove(UINT nFlags, CPoint pt);
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags, CPoint pt);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint pt);
afx_msg void OnLButtonUp(UINT nFlags, CPoint pt);
afx_msg void OnCancelMode();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg BOOL OnNcCreate(LPCREATESTRUCT lpcs);
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnDisplayChange();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};