www.pudn.com > MyTree.rar > MyTreeView.cpp
// MyTreeView.cpp : implementation of the CMyTreeView class
//
#include "stdafx.h"
#include "MyTree.h"
#include "MyTreeDoc.h"
#include "MyTreeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyTreeView
IMPLEMENT_DYNCREATE(CMyTreeView, CTreeView)
BEGIN_MESSAGE_MAP(CMyTreeView, CTreeView)
//{{AFX_MSG_MAP(CMyTreeView)
ON_WM_RBUTTONDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyTreeView construction/destruction
CMyTreeView::CMyTreeView()
{
// TODO: add construction code here
}
CMyTreeView::~CMyTreeView()
{
}
BOOL CMyTreeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CTreeView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyTreeView drawing
void CMyTreeView::OnDraw(CDC* pDC)
{
CMyTreeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CMyTreeView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
CTreeCtrl& p =GetTreeCtrl();
m_image.Create(16,16,ILC_COLOR|ILC_MASK,3,0);
m_image.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_image.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
p.SetImageList(&m_image,TVSIL_NORMAL);
root=p.InsertItem("我的电脑",0,1);
p.InsertItem("X",1,1,root);
p.InsertItem("Y",1,0,root);
p.Expand(root,TVE_EXPAND);
// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().
}
/////////////////////////////////////////////////////////////////////////////
// CMyTreeView printing
BOOL CMyTreeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyTreeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyTreeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyTreeView diagnostics
#ifdef _DEBUG
void CMyTreeView::AssertValid() const
{
CTreeView::AssertValid();
}
void CMyTreeView::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
CMyTreeDoc* CMyTreeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyTreeDoc)));
return (CMyTreeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyTreeView message handlers
void CMyTreeView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CTreeCtrl& p =GetTreeCtrl();
HTREEITEM root2;
CString str;
static int i=1;
i=i+1;
str.Format("第%d个点",i);
root2=p.InsertItem(str,0,0,root);
str.Format("x=%d",point.x);
p.InsertItem(str,0,1,root2);
str.Format("y=%d",point.y);
p.InsertItem(str,0,1,root2);
p.Expand(root,TVE_EXPAND);
CTreeView::OnRButtonDown(nFlags, point);
}