⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treeviewexampleview.cpp

📁 MFC程序开发参考大全 【明日科技】宋坤 刘锐宁 李伟明 【丛 书 名】 软件工程师典藏 【出 版 社】 人民邮电出版社 本书详细介绍了MFC框架中所有常用类及控件的应用
💻 CPP
字号:
// TreeViewExampleView.cpp : implementation of the CTreeViewExampleView class
//

#include "stdafx.h"
#include "TreeViewExample.h"

#include "TreeViewExampleDoc.h"
#include "TreeViewExampleView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTreeViewExampleView

IMPLEMENT_DYNCREATE(CTreeViewExampleView, CTreeView)

BEGIN_MESSAGE_MAP(CTreeViewExampleView, CTreeView)
	//{{AFX_MSG_MAP(CTreeViewExampleView)
	ON_NOTIFY_REFLECT(NM_RDBLCLK, OnRdblclk)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CTreeViewExampleView construction/destruction

CTreeViewExampleView::CTreeViewExampleView()
{
	imlst.Create(16,16,ILC_COLOR32|ILC_MASK,0,0);
}

CTreeViewExampleView::~CTreeViewExampleView()
{
}

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

	return CTreeView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTreeViewExampleView drawing

void CTreeViewExampleView::OnDraw(CDC* pDC)
{
	CTreeViewExampleDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

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

	
	GetTreeCtrl().SetImageList(&imlst,TVSIL_NORMAL);
	GetTreeCtrl().ModifyStyle(0L,TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS);
	for(int i=0;i<11;i++)
	imlst.Add(AfxGetApp()->LoadIcon(IDI_ICON1+i));

	CTreeCtrl *pTreeCtl=&GetTreeCtrl();
	HTREEITEM item;
	pTreeCtl->DeleteAllItems();
	item=pTreeCtl->InsertItem("基本信息",0,0,TVI_ROOT);
	pTreeCtl->InsertItem("员工信息",1,1,item);
	pTreeCtl->InsertItem("固定资产",2,2,item);
	pTreeCtl->InsertItem("企业结构",3,3,item);
	item=pTreeCtl->InsertItem("查询",4,4,TVI_ROOT);
	pTreeCtl->InsertItem("简单查询",5,5,item);
	pTreeCtl->InsertItem("复合查询",6,6,item);
	item=pTreeCtl->InsertItem("打印",7,7,TVI_ROOT);
	pTreeCtl->InsertItem("打印工资条",8,8,item);
	pTreeCtl->InsertItem("打印报表",9,9,item);
	pTreeCtl->InsertItem("打印查询结果",10,10,item);
}

/////////////////////////////////////////////////////////////////////////////
// CTreeViewExampleView printing

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

void CTreeViewExampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

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

/////////////////////////////////////////////////////////////////////////////
// CTreeViewExampleView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTreeViewExampleView message handlers

void CTreeViewExampleView::OnRdblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HTREEITEM item=this->GetTreeCtrl().GetSelectedItem();
	if(item)
	{
		if(GetTreeCtrl().GetChildItem(item))return;
		MessageBox(GetTreeCtrl().GetItemText(item),"选择的是:",MB_OK);
	}
	*pResult = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -