kill.cpp
来自「自己写的一个仿瑞星界面,没有什么具体功能,请不要见笑」· C++ 代码 · 共 207 行
CPP
207 行
// Kill.cpp : implementation file
//
#include "stdafx.h"
#include "rising.h"
#include "Kill.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CKill dialog
CKill::CKill(CWnd* pParent /*=NULL*/)
: CDialog(CKill::IDD, pParent)
{
//{{AFX_DATA_INIT(CKill)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CKill::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKill)
DDX_Control(pDX, IDC_TREE1, m_tree);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_BUTTON1, m_btnSetSpace);
DDX_Control(pDX, IDC_BUTTON2, m_btnBegin);
DDX_Control(pDX, IDC_BUTTON5, m_btnStop);
DDX_Control(pDX, IDC_BUTTON6, m_btnSetKill);
}
BEGIN_MESSAGE_MAP(CKill, CDialog)
//{{AFX_MSG_MAP(CKill)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
ON_NOTIFY(TVN_ITEMEXPANDED, IDC_TREE1, OnItemexpandedTree1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKill message handlers
void CKill::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CDC dcMem;
dcMem.CreateCompatibleDC(&dc); //创建与对话框dc兼容的内存dc
CRect rect;
GetClientRect(&rect);
BITMAP bitMap;
m_bmpBackground.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&m_bmpBackground); //将背景位图选入内存dc中
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY); //将内存dc中的位图拉伸显示在对话框的dc中
//dc.BitBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,SRCCOPY);
// Do not call CDialog::OnPaint() for painting messages
}
BOOL CKill::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_bmpBackground.LoadBitmap(IDB_BITMAP5);
m_ImageList.Create(32,32,ILC_COLOR32,10,30);
DWORD dwStyle = GetWindowLong(m_tree.m_hWnd,GWL_STYLE);
dwStyle |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT;
SetWindowLong(m_tree.m_hWnd,GWL_STYLE,dwStyle);
m_hRoot = m_tree.InsertItem("我的电脑");
GetLogicalDrives(m_hRoot);
GetDriveDir(m_hRoot);
m_tree.Expand(m_hRoot,TVE_EXPAND);
GetDlgItem(IDC_COMBO1)->SetWindowText("不处理");
GetDlgItem(IDC_COMBO2)->SetWindowText("返回");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
HBRUSH CKill::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
pDC->SetTextColor(RGB(0,0,80));
// TODO: Change any attributes of the DC here
switch(nCtlColor)
{
case CTLCOLOR_STATIC:
pDC->SetBkMode(TRANSPARENT);
hbr=(HBRUSH)::GetStockObject(NULL_BRUSH);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CKill::OnItemexpandedTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
TVITEM item = pNMTreeView->itemNew;
if(item.hItem == m_hRoot)
return;
HTREEITEM hChild = m_tree.GetChildItem(item.hItem);
while(hChild)
{
AddSubDir(hChild);
hChild = m_tree.GetNextItem(hChild,TVGN_NEXT);
}
*pResult = 0;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//函数功能:获取驱动器
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void CKill::GetLogicalDrives(HTREEITEM hParent)
{
size_t szAllDriveStrings = GetLogicalDriveStrings(0,NULL);
char *pDriveStrings = new char[szAllDriveStrings + sizeof(_T(""))];
char *pNew = pDriveStrings;
GetLogicalDriveStrings(szAllDriveStrings,pDriveStrings);
size_t szDriveString = strlen(pDriveStrings);
while(szDriveString > 0)
{
m_tree.InsertItem(pDriveStrings,hParent);
pDriveStrings += szDriveString + 1;
szDriveString = strlen(pDriveStrings);
}
delete pNew;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//函数功能:添加子项
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void CKill::GetDriveDir(HTREEITEM hParent)
{
HTREEITEM hChild = m_tree.GetChildItem(hParent);
while(hChild)
{
CString strText = m_tree.GetItemText(hChild);
if(strText.Right(1) != "\\")
strText += _T("\\");
strText += "*.*";
CFileFind file;
BOOL bContinue = file.FindFile(strText);
while(bContinue)
{
bContinue = file.FindNextFile();
if(file.IsDirectory() && !file.IsDots())
m_tree.InsertItem(file.GetFileName(),hChild);
}
GetDriveDir(hChild);
hChild = m_tree.GetNextItem(hChild,TVGN_NEXT);
}
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//函数功能:获取树项目全跟径
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
CString CKill::GetFullPath(HTREEITEM hCurrent)
{
CString strTemp;
CString strReturn = "";
while(hCurrent != m_hRoot)
{
strTemp = m_tree.GetItemText(hCurrent);
if(strTemp.Right(1) != "\\")
strTemp += "\\";
strReturn = strTemp + strReturn;
hCurrent = m_tree.GetParentItem(hCurrent);
}
return strReturn;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//添加子目录
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void CKill::AddSubDir(HTREEITEM hParent)
{
CString strPath = GetFullPath(hParent);
if(strPath.Right(1) != "\\")
strPath += "\\";
strPath += "*.*";
CFileFind file;
BOOL bContinue = file.FindFile(strPath);
while(bContinue)
{
bContinue = file.FindNextFile();
if(file.IsDirectory() && !file.IsDots())
m_tree.InsertItem(file.GetFileName(),hParent);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?