根据http://www.codeguru.com中的一个可显示隐藏或显示的splitter改造而来,可以隐藏左右栏或者上下栏的splitter类。
1 /////////////////////////////////////////////////////////////////////////////
2 // CLockSplitter
3
4 CLockSplitter::CLockSplitter():m_nHidedCol(-1), m_nHidedRow(-1)
5 {
6 }
7
8 CLockSplitter::~CLockSplitter()
9 {
10 }
11
12
13 BEGIN_MESSAGE_MAP(CLockSplitter, CSplitterWnd)
14 //{{AFX_MSG_MAP(CLockSplitter)
15 ON_WM_LBUTTONDOWN()
16 ON_WM_SIZE()
17 //}}AFX_MSG_MAP
18 END_MESSAGE_MAP()
19
20 /////////////////////////////////////////////////////////////////////////////
21 // CLockSplitter message handlers
22
23 void CLockSplitter::OnLButtonDown(UINT nFlags, CPoint point)
24 {
25
26 //CSplitterWnd::OnLButtonDown(nFlags, point);
27 }
28
29 void CLockSplitter::OnSize(UINT nType, int cx, int cy)
30 {
31 RECT rect;
32 int Width;
33 GetClientRect(&rect);
34 Width = rect.right - rect.left - 115;
35 if(m_pColInfo != NULL)
36 if(Width < 0)
37 SetColumnInfo(0,1,1);
38 else
39 SetColumnInfo(0,Width,Width);
40
41 CSplitterWnd::OnSize(nType, cx, cy);
42 }
43
44
45 void CLockSplitter::ShowColumn()
46 {
47 ASSERT_VALID(this);
48 ASSERT(m_nCols < m_nMaxCols);
49 ASSERT(m_nHidedCol != -1);
50
51 int colNew = m_nHidedCol;
52 m_nHidedCol = -1;
53 int cxNew = m_pColInfo[m_nCols].nCurSize;
54 m_nCols++; // add a column
55 ASSERT(m_nCols == m_nMaxCols);
56
57 // fill the hidden column
58 int col;
59 for (int row = 0; row < m_nRows; row++)
60 {
61 CWnd* pPaneShow = GetDlgItem(AFX_IDW_PANE_FIRST + row * 16 + m_nCols);
62 ASSERT(pPaneShow != NULL);
63 pPaneShow->ShowWindow(SW_SHOWNA);
64
65 for (col = m_nCols - 2; col >= colNew; col--)
66 {
67 CWnd* pPane = GetPane(row, col);
68 ASSERT(pPane != NULL);
69 pPane->SetDlgCtrlID(IdFromRowCol(row, col + 1));
70 }
71
72 pPaneShow->SetDlgCtrlID(IdFromRowCol(row, colNew));
73 }
74
75 // new panes have been created -- recalculate layout
76 for (col = colNew + 1; col < m_nCols; col++)
77 m_pColInfo[col].nIdealSize = m_pColInfo[col - 1].nCurSize;
78 m_pColInfo[colNew].nIdealSize = cxNew;
79 RecalcLayout();
80
81 CFrameWnd* myWnd = (CFrameWnd*)AfxGetMainWnd();
82 myWnd->SetActiveView((CView*)this->GetPane(0,colNew));
83 }
84
85 void CLockSplitter::ShowRow()
86 {
87 ASSERT_VALID(this);
88 ASSERT(m_nRows < m_nMaxRows);
89 ASSERT(m_nHidedRow != -1);
90
91 int rowNew = m_nHidedRow;
92 m_nHidedRow = -1;
93
94 int cyNew = m_pRowInfo[m_nRows].nCurSize;
95 m_nRows++; // add a row
96 ASSERT(m_nRows == m_nMaxRows);
97
98 // fill the hidden row
99 int row;
100 for (int col = 0; col < m_nCols; col++)
101 {
102 CWnd* pPaneShow = GetDlgItem(AFX_IDW_PANE_FIRST + col * 16 + m_nRows);
103 ASSERT(pPaneShow != NULL);
104 pPaneShow->ShowWindow(SW_SHOWNA);
105
106 for (row = m_nRows - 2; row >= rowNew; row--)
107 {
108 CWnd* pPane = GetPane(row, col);
109 ASSERT(pPane != NULL);
110 pPane->SetDlgCtrlID(IdFromRowCol(row + 1, col));
111 }
112 pPaneShow->SetDlgCtrlID(IdFromRowCol(rowNew, col));
113 }
114
115 // new panes have been created -- recalculate layout
116 for (row = rowNew + 1; row < m_nRows; row++)
117 m_pRowInfo[row].nIdealSize = m_pRowInfo[row - 1].nCurSize;
118
119 m_pRowInfo[rowNew].nIdealSize = cyNew;
120 RecalcLayout();
121
122 CFrameWnd* myWnd = (CFrameWnd*)AfxGetMainWnd();
123 myWnd->SetActiveView((CView*)GetPane(rowNew,0));
124 }
125
126 void CLockSplitter::HideRow(int rowHide)
127 {
128 ASSERT_VALID(this);
129 ASSERT(m_nRows > 1);
130 ASSERT(rowHide < m_nRows);
131 ASSERT(m_nHidedRow == -1);
132 m_nHidedRow = rowHide;
133
134 // if the column has an active window -- change it
135 int rowActive, colActive;
136 if (GetActivePane(&rowActive, &colActive) != NULL &&
137 rowActive == rowHide)
138 {
139 if (++rowActive >= m_nRows)
140 rowActive = 0;
141 SetActivePane(rowActive, colActive);
142 }
143
144 // hide all column panes
145 for (int col = 0; col < m_nCols; col++)
146 {
147 CWnd* pPaneHide = GetPane(rowHide, col);
148 ASSERT(pPaneHide != NULL);
149 pPaneHide->ShowWindow(SW_HIDE);
150 pPaneHide->SetDlgCtrlID(AFX_IDW_PANE_FIRST + col * 16 + m_nRows); //命名该id
151
152 for (int row = rowHide + 1; row < m_nRows; row++)
153 {
154 CWnd* pPane = GetPane(row, col);
155 ASSERT(pPane != NULL);
156 pPane->SetDlgCtrlID(IdFromRowCol(row, col - 1));
157 }
158 }
159
160 m_nRows--;
161 m_pRowInfo[m_nRows].nCurSize = m_pRowInfo[rowHide].nCurSize;
162
163 RecalcLayout();
164 }
165
166 void CLockSplitter::HideColumn(int colHide)
167 {
168 ASSERT_VALID(this);
169 ASSERT(m_nCols > 1);
170 ASSERT(colHide < m_nCols);
171 ASSERT(m_nHidedCol == -1);
172 m_nHidedCol = colHide;
173
174 // if the column has an active window -- change it
175 int rowActive, colActive;
176 if (GetActivePane(&rowActive, &colActive) != NULL &&
177 colActive == colHide)
178 {
179 if (++colActive >= m_nCols)
180 colActive = 0;
181 SetActivePane(rowActive, colActive);
182 }
183
184 // hide all column panes
185 for (int row = 0; row < m_nRows; row++)
186 {
187 CWnd* pPaneHide = GetPane(row, colHide);
188 ASSERT(pPaneHide != NULL);
189 pPaneHide->ShowWindow(SW_HIDE);
190 pPaneHide->SetDlgCtrlID(
191 AFX_IDW_PANE_FIRST + row * 16 + m_nCols);
192
193 for (int col = colHide + 1; col < m_nCols; col++)
194 {
195 CWnd* pPane = GetPane(row, col);
196 ASSERT(pPane != NULL);
197 pPane->SetDlgCtrlID(IdFromRowCol(row, col - 1));
198 }
199 }
200 m_nCols--;
201 m_pColInfo[m_nCols].nCurSize = m_pColInfo[colHide].nCurSize;
202 RecalcLayout();
203 }
204
205