11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 14. Views<br />

ON_COMMAND(ID_BUTTON_FORMATITALIC, CRichEditView::OnCharItalic)<br />

ON_COMMAND(ID_BUTTON_FORMATLEFT, CRichEditView::OnParaLeft)<br />

ON_UPDATE_COMMAND_UI(ID_BUTTON_FORMATBOLD, CRichEditView::OnUpdateCharBold)<br />

ON_UPDATE_COMMAND_UI(ID_BUTTON_FORMATCENTER, CRichEditView::OnUpdateParaCenter)<br />

ON_UPDATE_COMMAND_UI(ID_BUTTON_FORMATITALIC, CRichEditView::OnUpdateCharItalic)<br />

ON_UPDATE_COMMAND_UI(ID_BUTTON_FORMATLEFT, CRichEditView::OnUpdateParaLeft)<br />

ON_UPDATE_COMMAND_UI(ID_BUTTON_FORMATRIGHT, CRichEditView::OnUpdateParaRight)<br />

ON_UPDATE_COMMAND_UI(ID_BUTTON_FORMATUNDER, CRichEditView::OnUpdateCharUnderline)<br />

With the above implementation, the editor can let the user set the character and paragraph properties.<br />

14.3 Simple Explorer, Step 1: Preparation<br />

Starting from this section we are going to create an Explorer-like application using classes CTreeView<br />

and CListView. The application is based on an SDI application whose client window is implemented by a<br />

2-pane splitter window. We will use CTreeView to create the left pane, and use CListView to create the<br />

right pane. One the left pane, the file system (directories) will be displayed in a tree form, the user can click<br />

on any node to select a directory, or double click on it to expand the node (show all the sub-directories). On<br />

the right pane, all files and sub-directories contained in the currently selected directory will be listed, they<br />

can be displayed in one of the four styles supported by list view.<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

1. ID_BUTTON_FORMATCENTER<br />

2. ID_BUTTON_FORMATRIGHT<br />

3. ID_BUTTON_FORMATBOLD<br />

4. ID_BUTTON_FORMATUNDER<br />

5. ID_BUTTON_FORMATITALIC<br />

6. ID_BUTTON_FORMATLEFT<br />

Figure 14-1. New commands<br />

We have introduced how to create splitter window in Chapter 3. Obviously here we need to create<br />

static splitter windows. Application Wizard does have a choice to let us create splitter window, however, it<br />

can only help us with creating dynamic splitter window. We can modify the dynamic splitter window to<br />

static splitter window after the application is generated. To let the Application Wizard generate code for<br />

implementing dynamic splitter window, we can click “<strong>Advanced</strong>…” button (in step 4) and check “Use split<br />

widow” check box in the popped up dialog box.<br />

In order to create a splitter window with two panes implemented by different types of views, first we<br />

must implement two view classes. Here, one of the views can be implemented as we go through the<br />

Application Wizard’s project creation steps: in the final step, we can select CListView as the view’s base<br />

class. The other class can be added after the project is generated by Class Wizard.<br />

Sample 14.3\Explorer is created this way. It is a standard SDI application, with first view generated by<br />

Application Wizard whose name is CExplorerView. The second view is added by Class Wizard, whose<br />

base class is CTreeView and the class name is CDirView. In function CMainFrame::OnCreateClient(…), the<br />

splitter window is created using the above two classes:<br />

BOOL CMainFrame::OnCreateClient<br />

(<br />

LPCREATESTRUCT lpcs,<br />

CCreateContext *pContext<br />

)<br />

{<br />

if<br />

(<br />

!m_wndSplitter.CreateStatic<br />

(<br />

this, 1, 2, WS_CHILD | WS_VISIBLE, AFX_IDW_PANE_FIRST<br />

)<br />

)<br />

{<br />

435

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

Saved successfully!

Ooh no, something went wrong!