📄 filemanagedlg.cpp
字号:
// FileManageDlg.cpp : implementation file
//
#include "stdafx.h"
#include "VipShellClient.h"
#include "FileManageDlg.h"
#include ".\filemanagedlg.h"
#include <shlwapi.h>
#include "../help/Template.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma comment(lib, "shlwapi.lib")
/////////////////////////////////////////////////////////////////////////////
// CFileManageDlg dialog
CFileManageDlg::CFileManageDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileManageDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileManageDlg)
m_listPath = _T("");
//}}AFX_DATA_INIT
}
void CFileManageDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileManageDlg)
DDX_Control(pDX, IDC_LIST_FILE, m_listFile);
DDX_CBString(pDX, IDC_COMBO_TEXT, m_listPath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileManageDlg, CDialog)
//{{AFX_MSG_MAP(CFileManageDlg)
ON_COMMAND(ID_MENUITEM_FILEMANAGEDOWN, OnMenuitemFilemanagedown)
ON_NOTIFY(NM_RCLICK, IDC_LIST_FILE, OnRclickListFile)
ON_COMMAND(ID_MENUITEM_UPFILE, OnMenuitemUpfile)
//}}AFX_MSG_MAP
ON_NOTIFY(NM_DBLCLK, IDC_LIST_FILE, OnNMDblclkListFile)
END_MESSAGE_MAP()
BOOL CFileManageDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_listFile.DragAcceptFiles();
m_listFile.InsertColumn(0, L"名称", LVCFMT_LEFT, 300);
m_listFile.InsertColumn(1, L"大小", LVCFMT_LEFT, 100);
m_listFile.InsertColumn(2, L"修改时间", LVCFMT_LEFT, 200);
__InitImgList();
m_WndCopy.Create(IDD_DIALOG_COPYDLG, this);
m_WndCopy.ShowWindow( SW_HIDE );
GetRoot();
return TRUE;
}
DWORD CFileManageDlg::_GetFileImg(LPCTSTR sz)
{
CString strType;
CString strT = sz;/*GetCurrentPath();*/
TCHAR sPath[MAX_PATH] = {0};
lstrcpy(sPath, strT);
if(_tcsrchr(sPath, _T('.')) != NULL)
strType = _tcsrchr(sPath, _T('.'));
else
strType = sPath;
if(strType[0] != _T('.'))
strType = sz;
if( strType.CompareNoCase(L".exe") == 0 )
return _GetFileImg(L"__exe");
if( strType.CompareNoCase(L".sys") == 0 )
strType = L".dll";
for (UINT i = 0; i < m_strFileType.size(); i++)
{
CString strT = m_strFileType[i];
if(strType.CompareNoCase(m_strFileType[i]) ==0)
return i;
}
HICON hIcon = __FindFileType(strType);
if ( hIcon )
{
_AddImgFileType(hIcon, strType);
return _GetFileImg(sz);
}
return 0;
}
HICON CFileManageDlg::__FindFileType(LPCTSTR szType)
{
CString strRet;
LPCTSTR szKey = szType;
if(lstrlen(szKey) == 0)
return NULL;
HKEY HKEYFileType;
long ret;
CString strFileType = szKey;
ret = RegOpenKeyEx(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &HKEYFileType);
if(ret != ERROR_SUCCESS)
{
RegCloseKey(HKEYFileType);
return NULL;
}
DWORD dwType = REG_SZ;
TCHAR szVel[256] = {0};
DWORD dwLen = 256;
RegQueryValueEx(HKEYFileType, NULL, NULL, &dwType, (BYTE*)szVel, &dwLen);
RegCloseKey(HKEYFileType);
strRet = szVel;
if(strRet.GetLength() == 0)
return NULL;
{{
CString strFileType ; strFileType.Format(_T("%s\\DefaultIcon"), strRet);
ret = RegOpenKeyEx(HKEY_CLASSES_ROOT, strFileType, 0, KEY_READ, &HKEYFileType);
if(ret != ERROR_SUCCESS)
{
RegCloseKey(HKEYFileType);
return NULL;
}
DWORD dwType = REG_SZ;
TCHAR szVel[256] = {0};
DWORD dwLen = 256;
RegQueryValueEx(HKEYFileType, NULL, NULL, &dwType, (BYTE*)szVel, &dwLen);
RegCloseKey(HKEYFileType);
CString strIcoPath = szVel;
CString strFile;
int nFind = strIcoPath.Find(_T(","));
DWORD dwIndex = 0;
if(nFind == -1)
{
strFile = strIcoPath;
}
else
{
strFile = strIcoPath.Left(nFind);
CString strIndex = strIcoPath.Mid(nFind + 1);
LPCTSTR szIndex = strIndex;
for(DWORD i = 0; i < (DWORD)strIndex.GetLength(); i++)
{
if(_wtol(szIndex) != 0)
{
dwIndex = _wtol(szIndex);
break;
}
szIndex ++;
}
}
return ExtractIcon(NULL, strFile, dwIndex );
}}
return NULL;
}
void CFileManageDlg::_AddImgFileType(HICON hIcon, LPCTSTR strFile)
{
m_FileImgList.Add(hIcon);
m_strFileType.push_back(strFile);
}
void CFileManageDlg::_AddImgFileType(UINT dwImgFile, LPCTSTR strFile)
{
HICON hIcon =theApp.LoadIcon(dwImgFile);
_AddImgFileType(hIcon, strFile);
}
void CFileManageDlg::__InitImgList()
{
m_FileImgList.Create(16, 16, TRUE | ILC_COLOR32 , 1000, 0);
_AddImgFileType(IDI_ICON_NOTHING, L"__Nothing");
_AddImgFileType(IDI_ICON_FLOPPY, L"__floppy");
_AddImgFileType(IDI_ICON_EXE, L"__exe");
_AddImgFileType(IDI_ICON_DISK, L"__disk");
_AddImgFileType(IDI_ICON_DIR, L"__dir");
_AddImgFileType(IDI_ICON_CD, L"__cd");
m_listFile.SetImageList(&m_FileImgList, LVSIL_SMALL);
}
/////////////////////////////////////////////////////////////////////////////
// CFileManageDlg message handlers
void CFileManageDlg::SetVipShellClientFileManageHandle(I_VipShellClientFileManageHandle* p)
{
m_spVipShellClientFileManageHandle = p;
m_spVipShellClientFileManageHandle->SetVipShellClientShellHandleEvent(this);
}
BOOL CFileManageDlg::IsDir(UINT32 nIndex)
{
if( m_ViewType == enumViewType_Root )
return FALSE;
if( nIndex == 0 )
return FALSE;
UINT32 nItemDate = m_listFile.GetItemData(nIndex);
return IsDir( m_win32_find_datavecvec[nItemDate] ) ;
}
BOOL CFileManageDlg::IsDir(WIN32_FIND_DATA& file)
{
if(file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
return TRUE;
return FALSE;
}
BOOL CFileManageDlg::IsDir(LPCWSTR szPath)
{
WIN32_FIND_DATA info;
HANDLE hFile = FindFirstFile(szPath, &info);
if ( hFile == INVALID_HANDLE_VALUE )
return FALSE;
FindClose(hFile);
return IsDir(info);
}
CString CFileManageDlg::__MakeTimeString(DWORD dwTime)
{
CString strRet;
if ( dwTime < 60)
strRet.Format(_T("%d秒"), dwTime);
else if (dwTime < 60 * 60)
strRet.Format(_T("%d分钟"), dwTime / 60);
else if (dwTime < 60 * 60 * 24)
strRet.Format(_T("%d小时"), dwTime / 60 / 60);
else
strRet.Format(_T("%d天"), dwTime / 60 / 60 / 24);
return strRet;
}
CString CFileManageDlg::__MakeFileSizeString(DWORD dwSize)
{
CString strRet;
if(dwSize < 1024)
strRet.Format(L"%d字节", dwSize);
else if (dwSize > 1024 && dwSize < 1024 * 1024)
strRet.Format(L"%4.2f K", (float)dwSize / 1024);
else if(dwSize > 1024 * 1024 && dwSize < 1024 * 1024 * 1024)
strRet.Format(L"%4.2f M", (float)dwSize / 1024 / 1024);
else
strRet.Format(L"%4.2f G", (float)dwSize / 1024 / 1024 / 1024);
return strRet;
}
CString CFileManageDlg::__MakeFileTimeString(FILETIME& fileTime)
{
SYSTEMTIME systime;
FileTimeToSystemTime(&fileTime, &systime);
CString strTime;
strTime.Format(_T("%d-%d-%d %d:%d:%02d"), systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond);
return strTime;
}
void CFileManageDlg::OnPathInfo(DWORD dwCount, const BYTE* p)
{
m_ViewType = enumViewType_File;
m_listFile.DeleteAllItems();
m_win32_find_datavecvec.clear();
for( DWORD i = 0; i < dwCount; i++)
{
PWIN32_FIND_DATA pFileData;
pFileData =(PWIN32_FIND_DATA)( p + ( i * sizeof(WIN32_FIND_DATA)));
if( wcscmp(L".", pFileData->cFileName) == 0 )
continue;
if( wcscmp(L"..", pFileData->cFileName) == 0 )
continue;
UINT32 nRetAdd;
UINT32 nCount = m_listFile.GetItemCount();
if( !IsDir(*pFileData) )
{
nRetAdd = m_listFile.InsertItem(nCount, pFileData->cFileName, _GetFileImg(pFileData->cFileName));
}
else
nRetAdd = m_listFile.InsertItem(nCount, pFileData->cFileName, _GetFileImg(L"__dir"));
m_win32_find_datavecvec.push_back(*pFileData);
UINT32 nItemDate = m_win32_find_datavecvec.size() - 1;
m_listFile.SetItemText(nRetAdd, 1, __MakeFileSizeString( pFileData->nFileSizeLow ));
m_listFile.SetItemText(nRetAdd, 2, __MakeFileTimeString( pFileData->ftLastWriteTime ));
m_listFile.SetItemData(nRetAdd, nItemDate);
}
m_listFile.InsertItem(0, L"..向上", _GetFileImg(L"__dir"));
}
void CFileManageDlg::OnRootInfo(DWORD dwCount, const BYTE* p)
{
m_ViewType = enumViewType_Root;
m_listFile.DeleteAllItems();
m_filemanagediskvec.clear();
m_strPath = L"";
for( DWORD i = 0; i < dwCount; i++)
{
PFILEMANAGEDISK pRootData;
pRootData =(PFILEMANAGEDISK)( p + i * sizeof(FILEMANAGEDISK));
DWORD dwType;
DWORD nCount;
nCount = m_listFile.GetItemCount();
if(DRIVE_CDROM == pRootData->dwType)
dwType = _GetFileImg(L"__cd");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -