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

📄 fileform.cpp

📁 实现了隐藏进程,使进程对任务管理器和进程查看器均不可见,使文件对资源管理器不可见 是驱动编程入门的好例子
💻 CPP
字号:
// FileForm.cpp : implementation file
//

#include "stdafx.h"
#include "GUI.h"
#include "FileForm.h"
#include "AddDlg.h"


// FileForm

IMPLEMENT_DYNCREATE(FileForm, CFormView)

FileForm::FileForm()
	: CFormView(FileForm::IDD)
{
}

FileForm::~FileForm()
{
}

void FileForm::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_FILE, mListFile);
}

BEGIN_MESSAGE_MAP(FileForm, CFormView)
	ON_NOTIFY(NM_RCLICK, IDC_LIST_FILE, OnNMRclickListFile)
	ON_COMMAND(ID_MENU_DELEATE, OnMenuDeleate)
	ON_COMMAND(ID_MENU_ADD, OnMenuAdd)
	ON_COMMAND(ID_MENU_QUERY, OnMenuQuery)
	ON_COMMAND(ID_MENU_DELEATE_ALL, OnMenuDeleateAll)
END_MESSAGE_MAP()


// FileForm diagnostics

#ifdef _DEBUG
void FileForm::AssertValid() const
{
	CFormView::AssertValid();
}

void FileForm::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG


// FileForm message handlers

void FileForm::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	mListFile.InsertColumn(0,_T("File path"),LVCFMT_LEFT,300,0);
	
	DWORD dwExStyle_f=mListFile.GetExtendedStyle();
	dwExStyle_f= (LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	mListFile.SetExtendedStyle(dwExStyle_f);
}

void FileForm::OnNMRclickListFile(NMHDR *pNMHDR, LRESULT *pResult)
{
	CPoint point; 
	GetCursorPos( &point); 
	CMenu menu;
	menu.LoadMenu(IDR_MENU_LIST);

	POSITION pos = mListFile.GetFirstSelectedItemPosition();
	if(pos == NULL)
		menu.EnableMenuItem(ID_MENU_DELEATE,TRUE);

	if(mListFile.GetItemCount() == 0)
		menu.EnableMenuItem(ID_MENU_DELEATE_ALL,TRUE);

	menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);	

	*pResult = 0;
}

void FileForm::OnMenuAdd()
{
	AddDlg dlg(TYPE_FILE);
	if( dlg.DoModal() != IDOK )
		return;

	CString strProcessName = dlg.mReturnData.Name;

	PWCHAR str = (PWCHAR)strProcessName.GetString();
	DWORD size = strProcessName.GetLength(); 
	WCHAR int_data;
	DWORD BytesReturned;
	size+=1; // Adding size of '\0' symbol
	size*=2; // Take into consideration UNICODE size of character

	BOOL res = mDrvWork.Exchange(IOCTL_ADD_FILE_NAME,
		str,					// Input string 
		size,					// Size of input string
		&int_data,				// Output string
		2 * sizeof(int_data),   // Size of buffer for output string
		&BytesReturned);
	if(!res) 
		AfxMessageBox(_T("Send error"));
	else
	{
		int nIndex = mListFile.GetItemCount();
		mListFile.InsertItem(nIndex,strProcessName);
	}
}

void FileForm::OnMenuDeleate()
{
	POSITION pos = mListFile.GetFirstSelectedItemPosition();
	if (pos == NULL)
		return;

	while (pos)
	{
		int nItem = mListFile.GetNextSelectedItem(pos);
		CString ProcessName = mListFile.GetItemText(nItem,0);

		PWCHAR str = (PWCHAR)ProcessName.GetString();
		WCHAR int_data;
		DWORD BytesReturned;
		DWORD size = ProcessName.GetLength(); 
		size+=1; // Adding size of '\0' symbol
		size*=2; // Take into consideration UNICODE size of character

		BOOL res = mDrvWork.Exchange(IOCTL_DEL_FILE_NAME,
			str,					// Input string 
			size,					// Size of input string
			&int_data,				// Output string
			2 * sizeof(int_data),   // Size of buffer for output string
			&BytesReturned);
		if(!res) 
			AfxMessageBox(_T("Send error"));
		else
		{
			LVFINDINFO info;
			int nIndex;

			info.flags = LVFI_PARTIAL|LVFI_STRING;
			info.psz = ProcessName;

			// Delete all of the items that begin with the string ProcessName.
			while ((nIndex=mListFile.FindItem(&info)) != -1)
			{
				mListFile.DeleteItem(nIndex);
			}
		}

	}
}

void FileForm::OnMenuDeleateAll()
{
	WCHAR Data;
	WCHAR int_data;
	DWORD BytesReturned;

	BOOL res = mDrvWork.Exchange(IOCTL_CLEAR_FILE_NAME,
		&Data,					// Input string 
		2 * sizeof(Data),		// Size of input string
		&int_data,				// Output string
		2 * sizeof(int_data),   // Size of buffer for output string
		&BytesReturned);
	if(!res) 
		AfxMessageBox(_T("Send error"));
	else
	{
		mListFile.DeleteAllItems();
	}
}

void FileForm::OnMenuQuery()
{
	WCHAR Data;
	WCHAR int_data[MAX_PATH];
	DWORD BytesReturned;

	BOOL res = mDrvWork.Exchange(IOCTL_QUERY_FILE_NAME,
		&Data,					// Input string 
		2 * sizeof(Data),		// Size of input string
		int_data,				// Output string
		2 * sizeof(int_data),	// Size of buffer for output string
		&BytesReturned);
	if(!res) 
		AfxMessageBox(_T("Send error"));
	else
	{
		mListFile.DeleteAllItems();

		CString str;
		str.Format(_T("%ws"),int_data);

		int LeftBorder=0;
		int RightBorder=0;
		while(true)
		{
			RightBorder = str.Find(_T("\n"),LeftBorder); 
			if(RightBorder == -1)
				break;

			CString ProcessName = str.Mid(LeftBorder,RightBorder - LeftBorder);
			LeftBorder = RightBorder + 1; 

			int nIndex = mListFile.GetItemCount();
			mListFile.InsertItem(nIndex,ProcessName);
		}
	}
}

⌨️ 快捷键说明

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