/////////////////////////////////////////////////////// LeftView.h : interface of the CLeftView class
#if !defined(AFX_LEFTVIEW_H__29F66875_4E46_11D6_9693_B383368EF622__INCLUDED_)
#define AFX_LEFTVIEW_H__29F66875_4E46_11D6_9693_B383368EF622__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CDriveExplorerDoc;
class CLeftView : public CTreeView
{
protected: // create from serialization only
¡¡CLeftView();
¡¡DECLARE_DYNCREATE(CLeftView)
¡¡// Attributes
public:
¡¡CDriveExplorerDoc* GetDocument();
¡¡CImageList* m_pImageList;
¡¡CString m_LocalPath;
¡¡// Operations
public:
¡¡BOOL HasSubdirectory(CString &strPathName);
¡¡BOOL IsDriveNode(HTREEITEM hItem);
¡¡void SetButtonState(HTREEITEM hItem, CString &strPathName);
¡¡UINT AddDirectoryNodes(HTREEITEM hItem, CString &strPathName);
¡¡BOOL IsMediaValid(CString &strPathName);
¡¡HTREEITEM GetDriveNode(HTREEITEM hItem);
¡¡UINT DeleteChildren(HTREEITEM hItem);
¡¡BOOL IsPathValid(CString &strPathName);
¡¡CString GetPathFromItem(HTREEITEM hItem);
¡¡void AddDummyNode(HTREEITEM hItem);
¡¡void InitTreeView(HTREEITEM hParent);
¡¡BOOL AddDrives(CString strDrive, HTREEITEM hParent);
¡¡// Overrides
¡¡// ClassWizard generated virtual function overrides
¡¡//{{AFX_VIRTUAL(CLeftView)
public:
¡¡virtual void OnDraw(CDC* pDC); // overridden to draw this view
¡¡virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
¡¡virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
¡¡virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
¡¡virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
¡¡virtual void OnInitialUpdate(); // called first time after construct
//}}AFX_VIRTUAL
// Implementation
public:
¡¡virtual ~CLeftView();
¡¡#ifdef _DEBUG
¡¡¡¡virtual void AssertValid() const;
¡¡¡¡virtual void Dump(CDumpContext& dc) const;
¡¡#endif
protected:
¡¡// Generated message map functions
protected:
¡¡//{{AFX_MSG(CLeftView)
¡¡¡¡// NOTE - the ClassWizard will add and remove member functions here.
¡¡¡¡// DO NOT EDIT what you see in these blocks of generated code !
¡¡¡¡afx_msg void OnDestroy();
¡¡¡¡afx_msg void OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult);
¡¡¡¡afx_msg void OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult);
¡¡//}}AFX_MSG
¡¡DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in LeftView.cpp
¡¡inline CDriveExplorerDoc* CLeftView::GetDocument()
¡¡{ return (CDriveExplorerDoc*)m_pDocument; }
#endif
#endif
////////////////////////////////////////////////////////// CLeftView
#include "stdafx.h"
#include "DriveExplorer.h"
#include "DriveExplorerDoc.h"
#include "LeftView.h"
#include "DriveExplorerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ILI_CDDRV 0
#define ILI_CLSDFLD 1
#define ILI_DRIVE 2
#define ILI_FLOPPYDRV 3
#define ILI_MYCOMP 4
#define ILI_OPENFLD 5
#define ILI_TEXTFILE 6
#define MYCOMPUTER "My Computer"
IMPLEMENT_DYNCREATE(CLeftView, CTreeView)
BEGIN_MESSAGE_MAP(CLeftView, CTreeView)
//{{AFX_MSG_MAP(CLeftView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_WM_DESTROY()
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
ON_NOTIFY_REFLECT(TVN_SELCHANGING, OnSelchanging)
//}}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()
///////////////////////////////////// CLeftView construction/destruction
CLeftView::CLeftView()
{
¡¡// TODO: add construction code here
}
CLeftView::~CLeftView()
{}
BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs)
{
¡¡// TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs
cs.style |= TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES;
¡¡return CTreeView::PreCreateWindow(cs);
}
void CLeftView::OnDraw(CDC* pDC)
{
¡¡CDriveExplorerDoc* pDoc = GetDocument();
¡¡ASSERT_VALID(pDoc);
¡¡// TODO: add draw code for native data here
}
BOOL CLeftView::OnPreparePrinting(CPrintInfo* pInfo)
{
¡¡// default preparation
¡¡return DoPreparePrinting(pInfo);
}
void CLeftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
¡¡// TODO: add extra initialization before printing
}
void CLeftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
¡¡// TODO: add cleanup after printing
}
void CLeftView::OnInitialUpdate()
{
¡¡CTreeView::OnInitialUpdate();
¡¡m_pImageList = new CImageList();
¡¡CWinApp* pApp = AfxGetApp();
¡¡// ASSERT(m_pImageList != NULL); // serious allocation failure checking
¡¡m_pImageList->Create(16, 16, ILC_COLOR8 | ILC_MASK, 9, 9);
¡¡m_pImageList->Add(pApp->LoadIcon(ICO_CDDRV));
¡¡m_pImageList->Add(pApp->LoadIcon(ICO_CLSDFLD));
¡¡m_pImageList->Add(pApp->LoadIcon(ICO_DRIVE));
¡¡m_pImageList->Add(pApp->LoadIcon(ICO_FLOPPYDRV));
¡¡m_pImageList->Add(pApp->LoadIcon(ICO_MYCOMP));
¡¡m_pImageList->Add(pApp->LoadIcon(ICO_OPENFLD));
¡¡m_pImageList->Add(pApp->LoadIcon(ICO_TEXTFILE));
¡¡GetTreeCtrl().SetImageList(m_pImageList , TVSIL_NORMAL);
¡¡HTREEITEM hParent = GetTreeCtrl().InsertItem(MYCOMPUTER,
¡¡ILI_MYCOMP, ILI_MYCOMP);
¡¡InitTreeView(hParent);
¡¡GetTreeCtrl().Expand(hParent, TVE_EXPAND);
}
#ifdef _DEBUG
void CLeftView::AssertValid() const
{
¡¡CTreeView::AssertValid();
}
void CLeftView::Dump(CDumpContext& dc) const
{
¡¡CTreeView::Dump(dc);
}
CDriveExplorerDoc* CLeftView::GetDocument() // non-debug version is inline
{
¡¡ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDriveExplorerDoc)));
¡¡return (CDriveExplorerDoc*)m_pDocument;
}
#endif //_DEBUG
void CLeftView::InitTreeView(HTREEITEM hParent)
{
¡¡int nPos = 0;
¡¡UINT nCount = 0;
¡¡CString strDrive = "?:";
¡¡DWORD dwDriveList = ::GetLogicalDrives ();
¡¡CString cTmp;
¡¡while (dwDriveList) {
¡¡¡¡if (dwDriveList & 1) {
¡¡¡¡¡¡cTmp = strDrive;
¡¡¡¡¡¡strDrive.SetAt (0, 0x41 + nPos);
¡¡¡¡¡¡if (AddDrives(strDrive , hParent))
¡¡¡¡¡¡¡¡nCount++;
¡¡¡¡}
¡¡¡¡dwDriveList >>= 1;
¡¡¡¡nPos++;
¡¡}
¡¡return;
}
BOOL CLeftView::AddDrives(CString strDrive, HTREEITEM hParent)
{
¡¡HTREEITEM hItem;
¡¡UINT nType = ::GetDriveType ((LPCTSTR) strDrive);
¡¡UINT nDrive = (UINT) strDrive[0] - 0x41;
¡¡switch (nType) {
¡¡¡¡case DRIVE_REMOVABLE:
¡¡¡¡¡¡hItem = GetTreeCtrl().InsertItem(strDrive, ILI_FLOPPYDRV, ILI_FLOPPYDRV, hParent);
¡¡¡¡¡¡AddDummyNode(hItem);
¡¡¡¡¡¡break;
¡¡¡¡case DRIVE_FIXED:
¡¡¡¡¡¡hItem = GetTreeCtrl().InsertItem(strDrive, ILI_DRIVE, ILI_DRIVE, hParent);
¡¡¡¡¡¡AddDummyNode(hItem);
¡¡¡¡¡¡break;
¡¡¡¡case DRIVE_REMOTE:
¡¡¡¡¡¡hItem = GetTreeCtrl().InsertItem(strDrive, ILI_DRIVE, ILI_DRIVE, hParent);
¡¡¡¡¡¡AddDummyNode(hItem);
¡¡¡¡¡¡break;
¡¡¡¡case DRIVE_CDROM:
¡¡¡¡¡¡hItem = GetTreeCtrl().InsertItem(strDrive, ILI_CDDRV, ILI_CDDRV, hParent);
¡¡¡¡¡¡AddDummyNode(hItem);
¡¡¡¡¡¡break;
¡¡¡¡case DRIVE_RAMDISK:
¡¡¡¡¡¡hItem = GetTreeCtrl().InsertItem(strDrive, ILI_CDDRV, ILI_CDDRV, hParent);
¡¡¡¡¡¡AddDummyNode(hItem);
¡¡¡¡¡¡break;
¡¡¡¡default:
¡¡¡¡¡¡return FALSE;
¡¡}
¡¡return true;
}
void CLeftView::OnDestroy()
{
¡¡CTreeView::OnDestroy();
¡¡// TODO: Add your message handler code here
¡¡if(m_pImageList != NULL)
¡¡¡¡m_pImageList = NULL;
¡¡¡¡delete m_pImageList;
}
void CLeftView::AddDummyNode(HTREEITEM hItem)
{
¡¡GetTreeCtrl().InsertItem ("", 0, 0, hItem);
}
CString CLeftView::GetPathFromItem(HTREEITEM hItem)
{
¡¡CString strPathName;
¡¡while (hItem != NULL)
¡¡{
¡¡¡¡CString string = GetTreeCtrl().GetItemText (hItem);
¡¡¡¡if ((string.Right (1) != "") && !strPathName.IsEmpty ())
¡¡¡¡¡¡string += "";
¡¡¡¡strPathName = string + strPathName;
¡¡¡¡hItem = GetTreeCtrl().GetParentItem (hItem);
¡¡}
¡¡if(strPathName.Left(11) == MYCOMPUTER && strPathName.GetLength() > 11)
¡¡¡¡strPathName = strPathName.Mid(12);
¡¡return strPathName;
}
BOOL CLeftView:
source_browse.rar_Windows资源管理器_工具栏_文件夹 列表_树型控件_资源管理器
版权申诉
80 浏览量
2022-09-24
13:24:52
上传
评论
收藏 7KB RAR 举报
小波思基
- 粉丝: 70
- 资源: 1万+