Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 21: Tree and List Controls


return (ModifyStyle(LVS_TYPEMASK, dwViewType & LVS_TYPEMASK));
}


  1. From the Resource View tab, display the IDR_MAINFRAME menu. In the View
    category, add a separator in the first empty item

  2. Click the next empty field and, in the Properties window, click the ID field. Then
    click its arrow to select ID_VIEW_LARGEICON. Set its Caption to Large &Icons

  3. In the same way, set the ID of the next item to ID_VIEW_SMALLICICON and set
    its Caption to S&mall Icons

  4. In the same way, set the ID of the next item to ID_VIEW_LIST and set its Caption
    to &List

  5. In the same way, set the ID of the next item to ID_VIEW_DETAILS and set its
    Caption to &Details

  6. To allow the user to change views, right-click the Large Icons menu item and click
    Add Event Handler...

  7. In the Message Type list, accept the COMMAND message. In the Class List, click
    the view class. In the Function Handler Name, change the name to
    OnViewLargeIcon

  8. Click Add And Edit and implement the message as follows:


void CCountriesView::OnViewLargeIcon()
{
// TODO: Add your command handler code here
if( GetViewType() != LVS_ICON )
SetViewType(LVS_ICON);
}


  1. In the same way, Add An Event Handler for the Small Icons menu item. Associate
    its COMMAND message with the view class. Change its name to
    OnViewSmallIcon

  2. Implement it as follows:


void CCountriesView::OnViewSmallicon()
{
// TODO: Add your command handler code here
if( GetViewType() != LVS_SMALLICON )
SetViewType(LVS_SMALLICON);
}


  1. In the same way, Add An Event Handler for the List menu item. Associate its
    COMMAND message with the view class and implement it as follows:


void CCountriesView::OnViewList()
{
// TODO: Add your command handler code here
if( GetViewType() != LVS_LIST )
SetViewType(LVS_LIST);
}


  1. In the same way, Add An Event Handler for the List menu item. Associate its
    COMMAND message with the view class and implement it as follows:


void CCountriesView::OnViewDetails()
{
// TODO: Add your command handler code here
if( GetViewType() != LVS_REPORT )
SetViewType(LVS_REPORT);
Free download pdf