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

📄 clearalldlg.cpp

📁 递归法实现一键清空,可以清空浏览记录,查找痕迹,网址等,在VC.NET,WINXP下调试通过.
💻 CPP
字号:
// ClearAllDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ClearAll.h"
#include "ClearAllDlg.h"
#include "Registry.h"
#include "HyperLink.h"

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

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

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

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CHyperLink	m_email;
	//}}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
	
//EMAIL显示
	m_email.SetURL("mailto:david-angel@sohu.com");
	m_email.SetUnderline(FALSE);
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_EMAIL, m_email);
	//}}AFX_DATA_MAP
}

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

/////////////////////////////////////////////////////////////////////////////
// CClearAllDlg dialog

CClearAllDlg::CClearAllDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CClearAllDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CClearAllDlg)
	m_status = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CClearAllDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClearAllDlg)
	DDX_Control(pDX, IDC_BUTTON1, m_button);
	DDX_Control(pDX, IDC_INTRO, m_intro);
	DDX_Text(pDX, IDC_STATUS, m_status);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CClearAllDlg, CDialog)
	//{{AFX_MSG_MAP(CClearAllDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClearAllDlg message handlers

BOOL CClearAllDlg::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
	
//软件介绍显示
	TCHAR *pIntro={
		_T("软件介绍\t|"
			"本软件实现了一键清空的功能|"
			"可以方便有效的保护您的隐私|"
			"本软件清理的内容包括:|"
			"清除我最近的文档|"
			"清除IE访问记录|"
			"清除上网历史记录|"
			"清除地址栏URL记录|"
			"清除REALPLAY播放列表|"
			"清除REALONE播放列表|"
			"支持Windows 9X/2000/XP/2003||"
			"版权信息\t|"
			"程序设计:同济大学 David|"
			"感谢女友CiCi的支持|"
			"CopyRight 2003\r||||||||")
		
	};
	m_intro.SetCredits(pIntro);
	m_intro.StartScrolling();

//更改按钮风格
	m_button.SetTooltipText("单击按钮,立即清空");
	m_button.SetColor(4,RGB(120, 180, 230));
	m_button.SetColor(0,RGB(180, 180, 230));

//提示条显示
	m_status="请单击上面的按钮";
	UpdateData(FALSE);
	// TODO: Add extra initialization here

	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CClearAllDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	
//判断操作系统
	OSVERSIONINFO os;
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&os);
	
//操作系统为WINDOWS 2000/XP/2003的情况
if (os.dwPlatformId==VER_PLATFORM_WIN32_NT)
{
	//构造NT环境下我的文档的文件路径
	CString clearpath;
	char buffer[MAX_PATH];
	char name[100];
	char pcname[100];
	DWORD nSize=100;
	DWORD nSize2=100;
	int n=0;
	GetWindowsDirectory(buffer,MAX_PATH);
	GetUserName(name,&nSize);
	GetComputerName(pcname,&nSize2);
		
	//以下操作涉及文件删除,慎用!
		
	//清除我最近的文档
	m_status="正在清除我的文档";UpdateData(FALSE);
	clearpath=buffer[0];
	clearpath+=":\\Documents and Settings\\";
	while (name[n]!='\0') {clearpath+=name[n];n++;}
	clearpath+="\\Recent\\";
	ClearDir(clearpath);
	clearpath.Empty();
	clearpath=buffer[0];
	clearpath+=":\\Documents and Settings\\Default User\\Recent\\";
	ClearDir(clearpath);
	clearpath.Empty();
	n=0;
		
	//构造另一种名字路径
	clearpath=buffer[0];
	clearpath+=":\\Documents and Settings\\";
	while (name[n]!='\0') {clearpath+=name[n];n++;}
	clearpath+='.';
	n=0;
	while (pcname[n]!='\0') {clearpath+=pcname[n];n++;}
	clearpath+="\\Recent\\";
	ClearDir(clearpath);
	clearpath.Empty();
		
	//清除上网历史记录
	n=0;
	m_status="清除上网历史记录";UpdateData(FALSE);
	clearpath=buffer[0];
	clearpath+=":\\Documents and Settings\\";
	while (name[n]!='\0') {clearpath+=name[n];n++;}
	clearpath+="\\Local Settings\\History\\";	
	ClearDir(clearpath);
	clearpath.Empty();
		
	clearpath=buffer[0];
	clearpath+=":\\Documents and Settings\\Default User\\Local Settings\\History\\";
	ClearDir(clearpath);
	clearpath.Empty();
	n=0;
		
	//构造另一种路径
	clearpath=buffer[0];
	clearpath+=":\\Documents and Settings\\";
	while (name[n]!='\0') {clearpath+=name[n];n++;}
	clearpath+='.';
	n=0;
	while (pcname[n]!='\0') {clearpath+=pcname[n];n++;}
	clearpath+="\\Local Settings\\History\\";
	ClearDir(clearpath);
	clearpath.Empty();
			
	//以下操作仅涉及到注册表

	//清除URL记录
	m_status="清除URL记录";UpdateData(FALSE);
	CRegistry key(HKEY_CURRENT_USER);
	key.DeleteKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Internet Explorer\\TypedURLs\0");

	//清除IE记录
	m_status="清除IE记录";UpdateData(FALSE);
	CRegistry key3(HKEY_CURRENT_USER);
	key3.DeleteKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Internet Explorer\\Explorer Bars\\{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1}\\FilesNamedMRU\0");
	key3.DeleteKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\UserAssist\\{75048700-EF1F-11D0-9888-006097DEACF9}\\Count\0");

	//清除REALONE播放列表
	m_status="清除REALONE播放列表";UpdateData(FALSE);
	CRegistry key4(HKEY_CURRENT_USER);
	char szpath[MAX_PATH];
	for (int i=1;i<=10;i++)
	{
	sprintf(szpath,"Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MostRecentClips%d\0",i);
	key4.DeleteKey(HKEY_CURRENT_USER,szpath);
	}
	
    //清除REALPLAY播放列表	
	m_status="清除REALPLAY播放列表";UpdateData(FALSE);
	CRegistry key5(HKEY_LOCAL_MACHINE);
	for (i=1;i<=10;i++)
	{
	sprintf(szpath,"SOFTWARE\\Classes\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MostRecentClips%d\0",i);
	key5.DeleteKey(HKEY_LOCAL_MACHINE,szpath);
	}

	m_status="全部清理完毕";UpdateData(FALSE);
}


//操作系统为WINDOWS 9X的情况
	if (os.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
	{
	CString clearpath;
	char buffer[MAX_PATH];
	GetWindowsDirectory(buffer,MAX_PATH);
	
	//清除我最近的文档
	clearpath=buffer[0];
	clearpath+=":\\WINDOWS\\Recent\\";
	m_status="正在清除我的文档";UpdateData(FALSE);
	ClearDir(clearpath);
	clearpath.Empty();
	
	//清除历史记录
	clearpath=buffer[0];
	clearpath+=":\\WINDOWS\\History\\";
	m_status="清除上网历史记录";UpdateData(FALSE);
	ClearDir(clearpath);
	clearpath.Empty();
	
	//清除URL记录
	m_status="清除URL记录";UpdateData(FALSE);
	CRegistry key(HKEY_CURRENT_USER);
	key.DeleteKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Internet Explorer\\TypedURLs\0");
		
	//清除IE记录
	m_status="清除IE记录";UpdateData(FALSE);
	CRegistry key3(HKEY_CURRENT_USER);
	key3.DeleteKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Internet Explorer\\Explorer Bars\\{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1}\\FilesNamedMRU\0");
	key3.DeleteKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\UserAssist\\{75048700-EF1F-11D0-9888-006097DEACF9}\\Count\0");
	
	//清除REALONE播放列表
	m_status="清除REALONE播放列表";UpdateData(FALSE);
	CRegistry key4(HKEY_CURRENT_USER);
	char szpath[MAX_PATH];
	for (int i=1;i<=10;i++)
	{
		sprintf(szpath,"Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MostRecentClips%d\0",i);
		key4.DeleteKey(HKEY_CURRENT_USER,szpath);
	}
	
    //清除REALPLAY播放列表	
	m_status="清除REALPLAY播放列表";UpdateData(FALSE);
	CRegistry key5(HKEY_LOCAL_MACHINE);
	for (i=1;i<=10;i++)
	{
		sprintf(szpath,"SOFTWARE\\Classes\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MostRecentClips%d\0",i);
		key5.DeleteKey(HKEY_LOCAL_MACHINE,szpath);
	}
	
	m_status="全部清理完毕";UpdateData(FALSE);
	}

}

//递归法清除一个目录下所有文件和子目录
void CClearAllDlg::ClearDir(CString str)
  {	
	CFileFind ff;
	CString szDir=str;
	if (szDir.Right(1)!="\\") szDir+="\\";
	szDir+="*.*";
	
	BOOL bfile=ff.FindFile(szDir);
	while (bfile)
	{
	  bfile=ff.FindNextFile();
	  if (ff.IsDirectory() && !ff.IsDots())   ClearDir(ff.GetFilePath());
	  else if (!ff.IsDots() && !ff.IsDirectory())  DeleteFile(ff.GetFilePath());
	}
	 ff.Close();
  }

⌨️ 快捷键说明

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