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

📄 processform.cpp

📁 The main idea of this work is to create a driver for hiding selected processes and files.
💻 CPP
字号:
// ProcessForm.cpp : implementation file
//

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

// ProcessForm

IMPLEMENT_DYNCREATE(ProcessForm, CFormView)

ProcessForm::ProcessForm()
	: CFormView(ProcessForm::IDD)
{
}

ProcessForm::~ProcessForm()
{
}

void ProcessForm::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_PROCESS, mListProcess);
}

BEGIN_MESSAGE_MAP(ProcessForm, CFormView)
	ON_NOTIFY(NM_RCLICK, IDC_LIST_PROCESS, OnNMRclickListProcess)
	ON_COMMAND(ID_MENU_ADD, OnMenuAdd)
	ON_COMMAND(ID_MENU_DELEATE, OnMenuDeleate)
//	ON_COMMAND(ID_MENU_CANCEL, OnMenuCancel)
	ON_COMMAND(ID_MENU_DELEATE_ALL, OnMenuDeleateAll)
//	ON_COMMAND(ID_MENU_QUERY, OnMenuQuery)
ON_COMMAND(ID_MENU_QUERY, OnMenuQuery)
END_MESSAGE_MAP()


// ProcessForm diagnostics

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

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


// ProcessForm message handlers

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

	mListProcess.InsertColumn(0,_T("Process name"),LVCFMT_LEFT,100,0);

	DWORD dwExStyle_f=mListProcess.GetExtendedStyle();
	dwExStyle_f= (LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	mListProcess.SetExtendedStyle(dwExStyle_f);
}

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

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

	if(mListProcess.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 ProcessForm::OnMenuAdd()
{
	AddDlg dlg(TYPE_PROCESS);
	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_PROCESS_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 = mListProcess.GetItemCount();
		mListProcess.InsertItem(nIndex,strProcessName);
	}
}

void ProcessForm::OnMenuDeleate()
{
	POSITION pos = mListProcess.GetFirstSelectedItemPosition();
	if (pos == NULL)
		return;
	
	while (pos)
	{
		int nItem = mListProcess.GetNextSelectedItem(pos);
		CString ProcessName = mListProcess.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_PROCESS_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=mListProcess.FindItem(&info)) != -1)
			{
				mListProcess.DeleteItem(nIndex);
			}
		}

	}
}

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

	BOOL res = mDrvWork.Exchange(IOCTL_CLEAR_PROCESS_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
	{
		mListProcess.DeleteAllItems();
	}
}

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

	BOOL res = mDrvWork.Exchange(IOCTL_QUERY_PROCESS_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
	{
		mListProcess.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 = mListProcess.GetItemCount();
			mListProcess.InsertItem(nIndex,ProcessName);
		}
	}
}

⌨️ 快捷键说明

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