mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 12:11:09 +01:00
51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
#pragma once
|
|
#include <Windows.h>
|
|
|
|
/*
|
|
win_hook_event - Windows Event Hook
|
|
|
|
The PowerToys runner installs event hook functions for a range of events. See
|
|
https://docs.microsoft.com/pl-pl/windows/win32/api/winuser/nf-winuser-setwineventhook
|
|
for details.
|
|
|
|
The intptr_t data event argument is a pointer to the WinHookEvent struct.
|
|
|
|
The return value of the event handler is ignored.
|
|
|
|
Example usage, that detects a window being resized:
|
|
|
|
virtual intptr_t signal_event(const wchar_t* name, intptr_t data) override {
|
|
if (wcscmp(name, win_hook_event) == 0) {
|
|
auto& event = *(reinterpret_cast<WinHookEvent*>(data));
|
|
switch (event.event) {
|
|
case EVENT_SYSTEM_MOVESIZESTART:
|
|
size_start(event.hwnd);
|
|
break;
|
|
case EVENT_SYSTEM_MOVESIZEEND:
|
|
size_end(event.hwnd);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
Taking too long to process the events has negative impact on the whole system
|
|
performance. To address this, the events are signaled from a different
|
|
thread, not from the event hook callback itself.
|
|
*/
|
|
|
|
namespace {
|
|
const wchar_t* win_hook_event = L"win_hook_event";
|
|
}
|
|
|
|
struct WinHookEvent {
|
|
DWORD event;
|
|
HWND hwnd;
|
|
LONG idObject;
|
|
LONG idChild;
|
|
DWORD idEventThread;
|
|
DWORD dwmsEventTime;
|
|
};
|