home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Fast Track Visual C++ 6.0 Programming
(Publisher: John Wiley & Sons, Inc.)
Author(s): Steve Holzner
ISBN: 0471312908
Publication Date: 09/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next



Listing 3.2 TreeViewView.h and TreeViewView.cpp

// TreeViewView.h : interface of the CTreeViewView class
//
/////////////////////////////////////////////////////////////////////////////

#if 
!defined(AFX_TREEVIEWVIEW_H__093DDFF6_9FB2_11D1_887F_D42B07C10710__INCLUDED_)
#define AFX_TREEVIEWVIEW_H__093DDFF6_9FB2_11D1_887F_D42B07C10710__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CTreeViewView : public CTreeView
{
protected: // create from serialization only
    CTreeViewView();
    DECLARE_DYNCREATE(CTreeViewView)
    HTREEITEM item1;

// Attributes
public:
    CTreeViewDoc* GetDocument();

// Operations
public:

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CTreeViewView)
    public:
    virtual void OnDraw(CDC* pDC);  // overridden to draw this view
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    protected:
    virtual void OnInitialUpdate(); // called first time after construct
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
    //}}AFX_VIRTUAL



// Implementation
public:
    virtual ~CTreeViewView();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
    //{{AFX_MSG(CTreeViewView)
    afx_msg void OnDblclk(NMHDR* pNMHDR, LRESULT* pResult);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in TreeViewView.cpp
inline CTreeViewDoc* CTreeViewView::GetDocument()
   { return (CTreeViewDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately
before the previous line.

#endif // !defined(AFX_TREEVIEWVIEW_H__093DDFF6_9FB2_11D1_887F_D42B07C10710__INCLUDED_)



// TreeViewView.cpp : implementation of the CTreeViewView class
//

#include “stdafx.h”
#include “TreeView.h”

#include “TreeViewDoc.h”


#include “TreeViewView.h”

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTreeViewView

IMPLEMENT_DYNCREATE(CTreeViewView, CTreeView)

BEGIN_MESSAGE_MAP(CTreeViewView, CTreeView)
    //{{AFX_MSG_MAP(CTreeViewView)
    ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
    //}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTreeViewView construction/destruction

CTreeViewView::CTreeViewView()
{
    // TODO: add construction code here

}

CTreeViewView::~CTreeViewView()
{
}

BOOL CTreeViewView::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs



    return CTreeView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTreeViewView drawing

void CTreeViewView::OnDraw(CDC* pDC)
{
    CTreeViewDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    // TODO: add draw code for native data here
}

void CTreeViewView::OnInitialUpdate()
{
    CTreeView::OnInitialUpdate();


    // TODO: You may populate your TreeView with items by directly accessing
    //  its tree control through a call to GetTreeCtrl().
    HTREEITEM root = GetTreeCtrl().InsertItem(CString(“Click Me”));
    item1 = GetTreeCtrl().InsertItem(CString(“Hello”), root);
    GetTreeCtrl().InsertItem(CString(“from”), root);
    GetTreeCtrl().InsertItem(CString(“tree views!”), root);
    CImageList* pImageList = new CImageList();
    pImageList->Create(IDB_BITMAP1, 40, 0, RGB(255, 255, 255));
    GetTreeCtrl().SetImageList(pImageList, TVSIL_NORMAL);
}

/////////////////////////////////////////////////////////////////////////////
// CTreeViewView printing

BOOL CTreeViewView::OnPreparePrinting(CPrintInfo* pInfo)
{
    // default preparation
    return DoPreparePrinting(pInfo);
}

void CTreeViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{


   // TODO: add extra initialization before printing
}

void CTreeViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTreeViewView diagnostics

#ifdef _DEBUG
void CTreeViewView::AssertValid() const
{
    CTreeView::AssertValid();
}

void CTreeViewView::Dump(CDumpContext& dc) const
{
    CTreeView::Dump(dc);
}

CTreeViewDoc* CTreeViewView::GetDocument() // non-debug version is inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTreeViewDoc)));
    return (CTreeViewDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTreeViewView message handlers

void CTreeViewView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
    // TODO: Add your control notification handler code here
    if(GetTreeCtrl().GetSelectedItem() == item1){
            MessageBox(“You clicked the first subitem.”);
    };

    *pResult = 0;
}

Now that we’ve examined some of our view options, let’s look at splitter windows.

Splitter Windows

Splitter windows let you divide your view both horizontally and vertically by grasping splitter handles that appear at the top or to the left of the scrollbars and dragging them as you desire. We examine how to put splitters to work next.

Although we call this next example SplitterView, and everyone thinks of splitters as a view class, they are really a window class. This means that splitters aren’t installed through the AppWizard, but by creating a new class with ClassWizard. Create SplitterView now. To make it easy to type something into our view, select CEditView as the view class’s base class in AppWizard.


Figure 3.10  Creating a splitter window class.

Creating a Splitter Window Class

Open ClassWizard and click the Add Class button, followed by the New option to open the New Class box, as shown in Figure 3.10. This is where we create our new splitter window class. Give that class the name CSplit and make sure that “splitter” is selected in the Base class box. Then click OK to create the new class.

The next step is to install the new class in our program.

Adding Splitter Windows to a Program

Our new splitter windows are going to take the place of the standard MDI child windows in our document template, so we edit the main application object class’s file, SplitterView.cpp. First, we include the Split.h header in that file.

// SplitterView.cpp : Defines the class behaviors for the application.
//

#include “stdafx.h”
#include “SplitterView.h”

#include “MainFrm.h”
#include “ChildFrm.h”
#include “SplitterViewDoc.h”
#include “SplitterViewView.h”
#include “Split.h”                      ⇐
    .
    .
    .


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.