processlist.cpp

来自「在驱动下实现进程隐藏,在驱动下实现进程隐藏.」· C++ 代码 · 共 110 行

CPP
110
字号
// ProcessList.cpp : implementation file
//

#include "stdafx.h"
#include "GUI.h"
#include "ProcessList.h"
#include ".\processlist.h"
#include "tlhelp32.h" 

// ProcessList dialog

IMPLEMENT_DYNAMIC(ProcessList, CDialog)
ProcessList::ProcessList(CWnd* pParent /*=NULL*/)
	: CDialog(ProcessList::IDD, pParent)
{
}

ProcessList::~ProcessList()
{
}

void ProcessList::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_USERS, mListProcess);
}


BEGIN_MESSAGE_MAP(ProcessList, CDialog)

	ON_BN_CLICKED(IDC_BUTTON_OK, OnBnClickedButtonOk)
	ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnBnClickedButtonCancel)
END_MESSAGE_MAP()


// ProcessList message handlers

BOOL ProcessList::OnInitDialog()
{
	CDialog::OnInitDialog();
	SetWindowText(_T("Local Processes"));

	mListProcess.InsertColumn(0,_T("Image Name"),LVCFMT_LEFT,100,0);
	mListProcess.InsertColumn(1,_T("PID"),LVCFMT_LEFT,100,1);


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

	GetProcesses();

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void ProcessList::GetProcesses(void)
{
	CString str;
	int nIndex = mListProcess.GetItemCount();

	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,NULL);
	if(hSnapshot == INVALID_HANDLE_VALUE ) 
		return ;

	PROCESSENTRY32 pe = {sizeof(pe)}; 
	BOOL fOK = Process32First(hSnapshot,&pe); // FirstProcess always ignored
	while(Process32Next(hSnapshot,&pe))
	{
		// Process Name
		str.Format(_T("%ws"),pe.szExeFile);
		mListProcess.InsertItem(nIndex,str);
		// Process PID
		str.Format(_T("%d"),pe.th32ProcessID);
		mListProcess.SetItemText(nIndex,1,str);

		++nIndex;
	}
	
}
void ProcessList::OnBnClickedButtonOk()
{
	strProcesses.clear();
	POSITION pos = mListProcess.GetFirstSelectedItemPosition();
	if (pos == NULL)
	{
		CDialog::OnOK();
		return;
	}

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

		PWCHAR str = (PWCHAR)ProcessName.GetString();

		if(!strProcesses.empty())
			strProcesses+=L',';

		strProcesses+=str;
	}
	CDialog::OnOK();
}

void ProcessList::OnBnClickedButtonCancel()
{
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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