WZDLVIEW.CPP
资源名称:B43.rar [点击查看]
上传用户:leishk
上传日期:2022-03-16
资源大小:3649k
文件大小:5k
源码类别:
ListView/ListBox
开发平台:
Visual C++
- // WzdListView.cpp : implementation of the CWzdListView class
- //
- #include "stdafx.h"
- #include "Wzd.h"
- #include "WzdDoc.h"
- #include "WzdLView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CWzdListView
- IMPLEMENT_DYNCREATE(CWzdListView, CListView)
- BEGIN_MESSAGE_MAP(CWzdListView, CListView)
- //{{AFX_MSG_MAP(CWzdListView)
- ON_WM_LBUTTONDBLCLK()
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CWzdListView construction/destruction
- CWzdListView::CWzdListView()
- {
- // TODO: add construction code here
- }
- CWzdListView::~CWzdListView()
- {
- }
- BOOL CWzdListView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CListView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWzdListView drawing
- void CWzdListView::OnDraw(CDC* pDC)
- {
- CWzdDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWzdListView printing
- BOOL CWzdListView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CWzdListView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CWzdListView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWzdListView diagnostics
- #ifdef _DEBUG
- void CWzdListView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CWzdListView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CWzdDoc* CWzdListView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWzdDoc)));
- return (CWzdDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CWzdListView message handlers
- void CWzdListView::OnInitialUpdate()
- {
- CListView::OnInitialUpdate();
- // attach image lists to list control
- m_ImageList.Create(IDB_NORMAL_BITMAP, 32, 1, RGB(0,0,0));
- GetListCtrl().SetImageList(&m_ImageList, LVSIL_NORMAL);
- m_ImageSmallList.Create(IDB_SMALL_BITMAP, 16, 1, RGB(0,0,0));
- GetListCtrl().SetImageList(&m_ImageSmallList, LVSIL_SMALL);
- // initialize list control
- CClientDC dc(this);
- TEXTMETRIC tm;
- dc.GetTextMetrics(&tm);
- GetListCtrl().ModifyStyle(0,LVS_REPORT|LVS_SHOWSELALWAYS);
- GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);
- GetListCtrl().InsertColumn(0,"Name",LVCFMT_LEFT,20*tm.tmAveCharWidth,0);
- GetListCtrl().InsertColumn(1,"Comment",LVCFMT_LEFT,30*tm.tmAveCharWidth,1);
- }
- void CWzdListView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- if (lHint&TREE_VIEW_ONLY)
- {
- return;
- }
- GetListCtrl().DeleteAllItems();
- switch (lHint)
- {
- case ICON_LIST_VIEW:
- GetListCtrl().ModifyStyle(LVS_LIST|LVS_SMALLICON|LVS_REPORT,LVS_ICON);
- break;
- case LIST_LIST_VIEW:
- GetListCtrl().ModifyStyle(LVS_ICON|LVS_SMALLICON|LVS_REPORT,LVS_LIST);
- break;
- case SMALL_ICON_LIST_VIEW:
- GetListCtrl().ModifyStyle(LVS_LIST|LVS_ICON|LVS_REPORT,LVS_SMALLICON);
- break;
- case REPORT_LIST_VIEW:
- GetListCtrl().ModifyStyle(LVS_LIST|LVS_SMALLICON|LVS_ICON,LVS_REPORT);
- break;
- }
- // list all folders in selection
- POSITION pos;
- CWzdInfo *pSelInfo=GetDocument()->GetSelection();
- for (pos = pSelInfo->m_list.GetHeadPosition(); pos;)
- {
- CWzdInfo *pInfo = pSelInfo->m_list.GetNext(pos);
- if (pInfo->m_nCategory==CWzdInfo::FOLDER)
- {
- AddLine(pInfo);
- }
- }
- // list all files in selection
- for (pos = pSelInfo->m_list.GetHeadPosition(); pos;)
- {
- CWzdInfo *pInfo = pSelInfo->m_list.GetNext(pos);
- if (pInfo->m_nCategory==CWzdInfo::FILE)
- {
- AddLine(pInfo);
- }
- }
- }
- void CWzdListView::AddLine(CWzdInfo *pInfo)
- {
- LV_ITEM item;
- item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
- item.iItem = GetListCtrl().GetItemCount();
- item.iSubItem = 0;
- item.pszText = (char *)LPCTSTR(pInfo->m_sName);
- item.iImage = pInfo->m_nCategory;
- item.lParam = (DWORD)pInfo;
- int ndx=GetListCtrl().InsertItem(&item);
- // if report style add comment
- if (GetListCtrl().GetStyle() & LVS_REPORT)
- {
- GetListCtrl().SetItemText(ndx, 1, pInfo->m_sComment);
- }
- }
- void CWzdListView::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- int ndx;
- if (GetListCtrl().GetSelectedCount()==1 &&
- (ndx = GetListCtrl().GetNextItem(-1, LVIS_SELECTED)) != -1)
- {
- GetDocument()->SaveSelection((CWzdInfo *)GetListCtrl().GetItemData(ndx),TREE_VIEW_SELECT);
- }
- CListView::OnLButtonDblClk(nFlags, point);
- }