1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
| #include "resource.h"
#include <windows.h>
#include <stdio.h>
#include <Tlhelp32.h> /* process */
HINSTANCE hInstDlg;
HBRUSH hBrush;
/*********************/
void GetProcessList(HWND hwnd)
{
HANDLE hSnapShot;
PROCESSENTRY32 uProcess;
bool r;
char BufferProcess[2048]={0};
memset(BufferProcess, '\0', sizeof(BufferProcess));
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
uProcess.dwSize = (DWORD) sizeof(PROCESSENTRY32);
r = Process32First(hSnapShot, &uProcess);
do {
strcat(BufferProcess, uProcess.szExeFile);
strcat(BufferProcess, "\r\n");
r = Process32Next(hSnapShot, &uProcess);
}while(r);
CloseHandle(hSnapShot);
SetDlgItemText(hwnd, IDC_PROCESS_REPLY, BufferProcess);
}
void KillProcess(char *ExeName)
{
HANDLE hSnapShot;
PROCESSENTRY32 uProcess;
bool r;
short PID = 0;
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
uProcess.dwSize = (DWORD) sizeof(PROCESSENTRY32);
r = Process32First(hSnapShot, &uProcess);
do {
if (strstr(uProcess.szExeFile, ExeName)) {
PID = (short) uProcess.th32ProcessID;
}
r = Process32Next(hSnapShot, &uProcess);
}while(r);
CloseHandle(hSnapShot);
HANDLE hTemp;
hTemp = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
TerminateProcess(hTemp,0);
}
/*********************/
LRESULT CALLBACK MainProc(HWND Dlg,UINT message,WPARAM wParam,LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
hInstDlg = hInstance;
HWND hDlg;
hDlg=CreateDialog(hInstance,(LPCTSTR)IDD_DIALOG1,NULL,(DLGPROC)MainProc);
ShowWindow(hDlg,SW_SHOW);
MSG msg;
while(GetMessage(&msg,NULL,0,0)==TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK MainProc(HWND Dlg,UINT message,WPARAM wParam,LPARAM lParam)
{
int Select;
switch(message)
{
case WM_INITDIALOG:
hBrush = CreateSolidBrush(RGB(0,0,0));
break;
case WM_CTLCOLORDLG:
return (LONG)hBrush;
break;
case WM_CTLCOLORSTATIC:
SetTextColor( (HDC)wParam, RGB(255,0,0) );
SetBkMode( (HDC)wParam, TRANSPARENT );
return (LONG)hBrush;
break;
case WM_CTLCOLOREDIT:
SetTextColor( (HDC)wParam, RGB(0,255,0) );
SetBkMode( (HDC)wParam, TRANSPARENT );
return (LONG)hBrush;
break;
case WM_COMMAND:
Select=LOWORD(wParam);
switch(Select)
{
case IDC_GET_PROCESS_LIST:
GetProcessList(Dlg);
return TRUE;
case IDC_KILL_PROCESS:
char ProcessName[64];
GetDlgItemText(Dlg, IDC_EDIT_KILL_PROCESS, ProcessName, sizeof(ProcessName));
KillProcess(ProcessName);
return TRUE;
case IDCANCEL:
EndDialog(Dlg,Select);
PostQuitMessage(0);
return TRUE;
}
default:
return FALSE;
}
return TRUE;
} |
Partager