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

📄 cleardiskdlg.cpp

📁 一种相当实用的硬盘空间检测工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
**  **************************************************************************
**  
**  
**       (c) CopyRight 2006-2006, ZheJiang Dahua Technology Stock Co.Ltd.
**                            All Rights Reserved
**  
**       File Name    : ClearDiskDlg.cpp
**       Description  : 硬盘空间监视
**       Modification : 2006/8/15
**  
**       Current ver  : 1.0.0
**       Writer       : 金杰
**  
**  **************************************************************************
*/

#include "stdafx.h"
#include "ClearDisk.h"
#include "ClearDiskDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//#include "BrowseForFolder.h"
#include "shlobj.h"
#include "Lm.h"
#include <wchar.h>
#include "Space.h"

UINT threadFunc ( LPVOID p );

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CClearDiskDlg dialog

CClearDiskDlg::CClearDiskDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CClearDiskDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CClearDiskDlg)
		// 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(IDI_MAIN);

}

void CClearDiskDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClearDiskDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CClearDiskDlg, CDialog)
	//{{AFX_MSG_MAP(CClearDiskDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SelectFolder, OnSelectFolder)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DEL, OnDel)
	ON_BN_CLICKED(IDC_ADDIP, OnAddip)
	ON_BN_CLICKED(IDC_DELIP, OnDelip)
	ON_BN_CLICKED(IDC_RUN, OnRun)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_WM_CLOSE()
	ON_WM_DESTROY()
	ON_MESSAGE( WM_ALARMMSG, OnSendAlarmMsg )
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClearDiskDlg message handlers

BOOL CClearDiskDlg::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
	
	// TODO: Add extra initialization here
	char szSysPath[MAXPATH];
	
	//取得系统当前运行目录
	memset( szSysPath, 0, MAXPATH );
	if( GetCurrentDirectory( MAXPATH, szSysPath ) )
	{
		m_strSysPath.Format( "%s", szSysPath );
	}
	else
	{
		m_strSysPath.Format( "." );
	}

	//定义配置文件名
	m_strProfile.Format( "cleardisk.ini" );

	m_dwFreeSpace = 1000;
	m_dwSendMsgTime = ::GetTickCount();

	//读取配置文件中的参数
	ReadProfile( );
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CClearDiskDlg::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 CClearDiskDlg::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 CClearDiskDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

#include <iostream.h>

void CClearDiskDlg::OnSelectFolder() 
{

	SelectPath( );

	return;
}

/* 
==  ============================================================
==  Function     : SelectPath
==  Description  : 弹出目录选择窗口,选择目录
==  Argument     : 
==  
==  Return       : TRUE  操作成功
==                 FALSE 操作失败
==  Modification : 2006-08-15
==  Writer       : 金杰
==  ============================================================
*/
BOOL CClearDiskDlg::SelectPath( )
{
	char FixString[201];
	char LocalComputerName[51];
	CString strPath;
	ITEMIDLIST* mList;
	BROWSEINFO mInfo;

	memset(FixString,0,201);
	memset(LocalComputerName,0,51);
	memset( &mInfo, 0, sizeof( BROWSEINFO ) );

	mInfo.hwndOwner = m_hWnd;
	mInfo.pidlRoot = NULL; 
	mInfo.pszDisplayName = FixString;
	mInfo.lpszTitle = "位置";
	mInfo.ulFlags = 1;
	mInfo.lpfn = NULL;
	mInfo.lParam = 0;
	mInfo.iImage = 0;

	//显示目录选择对话框
	mList=SHBrowseForFolder(&mInfo);
	if (mList == NULL)
	{
		return FALSE;
	}

	if (SHGetPathFromIDList( mList, FixString ))
	{
		strPath.Format("%s",FixString);
	}

	if (strPath.GetLength() && strPath.Left(2)!="\\\\")
	{
		switch (GetDriveType(strPath.Left(1)+":"))
		{
		  case 0:
			  AfxMessageBox("对不起,无法读取您选择的驱动器!");
			  return FALSE;
		  case 1:
			  //GetComputerName(LocalComputerName, &i);
			  //M.Format("%s",LocalComputerName); 
			  //T="\\\\"+M+"\\"+T.Left(1) +T.Mid(2);
			  break;
		  case 2:
			  AfxMessageBox("对不起,您选择的软盘驱动器不能作为本系统的存储介质!");
			  return FALSE;
		  case 3:
			  //GetComputerName(LocalComputerName, &i);
			  //U=GetLastError();
			  //M.Format("%s",LocalComputerName); 
			  //T="\\\\"+M+"\\"+T.Left(1) +T.Mid(2);
			  break;
		  case 4:
			  AfxMessageBox("对不起,您选择的驱动器是一个映射的网络驱动器,不能这样使用,请您再次选择打开,改从网上邻居中浏览此驱动器!");
			  return FALSE;
		  case 5:
			  AfxMessageBox("对不起,您选择的CD-ROM驱动器不能作为本系统的存储介质!");
			  return FALSE;
		  case 6:
			  AfxMessageBox("对不起,您选择的RAM驱动器不能作为本系统的存储介质!");
			  return FALSE;
		  default:
			  break;
		}
	}
	else
	{
		return FALSE;
	}

	if (strPath.Right(1) == "\\")
	{
		strPath = strPath.Left( strPath.GetLength() - 1 );
	}

	//显示所选目录
	SetDlgItemText( IDC_PATH, strPath );

	return TRUE;
}

/* 
==  ============================================================
==  Function     : OnAdd
==  Description  : 向目录列表增加目录
==  Argument     : 
==  
==  Return       : 
==                 
==  Modification : 2006-08-15
==  Writer       : 金杰
==  ============================================================
*/
void CClearDiskDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	CString strPath;
	CString strBuf;
	CListBox *pList;
	int nIdx = 0;
	int nCount = 0;

	pList = (CListBox *)GetDlgItem( IDC_CLEAR );
	if( !pList )
	{
		AfxMessageBox( "向列表中追加路径失败!取控件地址失败!" );
		return;
	}

	GetDlgItemText( IDC_PATH, strPath );

	if( strPath.GetLength() < 2 )
	{
		return;
	}

	//去掉目录最后的斜杆
	if( !strPath.Right( 1 ).Compare( "\\" ) )
	{
		strPath.Left( strPath.GetLength() - 1 );
	}

//	if( !strPath.Left( 1 ).Compare( "c" ) || !strPath.Left( 1 ).Compare( "C" ) )
//	{
//		AfxMessageBox( "不能对系统所在驱动器进行文件清理!" );
//		return;
//	}

	//判断列表中是否已经存在
	nIdx = 0;
	nCount = pList->GetCount();

	for( nIdx = 0; nIdx < nCount; nIdx ++ )
	{
		pList->GetText( nIdx, strBuf );
		if( !strPath.Compare( strBuf ) )
		{
			strBuf.Format( "列表中已经存在 目录【%s】!", strPath );
			AfxMessageBox( strBuf );
			SetDlgItemText( IDC_PATH, "" );
			return;
		}
	}

	//向列表中添加目录
	pList->AddString( strPath );
	SetDlgItemText( IDC_PATH, "" );

}

/* 
==  ============================================================
==  Function     : OnDel
==  Description  : 删除目录列表中的当前选中目录
==  Argument     : 
==  
==  Return       : 
==                 
==  Modification : 2006-08-15
==  Writer       : 金杰
==  ============================================================
*/
void CClearDiskDlg::OnDel() 
{
	// TODO: Add your control notification handler code here
	int nSel = -1;
	CListBox *pList;

	pList = (CListBox *)GetDlgItem( IDC_CLEAR );
	if (!pList)
	{
		AfxMessageBox( "向列表中追加路径失败!取控件地址失败!" );
		return;
	}

	//取得当前所选行号
	nSel = pList->GetCurSel();
	if( nSel > -1 )
	{
		pList->DeleteString( nSel );
		if( nSel < pList->GetCount() )
		{
			pList->SetCurSel( nSel );
		}
	}
}

/* 
==  ============================================================
==  Function     : OnAddip
==  Description  : 向地址列表中增加地址
==  Argument     : 
==  
==  Return       : 
==                 
==  Modification : 2006-08-15
==  Writer       : 金杰
==  ============================================================
*/
void CClearDiskDlg::OnAddip() 
{
	// TODO: Add your control notification handler code here
	CListBox *pList = NULL;
	CIPAddressCtrl *pIp = NULL;
	CString strIP;
	CString strBuf;
	BYTE nF1;
	BYTE nF2;
	BYTE nF3;
	BYTE nF4;
	int nIdx = 0;
	int nCount = 0;

	pIp = (CIPAddressCtrl *)GetDlgItem( IDC_IP );
	if (!pIp)
	{
		AfxMessageBox( "向列表中追加IP地址失败!取控件地址失败!" );
		return;
	}

	pList = (CListBox *)GetDlgItem( IDC_IPLIST );
	if (!pList)
	{
		AfxMessageBox( "向列表中追加IP地址失败!取控件地址失败!" );
		return;
	}

	//从控件读取IP地址
	if( !pIp->GetAddress( nF1,nF2,nF3,nF4 ) )
	{
		AfxMessageBox( "取IP地址失败!" );
		return;
	}

	strIP.Format( "%d.%d.%d.%d", nF1, nF2, nF3, nF4 );

	//判断列表中是否已经存在
	nIdx = 0;
	nCount = pList->GetCount();

	for( nIdx = 0; nIdx < nCount; nIdx ++ )
	{
		pList->GetText( nIdx, strBuf );
		if( !strIP.Compare( strBuf ) )
		{
			strBuf.Format( "列表中已经存在 IP【%s】!", strIP );
			AfxMessageBox( strBuf );
			pIp->SetAddress( 0,0,0,0 );
			return;
		}
	}

	//向列表中添加IP
	pList->AddString( strIP );
}

/* 
==  ============================================================
==  Function     : OnDelip
==  Description  : 删除地址列表中当前选中的地址
==  Argument     : 
==  
==  Return       : 
==                 
==  Modification : 2006-08-15
==  Writer       : 金杰
==  ============================================================
*/
void CClearDiskDlg::OnDelip() 
{
	// TODO: Add your control notification handler code here
	int nSel = -1;
	CListBox *pList;

	pList = (CListBox *)GetDlgItem( IDC_IPLIST );
	if (!pList)
	{
		AfxMessageBox( "删除列表中IP地址失败!取控件地址失败!" );
		return;
	}

	//取得当前所选行号
	nSel = pList->GetCurSel();
	if( nSel > -1 )
	{
		pList->DeleteString( nSel );
		if( nSel < pList->GetCount() )
		{
			pList->SetCurSel( nSel );
		}
	}
}

/* 
==  ============================================================
==  Function     : OnSendAlarmMsg
==  Description  : 响应请求向工作站发送警告信息
==  Argument     : 
==  
==  Return       : 
==                 
==  Modification : 2006-08-15
==  Writer       : 金杰
==  ============================================================
*/
void CClearDiskDlg::OnSendAlarmMsg()
{
	//半小时响应警告信息得发送,避免重复发送
	if( ::GetTickCount() - m_dwSendMsgTime > 30 * 60 * 1000 )
	{
		//向工作站发送警告信息
		SendAlarmMsg( );
		m_dwSendMsgTime = ::GetTickCount( );
	}
}

/* 
==  ============================================================
==  Function     : SendAlarmMsg
==  Description  : 向工作站发送警告信息
==  Argument     : 
==  
==  Return       : TRUE  :发送成功
==                 FALSE :发送失败 
==  Modification : 2006-08-15
==  Writer       : 金杰
==  ============================================================

⌨️ 快捷键说明

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