?? diskcheckdlg.cpp
字號(hào):
// DiskCheckDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DiskCheck.h"
#include "DiskCheckDlg.h"
#include <afx.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char PesqPath[50]="",MovePesqPath[50]="";
char SysDir[100]="", IniFile[100]="";
void GetSystemParams ( void );
BOOL DeleteDirectory(char *DirName);
BOOL DeleteDirectory1(char *DirName);
int bz=0,bz1=0;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CDiskCheckDlg dialog
CDiskCheckDlg::CDiskCheckDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDiskCheckDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDiskCheckDlg)
m_edit1 = _T("");
m_edit2 = _T("");
m_edit3 = _T("");
m_edit4 = _T("");
m_edit5 = _T("");
m_edit6 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDiskCheckDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDiskCheckDlg)
DDX_Text(pDX, IDC_EDIT1, m_edit1);
DDX_Text(pDX, IDC_EDIT2, m_edit2);
DDX_Text(pDX, IDC_EDIT3, m_edit3);
DDX_Text(pDX, IDC_EDIT4, m_edit4);
DDX_Text(pDX, IDC_EDIT5, m_edit5);
DDX_Text(pDX, IDC_EDIT6, m_edit6);
DDX_Text(pDX, IDC_EDIT7, m_edit7);
DDX_Text(pDX, IDC_EDIT8, m_edit8);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDiskCheckDlg, CDialog)
//{{AFX_MSG_MAP(CDiskCheckDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDiskCheckDlg message handlers
BOOL CDiskCheckDlg::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
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
GetSystemParams();
SetTimer(1,3000,NULL);
SetTimer(2,3000,NULL);
SetTimer(3,3000,NULL);
SetTimer(4,3000,NULL);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CDiskCheckDlg::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 CDiskCheckDlg::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 CDiskCheckDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDiskCheckDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent){
case 1:
scanfreedisk();
break;
case 2:
DeletePesqPath();
break;
case 3:
DeleteMovePesqPath();
break;
case 4:
scanfreedisk1();
break;
default:
break;
}
CDialog::OnTimer(nIDEvent);
}
void CDiskCheckDlg::DeletePesqPath(void)
{
if(bz==1)
DeleteDirectory(PesqPath);
}
void CDiskCheckDlg::DeleteMovePesqPath(void)
{
if(bz1==1)
DeleteDirectory1(MovePesqPath);
}
void CDiskCheckDlg::scanfreedisk(void)
{
char szBuffer[1024],szBuffer1[1024],szBuffer2[1024],szBuffer3[1024],szBuffer4[1024],szBuffer5[1024];
__int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes ;
GetDiskFreeSpaceEx(PesqPath,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes) ;
ZeroMemory(szBuffer, sizeof(szBuffer)) ;
m_edit7=PesqPath;
sprintf(szBuffer, "%I64dM", i64TotalBytes/1024/1024);
m_edit1=szBuffer;
ZeroMemory(szBuffer1, sizeof(szBuffer)) ;
sprintf(szBuffer1, "%I64dM", i64FreeBytesToCaller/1024/1024);
m_edit2=szBuffer1;
ZeroMemory(szBuffer2, sizeof(szBuffer)) ;
sprintf(szBuffer2, "%I64dM", i64FreeBytes/1024/1024);
m_edit3=szBuffer2;
UpdateData(FALSE);
if((strcmp(szBuffer2,"2500M")<=0)&&(bz==0))
bz=1;
}
void CDiskCheckDlg::scanfreedisk1(void)
{
char szBuffer[1024],szBuffer1[1024],szBuffer2[1024],szBuffer3[1024],szBuffer4[1024],szBuffer5[1024];
__int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes ;
m_edit8=MovePesqPath;
GetDiskFreeSpaceEx(MovePesqPath,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes) ;
ZeroMemory(szBuffer3, sizeof(szBuffer3)) ;
sprintf(szBuffer3, "%I64dM", i64TotalBytes/1024/1024);
m_edit4=szBuffer3;
ZeroMemory(szBuffer4, sizeof(szBuffer4)) ;
sprintf(szBuffer4, "%I64dM", i64FreeBytesToCaller/1024/1024);
m_edit5=szBuffer4;
ZeroMemory(szBuffer5, sizeof(szBuffer5)) ;
sprintf(szBuffer5, "%I64dM", i64FreeBytes/1024/1024);
m_edit6=szBuffer5;
UpdateData(FALSE);
if((strcmp(szBuffer5,"2500M")<=0)&&(bz1==0))
bz1=1;
}
void GetSystemParams ( void )
{
GetSystemDirectory (SysDir,100);
strcpy ( IniFile, SysDir );
strcat ( IniFile, "\\qmap.ini" );
GetPrivateProfileString ( "System", "PesqPath", "", PesqPath, sizeof(PesqPath), IniFile );
GetPrivateProfileString ( "System", "MovePesqPath", "", MovePesqPath, sizeof(MovePesqPath), IniFile );
}
void CDiskCheckDlg::OnCancel()
{
if(MessageBox("確定退出?","監(jiān)測磁盤空間程序",MB_OKCANCEL)==IDOK){
KillTimer(1);
KillTimer(2);
KillTimer(3);
CDialog::OnCancel();
}
}
BOOL DeleteDirectory(char *DirName)
{
SYSTEMTIME st;
CFileFind tempFind;
char tempFileFind[200];
sprintf(tempFileFind,"%s\\*.*",DirName);
bz=2;
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[200],filetime[20];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
GetLocalTime(&st);
sprintf(filetime,"%d%02d%02d",st.wYear,st.wMonth,st.wDay);
if(strncmp(foundFileName,filetime,8)<0){
if(tempFind.IsDirectory())
{
char tempDir[200];
sprintf(tempDir,"%s\\%s",DirName,foundFileName);
if(strcmp(tempDir,PesqPath)==0)
break;
DeleteDirectory(tempDir);
}
else
{
char tempFileName[200];
sprintf(tempFileName,"%s\\%s",DirName,foundFileName);
DeleteFile(tempFileName);
}
}
}
}
tempFind.Close();
if(strcmp(DirName,PesqPath)==0){
bz=0;
return TRUE;
}
if(!RemoveDirectory(DirName))
{
bz=0;
return FALSE;
}
bz=0;
return TRUE;
}
BOOL DeleteDirectory1(char *DirName)
{
SYSTEMTIME st;
CFileFind tempFind;
char tempFileFind[200];
sprintf(tempFileFind,"%s\\*.*",DirName);
bz1=2;
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[200],filetime[20];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
GetLocalTime(&st);
sprintf(filetime,"%d%02d%02d",st.wYear,st.wMonth,st.wDay);
if(strncmp(foundFileName,filetime,8)<0){
if(tempFind.IsDirectory())
{
char tempDir[200];
sprintf(tempDir,"%s\\%s",DirName,foundFileName);
if(strcmp(tempDir,MovePesqPath)==0)
break;
DeleteDirectory(tempDir);
}
else
{
char tempFileName[200];
sprintf(tempFileName,"%s\\%s",DirName,foundFileName);
DeleteFile(tempFileName);
}
}
}
}
tempFind.Close();
if(strcmp(DirName,MovePesqPath)==0){
bz1=0;
return TRUE;
}
if(!RemoveDirectory(DirName))
{
bz1=0;
return FALSE;
}
bz1=0;
return TRUE;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -