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
| #include "resource.h"
#include <Windows.h>
#include <stdio.h>
#include <TlHelp32.h>
HWND hListBox1 = NULL;
HWND hListBox2 = NULL;
HANDLE Snapshot, hProc = NULL;
PROCESSENTRY32 ProcEntry = { 0 };
INT i = 0;
DWORD ExitCode = 0;
INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_CLOSE:
EndDialog(hwndDlg, NULL);
break;
case WM_INITDIALOG:
hListBox1 = GetDlgItem(hwndDlg, IDC_LIST1);
hListBox2 = GetDlgItem(hwndDlg, IDC_LIST2);
break;
case WM_COMMAND:
switch (wParam) {
case IDOK:
if (WM_LBUTTONUP) i += 1;
switch (i) {
case 1:
SendMessage(hListBox1, LB_RESETCONTENT, NULL, NULL);
SendMessage(hListBox2, LB_RESETCONTENT, NULL, NULL);
Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcEntry.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(Snapshot, &ProcEntry)) {
do {
CHAR pID[MAXWORD] = "";
sprintf_s(pID, "%d", ProcEntry.th32ProcessID);
SendMessage(hListBox1, LB_ADDSTRING, NULL, (LPARAM)pID);
CHAR Buffer[MAXWORD] = "";
sprintf_s(Buffer, "%d - %s", ProcEntry.th32ProcessID, ProcEntry.szExeFile);
SendMessage(hListBox2, LB_ADDSTRING, NULL, (LPARAM)Buffer);
} while (Process32Next(Snapshot, &ProcEntry));
/*hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
ThreadEntry.dwSize = sizeof(THREADENTRY32);
do {
if (ThreadEntry.th32OwnerProcessID == dwProcessID)
wprintf(L"ProcessID: %d\nThreadID: %d\n", ThreadEntry.th32OwnerProcessID, ThreadEntry.th32ThreadID);
} while (Thread32Next(hSnapshot, &ThreadEntry));*/
}
i = 0;
break;
default:
break;
}
break;
case IDCANCEL:
INT CurrentIndex = (INT)SendMessage(hListBox1, LB_GETCURSEL, NULL, NULL);
INT TextLen = (INT)SendMessage(hListBox1, LB_GETTEXTLEN, (WPARAM)CurrentIndex, NULL);
TCHAR *TextBuffer = new TCHAR[TextLen + 1];
SendMessage(hListBox1, LB_GETTEXT, (WPARAM)CurrentIndex, (LPARAM)TextBuffer);
INT pID = atoi(TextBuffer);
hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
GetExitCodeProcess(hProc, &ExitCode);
TerminateProcess(hProc, ExitCode);
break;
}
break;
}
return FALSE;
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc, NULL);
return FALSE;
} |