www.pudn.com > 单文档多视图.rar > View2.cpp


// View2.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "SdiMulti.h" 
#include "View2.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// C2View 
 
IMPLEMENT_DYNCREATE(C2View, CTreeView) 
 
C2View::C2View() 
{ 
} 
 
C2View::~C2View() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(C2View, CTreeView) 
	//{{AFX_MSG_MAP(C2View) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// C2View drawing 
 
void C2View::OnDraw(CDC* pDC) 
{ 
	CDocument* pDoc = GetDocument(); 
	// TODO: add draw code here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// C2View diagnostics 
 
#ifdef _DEBUG 
void C2View::AssertValid() const 
{ 
	CTreeView::AssertValid(); 
} 
 
void C2View::Dump(CDumpContext& dc) const 
{ 
	CTreeView::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// C2View message handlers 
 
// thank Mike Wild for his tree sample 
// Image list indexes 
 
#define ILI_HARD_DISK       0 
#define ILI_FLOPPY          1 
#define ILI_CD_ROM          2 
#define ILI_NET_DRIVE       3 
#define ILI_RAM_DRIVE       4 
#define ILI_CLOSED_FOLDER   5 
#define ILI_OPEN_FOLDER     6 
 
void C2View::OnInitialUpdate()  
{ 
	CTreeView::OnInitialUpdate(); 
	CTreeCtrl& TreeCtrl = GetTreeCtrl(); 
	TreeCtrl.DeleteAllItems(); 
 
	m_ImageList.DeleteImageList();	// on new reuse this 
    m_ImageList.Create(IDR_DRIVEIMAGES, 16, 1, RGB(0, 0, 0)); 
    TreeCtrl.SetImageList(&m_ImageList, TVSIL_NORMAL); 
 
	HTREEITEM hItem0, hItem1, hItem2, hItem3; 
 
    // Fill the tree with colored text. 
	CString str; 
	for (int i = 0; i < 5; i++) 
	{ 
		str.Format("Parent Item %d", i+1); 
		hItem0 = TreeCtrl.InsertItem(str, ILI_HARD_DISK, ILI_HARD_DISK); 
		for (int j = 0; j < 5; j++) 
		{ 
			str.Format("Child Item %d", j+1); 
			hItem1 = TreeCtrl.InsertItem(str, ILI_FLOPPY, ILI_FLOPPY, hItem0); 
		    for (int k = 0; k < 5; k++) 
		    { 
			    str.Format("ChildChild Item %d", k+1); 
			    hItem2 = TreeCtrl.InsertItem(str, ILI_FLOPPY, ILI_FLOPPY, hItem1); 
		        for (int l = 0; l < 5; l++) 
		        { 
			        str.Format("ChildChildChild Item %d", l+1); 
			        hItem3 = TreeCtrl.InsertItem(str, ILI_FLOPPY, ILI_FLOPPY, hItem2); 
		        } 
		    } 
		} 
	} 
     
    // Fill the tree with Text and Icons 
    hItem0 = TreeCtrl.InsertItem("Floppy Drive", ILI_FLOPPY, ILI_FLOPPY); 
    hItem1 = TreeCtrl.InsertItem("Child Node", ILI_CLOSED_FOLDER, ILI_OPEN_FOLDER, hItem0, TVI_SORT); 
 
    hItem0 = TreeCtrl.InsertItem("HardDisk Drive", ILI_HARD_DISK, ILI_HARD_DISK); 
    hItem1 = TreeCtrl.InsertItem("Child Node", ILI_CLOSED_FOLDER, ILI_OPEN_FOLDER, hItem0, TVI_SORT); 
 
    hItem0 = TreeCtrl.InsertItem("Net Drive", ILI_NET_DRIVE, ILI_NET_DRIVE); 
    hItem1 = TreeCtrl.InsertItem("Child Node", ILI_CLOSED_FOLDER, ILI_OPEN_FOLDER, hItem0, TVI_SORT); 
 
    hItem0 = TreeCtrl.InsertItem("CD Drive", ILI_CD_ROM, ILI_CD_ROM); 
    hItem1 = TreeCtrl.InsertItem("Child Node", ILI_CLOSED_FOLDER, ILI_OPEN_FOLDER, hItem0, TVI_SORT); 
    hItem2 = TreeCtrl.InsertItem("ChildChild Node", ILI_CLOSED_FOLDER, ILI_OPEN_FOLDER, hItem1, TVI_SORT); 
 
    // Set Overlay-Image 
    TreeCtrl.SetItemState(hItem2, INDEXTOOVERLAYMASK(2), TVIS_OVERLAYMASK); 
}