WZDTVIEW.CPP
资源名称:B43.rar [点击查看]
上传用户:leishk
上传日期:2022-03-16
资源大小:3649k
文件大小:5k
源码类别:
ListView/ListBox
开发平台:
Visual C++
- // WzdTView.cpp : implementation of the CWzdTreeView class
- //
- #include "stdafx.h"
- #include "Wzd.h"
- #include "WzdDoc.h"
- #include "WzdTView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CWzdTreeView
- IMPLEMENT_DYNCREATE(CWzdTreeView, CTreeView)
- BEGIN_MESSAGE_MAP(CWzdTreeView, CTreeView)
- //{{AFX_MSG_MAP(CWzdTreeView)
- ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CWzdTreeView construction/destruction
- CWzdTreeView::CWzdTreeView()
- {
- // set the CTreeCtrl attributes
- m_dwDefaultStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES
- | TVS_SHOWSELALWAYS | TVS_LINESATROOT | TVS_HASBUTTONS;
- }
- CWzdTreeView::~CWzdTreeView()
- {
- }
- BOOL CWzdTreeView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CTreeView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWzdTreeView drawing
- void CWzdTreeView::OnDraw(CDC* pDC)
- {
- CWzdDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWzdTreeView printing
- BOOL CWzdTreeView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CWzdTreeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CWzdTreeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWzdTreeView diagnostics
- #ifdef _DEBUG
- void CWzdTreeView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CWzdTreeView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CWzdDoc* CWzdTreeView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWzdDoc)));
- return (CWzdDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CWzdTreeView message handlers
- void CWzdTreeView::OnInitialUpdate()
- {
- CTreeView::OnInitialUpdate();
- // set icons
- m_ImageList.Create(IDB_SMALL_BITMAP, 16, 1, RGB(0,0,0));
- GetTreeCtrl().SetImageList(&m_ImageList, TVSIL_NORMAL);
- }
- void CWzdTreeView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- if (lHint&LIST_VIEW_ONLY)
- {
- return;
- }
- HTREEITEM hitem;
- CWzdInfo *pInfo;
- switch (lHint)
- {
- case TREE_VIEW_SELECT:
- pInfo=GetDocument()->GetSelection();
- if ((hitem = FindTreeItem(GetTreeCtrl().GetChildItem(GetTreeCtrl().GetRootItem()), pInfo->m_nObjectID))!=NULL)
- {
- GetTreeCtrl().SelectItem(hitem);
- }
- break;
- case TREE_VIEW_UP_LEVEL:
- hitem=GetTreeCtrl().GetSelectedItem();
- hitem=GetTreeCtrl().GetParentItem(hitem);
- GetTreeCtrl().SelectItem(hitem);
- break;
- default:
- GetTreeCtrl().DeleteAllItems();
- AddBranch(TVI_ROOT, GetDocument()->GetWzdList());
- break;
- }
- }
- // recurse until all CWzdInfo items are in a leaf
- void CWzdTreeView::AddBranch(HTREEITEM hTreeItem, CList<CWzdInfo*,CWzdInfo*> *pList)
- {
- for (POSITION pos = pList->GetHeadPosition(); pos;)
- {
- CWzdInfo *pInfo = pList->GetNext(pos);
- if (pInfo->m_nCategory!=CWzdInfo::FILE)
- {
- HTREEITEM hTreeItemx=AddLeaf(hTreeItem, pInfo);
- if (pList->GetCount())
- {
- AddBranch(hTreeItemx, &pInfo->m_list);
- }
- }
- }
- }
- // add leaf to tree
- HTREEITEM CWzdTreeView::AddLeaf(HTREEITEM hTreeItem, CWzdInfo *pInfo)
- {
- TV_INSERTSTRUCT tvstruct;
- tvstruct.hParent = hTreeItem;
- tvstruct.hInsertAfter = TVI_LAST;
- tvstruct.item.iImage = tvstruct.item.iSelectedImage = pInfo->m_nObjectID;
- tvstruct.item.pszText = (char *)LPCTSTR(pInfo->m_sName);
- tvstruct.item.mask = TVIF_IMAGE |TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT;
- tvstruct.item.lParam=(DWORD)pInfo;
- return GetTreeCtrl().InsertItem(&tvstruct);
- }
- // recurse until item found or items expended
- HTREEITEM CWzdTreeView::FindTreeItem(HTREEITEM hTreeItem, long nObjectID)
- {
- while (hTreeItem != NULL)
- {
- CWzdInfo *pInfo=(CWzdInfo *)GetTreeCtrl().GetItemData(hTreeItem);
- if (pInfo->m_nObjectID==nObjectID)
- {
- return hTreeItem;
- }
- else if (GetTreeCtrl().ItemHasChildren(hTreeItem))
- {
- HTREEITEM hTreeItemx = FindTreeItem(GetTreeCtrl().GetChildItem(hTreeItem), nObjectID);
- if (hTreeItemx)
- {
- return hTreeItemx;
- }
- }
- else
- {
- hTreeItem = GetTreeCtrl().GetNextItem(hTreeItem, TVGN_NEXT);
- }
- }
- return NULL;
- }
- // new selection, change listview!
- void CWzdTreeView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- GetDocument()->SaveSelection((CWzdInfo *)pNMTreeView->itemNew.lParam,LIST_VIEW_ONLY);
- *pResult = 0;
- }