-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtf4.cpp
45 lines (43 loc) · 1.39 KB
/
gtf4.cpp
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
#include <Windows.h>
#include <assert.h>
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
constexpr int KeyID = 42;
auto RegisterSuccess = RegisterHotKey(NULL, KeyID, MOD_CONTROL | MOD_ALT, VK_F4);
assert(RegisterSuccess);
MSG Message;
while(GetMessage(&Message, NULL, 0, ~0))
{
if(Message.message == WM_HOTKEY)
{
HWND Window = GetForegroundWindow();
if(!Window)
{
OutputDebugStringA("GetForegroundWindow() failed!\n");
continue;
}
DWORD ProcessID = 0;
GetWindowThreadProcessId(Window, &ProcessID);
if(!ProcessID)
{
OutputDebugStringA("GetWindowThreadProcessId() failed!\n");
continue;
}
HANDLE Process = OpenProcess(PROCESS_TERMINATE, FALSE, ProcessID);
if(!Process)
{
OutputDebugStringA("OpenProcess() failed!\n");
continue;
}
BOOL TerminationSuccess = TerminateProcess(Process, 1);
if(!TerminationSuccess)
{
OutputDebugStringA("TerminateProcess() failed!\n");
continue;
}
}
}
auto UnregisterSuccess = UnregisterHotKey(NULL, KeyID);
assert(UnregisterSuccess);
return 0;
}