📄 explorerpage.cpp
字号:
// ExplorerPage.cpp : implementation file
//
#include "stdafx.h"
#include "Scan2PDF.h"
#include "ExplorerPage.h"
#include "Scan2PDFDefs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExplorerPage property page
IMPLEMENT_DYNCREATE(CExplorerPage, CPropertyPageEx)
CExplorerPage::CExplorerPage() : CPropertyPageEx(CExplorerPage::IDD, 0,
IDS_SCANNER_HEADER, IDS_SCANNER_SUBHEADER)
{
//{{AFX_DATA_INIT(CExplorerPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CExplorerPage::~CExplorerPage()
{
}
void CExplorerPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPageEx::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExplorerPage)
DDX_Control(pDX, IDC_DRIVE_COMBO, m_DrivesCombo);
DDX_Control(pDX, IDC_EXPLORER, m_FileList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExplorerPage, CPropertyPageEx)
//{{AFX_MSG_MAP(CExplorerPage)
ON_CBN_SELCHANGE(IDC_DRIVE_COMBO, OnSelChangeDriveCombo)
ON_BN_CLICKED(IDC_FORMAT, OnFormat)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExplorerPage message handlers
BOOL CExplorerPage::OnInitDialog()
{
CPropertyPageEx::OnInitDialog();
LV_COLUMN lvc;
lvc.cx=200;
lvc.mask=LVCF_WIDTH | LVCF_TEXT | LVCF_FMT;
lvc.fmt=LVCFMT_LEFT;
lvc.pszText=_T("FileName");
lvc.cchTextMax=8;
m_FileList.InsertColumn(0, &lvc);
lvc.cx=80;
lvc.pszText=_T("Size");
lvc.cchTextMax=4;
m_FileList.InsertColumn(1, &lvc);
lvc.cx=140;
lvc.pszText=_T("Modified");
lvc.cchTextMax=8;
m_FileList.InsertColumn(2, &lvc);
//fill the combo box
InitializeDriveCombo();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CExplorerPage::InitializeDriveCombo()
{
for (int iCounter=0;iCounter<MAX_OF_DISKS;iCounter++)
if (GetDriveType(DiskLetters[iCounter])==DRIVE_CDROM)
{
TCHAR VolumeName[200]=_T("");
TCHAR FileSystem[50]=_T(""); //FAT, FAT32, NTFS, CDFS, ...
DWORD VolumeSerialNumber=0;
DWORD MaxFileName=0;
DWORD dwFileSystem=0;
GetVolumeInformation(DiskLetters[iCounter], VolumeName, sizeof(VolumeName),
&VolumeSerialNumber, &MaxFileName, &dwFileSystem,
FileSystem, sizeof(FileSystem));
CString DriveLabel;
if (_tcscmp(VolumeName, _T(""))!=0)
DriveLabel.Format(_T("%s (%s)"), DiskLetters[iCounter], VolumeName);
else
DriveLabel.Format(_T("%s"), DiskLetters[iCounter]);
m_DrivesCombo.AddString(DriveLabel);
}
if (m_DrivesCombo.GetCount())
{
m_DrivesCombo.SetCurSel(0); //Select First Drive
PopulateFileList();
}
}
void CExplorerPage::PopulateFileList()
{
//clear the list
m_FileList.DeleteAllItems();
if (!m_DrivesCombo.GetCount())
return;
//get selected drive
TCHAR szSelectedDrive[10];
ZeroMemory(szSelectedDrive, sizeof(TCHAR) * 10);
CString temp;
m_DrivesCombo.GetWindowText(temp);
_tcscpy(szSelectedDrive, temp);
_tcscpy(szSelectedDrive+1, _T(":\\*.*"));
//now populate the files of drive
CFileFind m_filefind;
BOOL bresult=m_filefind.FindFile(szSelectedDrive);
int i=0;
while (bresult)
{
bresult=m_filefind.FindNextFile();
if (!m_filefind.IsDirectory())
{
CString myFile=m_filefind.GetFileName();
int mysize=m_filefind.GetLength();
CTime ref;
m_filefind.GetLastWriteTime(ref);
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT | LVIF_STATE;
lvItem.state = 0;
lvItem.stateMask = 0;
lvItem.iItem = i;
lvItem.iSubItem = 0;
lvItem.pszText=myFile.GetBuffer(0);
m_FileList.InsertItem(&lvItem);
CString szSize;
szSize.Format("%d", mysize);
m_FileList.SetItemText(i, 1, szSize);
CString filetime=ref.Format("%A, %B %d, %Y");
m_FileList.SetItemText(i, 2, filetime);
i++;
}
else
{
CString myFile=m_filefind.GetFileName();
//int mysize=m_filefind.GetLength();
CTime ref;
m_filefind.GetLastWriteTime(ref);
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT | LVIF_STATE;
lvItem.state = 0;
lvItem.stateMask = 0;
lvItem.iItem = i;
lvItem.iSubItem = 0;
lvItem.pszText=myFile.GetBuffer(0);
m_FileList.InsertItem(&lvItem);
CString szSize=_T("<dir>");
m_FileList.SetItemText(i, 1, szSize);
CString filetime=ref.Format("%A, %B %d, %Y");
m_FileList.SetItemText(i, 2, filetime);
//for next item
i++;
}
}
CPropertySheet* parent=(CPropertySheet*) GetParent();
if (m_FileList.GetItemCount())
parent->SetWizardButtons(PSWIZB_BACK);
else
parent->SetWizardButtons(PSWIZB_NEXT);
}
void CExplorerPage::OnSelChangeDriveCombo()
{
PopulateFileList();
}
BOOL CExplorerPage::OnSetActive()
{
PopulateFileList();
return CPropertyPageEx::OnSetActive();
}
LRESULT CExplorerPage::OnWizardNext()
{
if (m_FileList.GetItemCount())
{
AfxMessageBox(_T("The CD Drive that you selected contains some files.\nPlease put a free space CD or format it."), MB_ICONERROR);
return -1;
}
else
{
//save the drive letter for further process
CString Drive;
m_DrivesCombo.GetWindowText(Drive);
TCHAR szDrive[255];
_tcscpy(szDrive, Drive.GetBuffer(0));
szDrive[1]=_T('\0');
theConf.m_DriveLetter=szDrive;
}
return CPropertyPageEx::OnWizardNext();
}
void CExplorerPage::OnFormat()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -