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 14. Views<br />

}<br />

if<br />

(<br />

)<br />

{<br />

}<br />

if<br />

(<br />

)<br />

{<br />

}<br />

TRACE0("Failed to CreateStaticSplitter\n");<br />

return FALSE;<br />

!m_wndSplitter.CreateView<br />

(<br />

0, 0, RUNTIME_CLASS(CDirFormView), CSize(100, 100), pContext<br />

)<br />

TRACE0("Failed to create first pane\n");<br />

return FALSE;<br />

!m_wndSplitter.CreateView<br />

(<br />

0, 1, RUNTIME_CLASS(CExplorerView), CSize(100, 100), pContext<br />

)<br />

TRACE0("Failed to create first pane\n");<br />

return FALSE;<br />

}<br />

return TRUE;<br />

Functions CSplitterWnd::CreateStatic(…) and CSplitterWnd::CreateView(…) are called to create<br />

the splitter window and each individual pane. Please note that we must include “afxcview.h” in the header<br />

files of both class CExplorerView and CDirView, otherwise the compilation will generate errors.<br />

The only result of this sample is a two-way splitted window. We will add further features in the next<br />

several sections.<br />

14.4 Simple Explorer, Step 2: List Drives<br />

Sample 14.4\Explorer is based on sample 14.3\Explorer.<br />

We will display four types of items in the tree view window (left pane of splitter window): desktop,<br />

computer, drives, directories. The root node is desktop node, and there will be only one such type of node.<br />

Under the desktop node, there will be a computer node, which lists the computer name. Under the computer<br />

node, all the available drives will be listed, under each drive node, directories will be listed. With this<br />

structure, the file system of the whole computer can be displayed.<br />

Creating Image List<br />

Each node can have a label and also an associated image. Although they both are optional features,<br />

implementing them can make our application look more professional. To use images, we must create an<br />

image list and select it into the tree control. The image list can be created from either DIB images or icons.<br />

As we know from Chapter 5, the simplest way to create image list is to prepare images as the resources<br />

then load them at run time. In the sample, five images are prepared for the tree control, whose usage is<br />

listed in the following table:<br />

ID<br />

IDB_BITMAP_DESKTOP<br />

IDB_BITMAP_COMPUTER<br />

IDB_BITMAP_HARD<br />

IDB_BITMAP_OPENFOLDER<br />

Usage<br />

Desktop node<br />

Computer node<br />

Node for displaying a drive<br />

Node for displaying an opened (expanded) file folder<br />

436

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

Saved successfully!

Ooh no, something went wrong!