11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3. Splitter Window<br />

Split box<br />

Split box<br />

Figure 3-3. Double clicking on any of the split boxes will divide<br />

the window into panes dynamically<br />

This behavior could be customized. For example, sometimes by double clicking on the split bar, we<br />

want to resize the two panes instead of deleting one of them. This feature gives the user much convenience<br />

for changing the size of each pane bit by bit.<br />

Split bar<br />

Figure 3-4. Double clicking on the split bar will delete one of the<br />

two panes divided by the split bar<br />

Splitter Window Layout<br />

We need to override the following two member functions of class CSplitterWnd in order to implement<br />

this feature: CSplitterWnd::DeleteRow(…) and CSplitterWnd::DeleteColumn(…). When the user double<br />

clicks on the split bar, one of the two functions will be called to delete a row or column dynamically. In<br />

order to customize this behavior, after the split bar is clicked, we can first change the size of each pane,<br />

then judge if the size of one pane is smaller than its minimum size. If so, we call the default implementation<br />

of the corresponding function to delete one row or column.<br />

To change a pane’s size, we need to call function CSplitterWnd::SetColumnInfo(…) and<br />

CSplitterWnd::SetRowInfo(…). The current size of a pane could be obtained by their counterpart<br />

functions CSplitterWnd::GetColumnInfo(…) and CSplitterWnd::GetRowInfo(…). The following shows<br />

the formats of the above four functions:<br />

void CSplitterWnd::SetColumnInfo(int col, int cxIdeal, int cxMin);<br />

void CSplitterWnd::SetRowInfo(int row, int cyIdeal, int cyMin);<br />

void CSplitterWnd::GetColumnInfo(int col, int& cxCur, int& cxMin);<br />

void CSplitterWnd::GetRowInfo(int row, int& cyCur, int& cyMin);<br />

62

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!