DemonMemory/源代码/ChooseProcessDlg.cpp

120 lines
2.6 KiB
C++
Raw Normal View History

2022-04-14 14:09:23 +00:00
// ChooseProcessDlg.cpp : ʵ<><CAB5><EFBFBD>ļ<EFBFBD>
//
#include "stdafx.h"
#include "HandleMemory.h"
#include "ChooseProcessDlg.h"
#include "afxdialogex.h"
// CChooseProcessDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
IMPLEMENT_DYNAMIC(CChooseProcessDlg, CDialogEx)
CChooseProcessDlg::CChooseProcessDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CChooseProcessDlg::IDD, pParent)
{
}
CChooseProcessDlg::~CChooseProcessDlg()
{
}
void CChooseProcessDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_PROCESS, m_ProcessList);
}
BEGIN_MESSAGE_MAP(CChooseProcessDlg, CDialogEx)
ON_BN_CLICKED(IDOK, &CChooseProcessDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CChooseProcessDlg <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BOOL CChooseProcessDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
InitListControl();
return TRUE; // return TRUE unless you set the focus to a control
// <20>쳣: OCX <20><><EFBFBD><EFBFBD>ҳӦ<D2B3><D3A6><EFBFBD><EFBFBD> FALSE
}
void CChooseProcessDlg::OnBnClickedOk()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DWORD dwIndex = m_ProcessList.GetSelectionMark();
if(0 > dwIndex)
{
::MessageBox(m_hWnd, "Please Choose a Item!", "Warn", MB_OK | MB_ICONWARNING);
return ;
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
m_ProcessList.GetItemText(dwIndex, 0, m_szProcessName, MAX_PATH);
// <20><>ȡPID
char szTemp[MAX_PATH] = {0};
m_ProcessList.GetItemText(dwIndex, 1, szTemp, MAX_PATH);
m_dwID = atoi(szTemp);
CDialogEx::OnOK();
}
DWORD CChooseProcessDlg::GetProcessID()
{
return m_dwID;
}
char *CChooseProcessDlg::GetProcessName()
{
return m_szProcessName;
}
BOOL CChooseProcessDlg::InitListControl()
{
// <20><>ʼ<EFBFBD><CABC><EFBFBD>б<EFBFBD><D0B1>ؼ<EFBFBD>
m_ProcessList.InsertColumn(0, "Name", 0, 180);
m_ProcessList.InsertColumn(1, "PID", 0, 60);
m_ProcessList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
m_ProcessList.SetTextColor(RGB(0,100,0));
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
GetProcessInfo();
return TRUE;
}
BOOL CChooseProcessDlg::GetProcessInfo()
{
m_ProcessList.DeleteAllItems();
PROCESSENTRY32 pe32 = {0};
pe32.dwSize = sizeof(PROCESSENTRY32);
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(INVALID_HANDLE_VALUE == hProcessSnap)
{
::MessageBox(NULL, "Create Process Snapshot Error!", "Error", MB_OK);
return FALSE;
}
BOOL bMore = ::Process32First(hProcessSnap, &pe32);
DWORD dwIndex = 0;
char szTemp[MAX_PATH] = {0};
while(bMore)
{
::wsprintf(szTemp, "%s", pe32.szExeFile);
m_ProcessList.InsertItem(dwIndex, szTemp);
::wsprintf(szTemp, "%d", pe32.th32ProcessID);
m_ProcessList.SetItemText(dwIndex, 1, szTemp);
bMore = ::Process32Next(hProcessSnap, &pe32);
}
return TRUE;
}