📄 multidrivesview.cpp
字号:
// MultiDrivesView.cpp : implementation of the CMultiDrivesView class
//
#include "stdafx.h"
#include "MultiDrives.h"
#include "MultiDrivesDoc.h"
#include "MultiDrivesView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMultiDrivesView
IMPLEMENT_DYNCREATE(CMultiDrivesView, CListView)
BEGIN_MESSAGE_MAP(CMultiDrivesView, CListView)
//{{AFX_MSG_MAP(CMultiDrivesView)
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMultiDrivesView construction/destruction
CMultiDrivesView::CMultiDrivesView()
{
// TODO: add construction code here
}
CMultiDrivesView::~CMultiDrivesView()
{
}
BOOL CMultiDrivesView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= LVS_REPORT;
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMultiDrivesView drawing
void CMultiDrivesView::OnDraw(CDC* pDC)
{
CMultiDrivesDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CListCtrl& refCtrl = GetListCtrl();
refCtrl.InsertItem(0, "Item!");
// TODO: add draw code for native data here
}
void CMultiDrivesView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
GetListCtrl().InsertColumn(0, _T("File Name"), LVCFMT_LEFT, 0, -1);
GetListCtrl().InsertColumn(1, _T("Attrib"), LVCFMT_LEFT, 0 , -1);
GetListCtrl().InsertColumn(2, _T("Size"), LVCFMT_RIGHT, 0, -1);
GetListCtrl().InsertColumn(3, _T("Date"), LVCFMT_LEFT, 0, -1);
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
/////////////////////////////////////////////////////////////////////////////
// CMultiDrivesView printing
BOOL CMultiDrivesView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMultiDrivesView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMultiDrivesView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMultiDrivesView diagnostics
#ifdef _DEBUG
void CMultiDrivesView::AssertValid() const
{
CListView::AssertValid();
}
void CMultiDrivesView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CMultiDrivesDoc* CMultiDrivesView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMultiDrivesDoc)));
return (CMultiDrivesDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMultiDrivesView message handlers
void CMultiDrivesView::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
{
//TODO: add code to react to the user changing the view style of your window
}
void CMultiDrivesView::OnSize(UINT nType, int cx, int cy)
{
CListView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(GetListCtrl().GetSafeHwnd())
{
GetListCtrl().SetColumnWidth(0, cx/2);
GetListCtrl().SetColumnWidth(1, cx/6);
GetListCtrl().SetColumnWidth(2, cx/5);
GetListCtrl().SetColumnWidth(3, cx/5);
}
}
void CMultiDrivesView::PopulateListView(CString strPathName, CString fileName , CTime ct , DWORD fs) //WIN32_FIND_DATA fd)
{
if((fileName == ".") || (fileName == ".."))
return;
SHFILEINFO shinfo;
SHGetFileInfo( strPathName, NULL,
&shinfo,
sizeof(shinfo),
SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON | SHGFI_TYPENAME );
int iconIndex = m_pImageList.Add(shinfo.hIcon);
GetListCtrl().SetImageList(&m_pImageList, LVSIL_SMALL);
LV_ITEM lvitem;
char sNumBuff[100];
int iActualItem;
CString sText;
lvitem.mask = LVIF_TEXT | LVIF_IMAGE;
lvitem.iItem = 0;
lvitem.iSubItem = 0;
lvitem.pszText = GetNTS(fileName); // fd.cFileName;
lvitem.iImage = iconIndex; //SetFileIcon(fd->GetFileName());
iActualItem = GetListCtrl().InsertItem(&lvitem);
// Add Attribute column
lvitem.mask = LVIF_TEXT;
lvitem.iItem = iActualItem;
lvitem.iSubItem = 1;
lvitem.pszText = shinfo.szTypeName;
GetListCtrl().SetItem(&lvitem);
// Add Size column
if(fs != 0)
ltoa((long)fs , sNumBuff, 10);
else
strcpy(sNumBuff,"");
lvitem.mask = LVIF_TEXT;
lvitem.iItem = iActualItem;
lvitem.iSubItem = 2;
lvitem.pszText = sNumBuff;
GetListCtrl().SetItem(&lvitem);
// Add Time column
// CTime refTime;
// refTime = fd->ftCreationTime;
sText = ct.Format( "%b-%d-%Y" );
lvitem.mask = LVIF_TEXT;
lvitem.iItem = iActualItem;
lvitem.iSubItem = 3;
lvitem.pszText = sText.GetBuffer(sText.GetLength());
GetListCtrl().SetItem(&lvitem);
return;
}
void CMultiDrivesView::DeleteAllListItems()
{
GetListCtrl().DeleteAllItems();
}
int CMultiDrivesView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CMultiDrivesDoc* pDoc = (CMultiDrivesDoc*)GetDocument();
pDoc->m_FilesView = this;
m_pImageList.Create(16, 16, ILC_COLOR8 | ILC_MASK, 9, 9);
GetListCtrl().SetImageList(NULL, 0);
return 0;
}
LPTSTR CMultiDrivesView::GetNTS(CString cString)
{
LPTSTR lpsz = new TCHAR[cString.GetLength()+1];
_tcscpy(lpsz, cString);
return lpsz;
}
void CMultiDrivesView::OnDestroy()
{
CListView::OnDestroy();
// TODO: Add your message handler code here
m_pImageList.DeleteImageList();
}
int CMultiDrivesView::GetIconIndex(HICON hIcon)
{
int retVal = -1;
for(int i = 0 ; i <= 79 ; i++)
{
HICON hIC = m_pImageList.ExtractIcon(i);
if(hIcon == hIC)
{
retVal = i;
break;
}
}
return retVal;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -