📄 mtlistview.cpp
字号:
// MTListView.cpp : implementation of the CMTListView class
//
#include "stdafx.h"
#include "MTrickster.h"
#include "MTricksterDoc.h"
#include "MTListView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CMyList *ProcessList;
/////////////////////////////////////////////////////////////////////////////
// CMTListView
typedef struct _DELETE_INFO{
BOOLEAN IsDelete;
}DELETE_INFO,*PDELETE_INFO;
IMPLEMENT_DYNCREATE(CMTListView, CListView)
BEGIN_MESSAGE_MAP(CMTListView, CListView)
//{{AFX_MSG_MAP(CMTListView)
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
ON_COMMAND(ID_MENUITEM_DELETE, OnMenuitemDelete)
ON_COMMAND(ID_MENUITEM_FORCE_KILL, OnMenuitemForceKill)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMTListView construction/destruction
CMTListView::CMTListView()
{
// TODO: add construction code here
m_List=(CMyList*)&GetListCtrl();
index=0;
}
CMTListView::~CMTListView()
{
}
BOOL CMTListView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= LVS_REPORT;
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMTListView drawing
void CMTListView::OnDraw(CDC* pDC)
{
CMTricksterDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CListCtrl& refCtrl = GetListCtrl();
refCtrl.InsertItem(0, "Item!");
// TODO: add draw code for native data here
}
void CMTListView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
CMTricksterDoc* pDoc = GetDocument();
pDoc->m_MTListView= this;
m_pImage = new CImageList();
m_List->ModifyStyle(LVS_TYPEMASK, LVS_REPORT);
ASSERT(m_pImage != NULL); // serious allocation failure checking
m_List->SetImageList(m_pImage, LVSIL_SMALL);
m_List->SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
ProcessList->InitSystemImageLists(m_List->m_hWnd);
m_List->SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
CRect rect;
GetClientRect(&rect);
m_List->InsertColumn(0,"文件名称",LVCFMT_LEFT,rect.right/6,-1);
m_List->InsertColumn(1,"占用空间",LVCFMT_RIGHT,rect.right/8,-1);
m_List->InsertColumn(2,"创建时间",LVCFMT_RIGHT,rect.right/5,-1);
m_List->InsertColumn(3,"修改时间",LVCFMT_RIGHT,rect.right/5,-1);
m_List->InsertColumn(4,"进入时间",LVCFMT_RIGHT,rect.right/5,-1);
m_List->InsertColumn(5,"属性",LVCFMT_CENTER,rect.right/10,-1);
}
/////////////////////////////////////////////////////////////////////////////
// CMTListView diagnostics
#ifdef _DEBUG
void CMTListView::AssertValid() const
{
CListView::AssertValid();
}
void CMTListView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CMTricksterDoc* CMTListView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMTricksterDoc)));
return (CMTricksterDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMTListView message handlers
void CMTListView::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
{
//TODO: add code to react to the user changing the view style of your window
}
void CMTListView::DeleteAllItems()
{
m_List->DeleteAllItems();
index=0;
}
void CMTListView::AddToListView(PDIRECTORY_INFO_EX fd)
{
CString str,temp;
str.Format("%s",fd->DirectoryInfo.FileName);
str=fd->path+str;
m_List->InsertItem(index, fd->DirectoryInfo.FileName);
temp.Format("%d-%d-%d",fd->DirectoryInfo.CreationTime.Year,fd->DirectoryInfo.CreationTime.Month,fd->DirectoryInfo.CreationTime.Day);
m_List->SetItemText(index,2,temp);
if(fd->DirectoryInfo.AllocationSize.QuadPart>1024*1024*1024)
{
temp.Format("%0.2fG",(float)(fd->DirectoryInfo.AllocationSize.QuadPart)/(float)(1024*1024*1024));
}
else if(fd->DirectoryInfo.AllocationSize.QuadPart>1024*1024)
{
temp.Format("%0.2fM",(float)(fd->DirectoryInfo.AllocationSize.QuadPart)/(float)(1024*1024));
}
else if(fd->DirectoryInfo.AllocationSize.QuadPart>1024)
{
temp.Format("%0.2fK",(float)(fd->DirectoryInfo.AllocationSize.QuadPart)/(float)(1024));
}
else
{
temp.Format("%ldB",fd->DirectoryInfo.AllocationSize.QuadPart);
}
m_List->SetItemText(index,1,temp);
temp.Format("%d-%d-%d",fd->DirectoryInfo.LastWriteTime.Year,fd->DirectoryInfo.LastWriteTime.Month,fd->DirectoryInfo.LastWriteTime.Day);
m_List->SetItemText(index,3,temp);
temp.Format("%d-%d-%d",fd->DirectoryInfo.LastAccessTime.Year,fd->DirectoryInfo.LastAccessTime.Month,fd->DirectoryInfo.LastAccessTime.Day);
m_List->SetItemText(index,4,temp);
switch(fd->DirectoryInfo.FileAttributes)
{
case 0x00000001:
m_List->SetItemText(index,5,"只读");
break;
case 0x00000002:
m_List->SetItemText(index,5,"隐藏");
break;
case 0x00000004:
m_List->SetItemText(index,5,"系统");
break;
case 0x00000020:
m_List->SetItemText(index,5,"存档");
break;
case 0x00000080:
m_List->SetItemText(index,5,"正常");
break;
case 0x00000100:
m_List->SetItemText(index,5,"临时");
break;
case 0x00000800:
m_List->SetItemText(index,5,"压缩");
break;
}
m_List->SetItem(index, 0, LVIF_TEXT | LVIF_IMAGE,fd->DirectoryInfo.FileName,
ProcessList->GetFileIcon(str), 0, 0, 0);
//m_List->SetPath(str);
index++;
}
LPTSTR CMTListView::GetNTS(CString cString)
{
LPTSTR lpsz = new TCHAR[cString.GetLength()+1];
_tcscpy(lpsz, cString);
return lpsz;
}
void CMTListView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
iSelected = m_List->GetNextItem(-1, LVNI_SELECTED);
POINT point;
::GetCursorPos(&point);
CMenu menu;
menu.LoadMenu(IDR_MENU_FILE);
menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
*pResult = 0;
}
void CMTListView::OnMenuitemDelete()
{
// TODO: Add your command handler code here
if(iSelected < 0 || iSelected >= m_List->GetItemCount())
return;
char name[255];
m_List->GetItemText(iSelected,0, name, 255);
CString str,temp;
str.Format("%s",name);
str=path+str;
temp="确定删除"+str+"吗?";
if(MessageBox(temp,"提示", MB_OKCANCEL) != IDOK)
return;
//str.Format("%s",name);
if(!DeleteFile(str))
{
MessageBox("删除失败!");
}
else
{
m_List->DeleteItem(iSelected);
}
}
void CMTListView::SetPath(CString str,HANDLE handle)
{
path=str;
hDevice=handle;
}
void CMTListView::OnMenuitemForceKill()
{
// TODO: Add your command handler code here
DELETE_INFO delete_info;
if(iSelected < 0 || iSelected >= m_List->GetItemCount())
return;
char name[255];
m_List->GetItemText(iSelected,0, name, 255);
CString str,temp;
str.Format("%s",name);
str=path+str;
temp="确定删除"+str+"吗?";
if(MessageBox(temp,"提示", MB_OKCANCEL) != IDOK)
return;
strcpy(name,str.GetBuffer(str.GetLength()));
ULONG bytesReturned;
DeviceIoControl(hDevice,(DWORD)IOCTL_MT_KILLFILE,name,sizeof(name),&delete_info,sizeof(delete_info),&bytesReturned,NULL);//
if(!delete_info.IsDelete)
{
MessageBox("删除失败!");
}
else
{
m_List->DeleteItem(iSelected);
}
}
void CMTListView::OnSize(UINT nType, int cx, int cy)
{
CListView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
/*if(m_List->GetSafeHwnd())
{
m_List->SetColumnWidth(0,cx/5);
m_List->SetColumnWidth(1,cx/8);
m_List->SetColumnWidth(2,cx/5);
m_List->SetColumnWidth(3,cx/5);
m_List->SetColumnWidth(4,cx/5);
m_List->SetColumnWidth(5,cx/10);
}*/
if(GetListCtrl().GetSafeHwnd())
{
m_List->SetColumnWidth(0,cx/6);
m_List->SetColumnWidth(1,cx/8);
m_List->SetColumnWidth(2,cx/5);
m_List->SetColumnWidth(3,cx/5);
m_List->SetColumnWidth(4,cx/5);
m_List->SetColumnWidth(5,cx/10);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -