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 />

ff.Close();<br />

Destroying the Old List<br />

Whenever the current working directory is changed, we need to call function CExplorerView::<br />

ChangeDir() to create new file list. Before building a new one, we need to delete the old list. In the sample,<br />

this is implemented by function CExplorerView::DestroyList(). Within this function, both list items and<br />

image lists are deleted:<br />

void CExplorerView::DestroyList()<br />

{<br />

CImageList *pilCtrl;<br />

}<br />

GetListCtrl().DeleteAllItems();<br />

pilCtrl=GetListCtrl().GetImageList(LVSIL_NORMAL);<br />

if(pilCtrl != NULL)<br />

{<br />

pilCtrl->DeleteImageList();<br />

delete pilCtrl;<br />

}<br />

pilCtrl=GetListCtrl().GetImageList(LVSIL_SMALL);<br />

if(pilCtrl != NULL)<br />

{<br />

pilCtrl->DeleteImageList();<br />

delete pilCtrl;<br />

}<br />

Since we can retrieve the pointers of image list from the list control, there is no need for us to store<br />

them as variables. This function is called in function CExplorerView::ChangeDir() and WM_DESTROY<br />

message handler.<br />

Using Function CExplorerView::ChangeDir()<br />

At this point, we still do not allow the user to select a directory by clicking on a directory node in the<br />

tree view window. So we can only display the files and directories contained in the root directory when the<br />

application is first invoked. This is implemented in function CExplorerView::OnInitialUpdate(), where<br />

we find the first available drive, and call function CExplorerView::ChangeDir() to create the list view:<br />

void CExplorerView::OnInitialUpdate()<br />

{<br />

int drive;<br />

CListView::OnInitialUpdate();<br />

for(drive=1; drive

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

Saved successfully!

Ooh no, something went wrong!