⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ext32dlg.cpp

📁 visual c++ 实例编程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Ext32Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Ext32.h"
#include "Ext32Dlg.h"
#include "PathDlg.h"
#include "FilesDlg.h"
#include <direct.h>
#include <process.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define EXTNAME 0
#define EXTSIZE 1
#define EXTCOUNT 2
#define EXTCLUST 3
#define EXTTYPE 4
#define MAX_ALLOC_SIZE  sizeof(EXTINFO)*3000

char gsExtPath[MAX_PATH], gsFilespec[MAX_PATH];
BOOL gbStopThread, gbFreeFail, gbAscOrder;
DWORD gdNumFiles, gdNumExt;
EXTINFO *gpExtMem;
HWND ghDispFold, ghListBox, ghSearch, ghExit, hWndMain, ghNumExt;
DWORD gdSectorsPerCluster, gdBytesPerSector, gdNumFreeClusters, gdTotNumOfClusters, gdBytesPerClust;
CListCtrl m_ListCtrl;
CImageList ghImageList;
HINSTANCE ghInstance;
DWORD gdTotClust=0;
HICON Icon[4], hIconMain;
int AnimNum;
extern BOOL gbSubDir;
void CALLBACK IconTimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);
void InitTimerIcon(void);
void FinishTimerIcon(void);

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExt32Dlg dialog

CExt32Dlg::CExt32Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CExt32Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CExt32Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CExt32Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExt32Dlg)
	DDX_Control(pDX, IDC_NUMEXTEN, m_NumExten);
	DDX_Control(pDX, IDC_EXTLIST, m_ListCtrl);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CExt32Dlg, CDialog)
	//{{AFX_MSG_MAP(CExt32Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDEXIT, OnExit)
	ON_BN_CLICKED(IDFILES, OnFilespec)
	ON_BN_CLICKED(IDPATH, OnPath)
	ON_BN_CLICKED(IDSEARCH, OnSearch)
	ON_BN_CLICKED(IDSTOP, OnStop)
	ON_BN_CLICKED(IDABOUT, OnAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExt32Dlg message handlers

BOOL CExt32Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	
	// TODO: Add extra initialization here
	ghDispFold = ::GetDlgItem(this->m_hWnd, IDC_DISPFOLD);
	ghNumExt = ::GetDlgItem(this->m_hWnd, IDC_NUMEXTEN);
	ghListBox = ::GetDlgItem(this->m_hWnd, IDC_FILELIST);
	ghSearch = ::GetDlgItem(this->m_hWnd, IDSEARCH);
	ghExit = ::GetDlgItem(this->m_hWnd, IDEXIT);
	ghInstance = AfxGetApp()->m_hInstance;

	Icon[0] = ::LoadIcon(ghInstance, "Anim1");
	Icon[1] = ::LoadIcon(ghInstance, "Anim2");
	Icon[2] = ::LoadIcon(ghInstance, "Anim3");
	Icon[3] = ::LoadIcon(ghInstance, "Anim4");
	hIconMain = ::LoadIcon(ghInstance, "Ext");
	hWndMain = this->m_hWnd;
	SetIcon(hIconMain, TRUE);			// Set big icon
	SetIcon(hIconMain, FALSE);		// Set small icon
	ListView_SetExtendedListViewStyle(m_ListCtrl.m_hWnd, LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
	LV_COLUMN lvC;      		// list view column structure

	lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvC.fmt = LVCFMT_LEFT;  // left-align column
	lvC.cx = 75;            // width of column in pixels

	// Add the columns.
	lvC.pszText = "Extension";
	lvC.iSubItem = EXTNAME;
	m_ListCtrl.InsertColumn(EXTNAME, &lvC);
	lvC.pszText = "Size";
	lvC.iSubItem = EXTSIZE;
	m_ListCtrl.InsertColumn(EXTSIZE, &lvC);
	lvC.pszText = "Count";
	lvC.iSubItem = EXTCOUNT;
	m_ListCtrl.InsertColumn(EXTCOUNT, &lvC);
	lvC.pszText = "Real Size";
	lvC.iSubItem = EXTCLUST;
	m_ListCtrl.InsertColumn(EXTCLUST, &lvC);
	lvC.cx = 120;
	lvC.pszText = "Extension Type";
	lvC.iSubItem = EXTTYPE;
	m_ListCtrl.InsertColumn(EXTTYPE, &lvC);
	hExtMem = LocalAlloc(LMEM_MOVEABLE|LMEM_ZEROINIT, MAX_ALLOC_SIZE);
	if(hExtMem == NULL){
		AfxMessageBox("Error Allocating local memory");
		AfxEndThread(0);
		CDialog::OnOK();
	}
	gpExtMem = (EXTINFO *) LocalLock(hExtMem);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CExt32Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CExt32Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CExt32Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CExt32Dlg::OnExit() 
{
	// TODO: Add your control notification handler code here
	LocalFree(hExtMem);
	PostQuitMessage(0);
//	CDialog::OnOK();
}

void CExt32Dlg::OnFilespec() 
{
	// TODO: Add your control notification handler code here
	FilesDlg fd;
	fd.DoModal();
}

void CExt32Dlg::OnPath() 
{
	// TODO: Add your control notification handler code here
	PathDlg pd;
	pd.DoModal();
}

void CExt32Dlg::OnSearch() 
{
	// TODO: Add your control notification handler code here
	gbStopThread = FALSE;
	gdNumExt = gdNumFiles = gdTotClust = 0;
	if(gsFilespec[0] == 0)
		strcpy(gsFilespec, "*.*");
	m_ListCtrl.DeleteAllItems();
	ghImageList.DeleteImageList();
	ghImageList.Create(32, 32, TRUE, 1, 0);
	m_ListCtrl.SetImageList(&ghImageList, LVSIL_SMALL);
	AfxBeginThread(SearchExtProc, 0);
}

void CExt32Dlg::OnStop() 
{
	// TODO: Add your control notification handler code here
	gbStopThread = TRUE;
	
}

UINT CExt32Dlg::SearchExtProc(LPVOID lParam)
{
	int iCurrDrive = 0;
	char cCurrDir[]="A:\\";

	InitTimerIcon();
   	if(strcmpi(gsExtPath, "All") == 0){
		while(iCurrDrive<26){
			cCurrDir[0] = 'A'+iCurrDrive++;
			if(!_chdir(cCurrDir)){
				if(!GetDiskFreeSpace(NULL, &gdSectorsPerCluster, &gdBytesPerSector, &gdNumFreeClusters, &gdTotNumOfClusters))
					gdBytesPerClust = 1;
				else
					gdBytesPerClust = gdSectorsPerCluster*gdBytesPerSector;
				DisableButtons();
				OurFindFile(gsFilespec, 1);
			}
		}
	}
	else if(!_chdir(gsExtPath)){
		if(!GetDiskFreeSpace(NULL, &gdSectorsPerCluster, &gdBytesPerSector, &gdNumFreeClusters, &gdTotNumOfClusters))
			gdBytesPerClust = 1;
		else
			gdBytesPerClust = gdSectorsPerCluster*gdBytesPerSector;
		DisableButtons();
		OurFindFile(gsFilespec, 1);
	}
	else
		AfxMessageBox("Unable to locate the path");
	FinishTimerIcon();
	EnableButtons();
	::SetWindowText(ghDispFold, "");
	PrintExtInfo();
	AfxEndThread(0);
	return 1;
}

void DisableButtons(void)
{
	::EnableWindow(ghSearch, FALSE);
	::EnableWindow(ghExit, FALSE);
}

void EnableButtons(void)
{
	::EnableWindow(ghSearch, TRUE);
	::EnableWindow(ghExit, TRUE);
}

void OurFindFile(char FileSpec[], int NumFileSpec)
{
	WIN32_FIND_DATA FindStruct;
	HANDLE FFHan;
	char cPath[_MAX_PATH];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -