📄 myexplorerview.cpp
字号:
// MyExplorerView.cpp : implementation of the CMyExplorerView class
//
#include "stdafx.h"
#include "MyExplorer.h"
#include "MainFrm.h"
#include "MyExplorerDoc.h"
#include "MyExplorerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyExplorerView
IMPLEMENT_DYNCREATE(CMyExplorerView, CListView)
BEGIN_MESSAGE_MAP(CMyExplorerView, CListView)
//{{AFX_MSG_MAP(CMyExplorerView)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyExplorerView construction/destruction
CMyExplorerView::CMyExplorerView()
{
// TODO: add construction code here
}
CMyExplorerView::~CMyExplorerView()
{
}
BOOL CMyExplorerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyExplorerView drawing
void CMyExplorerView::OnDraw(CDC* pDC)
{
CMyExplorerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CMyExplorerView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
CComboBoxEx *pDriver;
pDriver=&(((CMainFrame*)GetParentFrame())->m_wndDriver);
int iIcon,iIconSel;
char lpBuffer[MAX_PATH];
char* ptr;
CString str;
CTime time;
int index=0;
::GetLogicalDriveStrings(MAX_PATH,lpBuffer);
ptr=lpBuffer;
while(*ptr)
{
str=ptr;
//GetFileIcon(str,&iIcon,&iIconSel);
COMBOBOXEXITEM Combo;
Combo.mask=/*CBEIF_IMAGE|*/CBEIF_TEXT/*|CBEIF_SELECTEDIMAGE*/;
//Combo.iImage=iIcon;
//Combo.iSelectedImage=iIconSel;
Combo.pszText=(LPTSTR)(LPCTSTR)str;
Combo.iItem=index;
pDriver->InsertItem(&Combo);
ptr+=strlen(ptr)+1;
index++;
}
// if(pDriver->FindStringExact(-1,"C:\\"))
{
str="C:\\";
COMBOBOXEXITEM Combo;
Combo.mask=/*CBEIF_IMAGE|*/CBEIF_TEXT/*|CBEIF_SELECTEDIMAGE*/;
//Combo.iImage=iIcon;
//Combo.iSelectedImage=iIconSel;
Combo.pszText=(LPTSTR)(LPCTSTR)str;
Combo.iItem=index;
pDriver->InsertItem(&Combo);
pDriver->SetCurSel(index);
}
::SetCurrentDirectory("C:\\");
::GetCurrentDirectory(MAX_PATH,(LPTSTR)(LPCTSTR)m_CurDir);
index=0;
CListCtrl &m_list=GetListCtrl();
m_list.InsertColumn(0,"文件名",LVCFMT_LEFT,100);
m_list.InsertColumn(1,"修改时间",LVCFMT_LEFT,200);
m_list.InsertColumn(2,"属性",LVCFMT_LEFT,200);
m_list.ModifyStyle(LVS_TYPEMASK, LVS_REPORT);
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
CFileFind fileFind;
BOOL bContinue;
bContinue=fileFind.FindFile("*.*");
while(bContinue)
{
bContinue=fileFind.FindNextFile();
if(fileFind.IsHidden())continue;
str=fileFind.GetFileName();
m_list.InsertItem(index,str);
fileFind.GetLastWriteTime(time);
str=time.Format("%Y-%m-%d %H:%M:%S");
m_list.SetItemText(index,1,str);
if(fileFind.IsDirectory())
{
m_list.SetItemText(index,2,"目录");
}
else
{
int i=fileFind.GetLength();
if(i>1024)
{
str.Format("%d",i/1024);
str+="KB";
}
else
str.Format("%d",i);
m_list.SetItemText(index,2,str);
}
index++;
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyExplorerView printing
BOOL CMyExplorerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyExplorerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyExplorerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyExplorerView diagnostics
#ifdef _DEBUG
void CMyExplorerView::AssertValid() const
{
CListView::AssertValid();
}
void CMyExplorerView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CMyExplorerDoc* CMyExplorerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyExplorerDoc)));
return (CMyExplorerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyExplorerView message handlers
void CMyExplorerView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString str,str1;
CListCtrl &m_list=GetListCtrl();
int index=m_list.GetNextItem(-1,LVNI_SELECTED);
if (index==-1)
return;
str=m_list.GetItemText(index,0);
str1=m_list.GetItemText(index,2);
if(str1=="目录"||str==".."||str==".")
m_CurDir=m_CurDir+str;
else
{
::ShellExecute(this->m_hWnd,NULL,str,"open",m_CurDir,SW_SHOWDEFAULT);
return;
}
Update(m_CurDir);
}
void CMyExplorerView::Update(CString str)
{
int index;
CTime time;
CListCtrl &m_list=GetListCtrl();
CComboBoxEx *pDriver;
pDriver=&(((CMainFrame*)GetParentFrame())->m_wndDriver);
char buf[MAX_PATH];
::SetCurrentDirectory(str);
::GetCurrentDirectory(MAX_PATH,buf);
m_CurDir.Format("%s",buf);
if(buf[strlen(buf)-1]!='\\')
m_CurDir+="\\";
index=pDriver->GetCount();
COMBOBOXEXITEM Combo;
Combo.mask=/*CBEIF_IMAGE|*/CBEIF_TEXT/*|CBEIF_SELECTEDIMAGE*/;
//Combo.iImage=iIcon;
//Combo.iSelectedImage=iIconSel;
Combo.pszText=(LPTSTR)(LPCTSTR)m_CurDir;
Combo.iItem=index-1;
pDriver->SetItem(&Combo);
pDriver->SetCurSel(index-1);
// AfxMessageBox("Current Directory:"+m_CurDir);
index=0;
m_list.DeleteAllItems();
CFileFind fileFind;
BOOL bContinue;
bContinue=fileFind.FindFile("*.*");
while(bContinue)
{
bContinue=fileFind.FindNextFile();
if(fileFind.IsHidden()) continue;
str=fileFind.GetFileName();
m_list.InsertItem(index,str);
fileFind.GetLastWriteTime(time);
str=time.Format("%x");
m_list.SetItemText(index,1,str);
if(fileFind.IsDirectory())
{
m_list.SetItemText(index,2,"目录");
}
else
{
int i=fileFind.GetLength();
if(i>1024)
{
str.Format("%d",i/1024);
str+="KB";
}
else
str.Format("%d",i);
m_list.SetItemText(index,2,str);
}
index++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -