-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Expand file tree
/
Copy pathWindowCreationHandler.cpp
More file actions
60 lines (55 loc) · 1.62 KB
/
WindowCreationHandler.cpp
File metadata and controls
60 lines (55 loc) · 1.62 KB
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
#include "pch.h"
#include "WindowCreationHandler.h"
WindowCreationHandler::WindowCreationHandler(std::function<void(HWND)> windowCreatedCallback) :
m_windowCreatedCallback(windowCreatedCallback)
{
s_instance = this;
InitHooks();
}
WindowCreationHandler::~WindowCreationHandler()
{
m_staticWinEventHooks.erase(std::remove_if(begin(m_staticWinEventHooks),
end(m_staticWinEventHooks),
[](const HWINEVENTHOOK hook) {
return UnhookWinEvent(hook);
}),
end(m_staticWinEventHooks));
}
void WindowCreationHandler::InitHooks()
{
std::array<DWORD, 3> events_to_subscribe = {
EVENT_OBJECT_UNCLOAKED,
EVENT_OBJECT_SHOW,
EVENT_OBJECT_CREATE
};
for (const auto event : events_to_subscribe)
{
auto hook = SetWinEventHook(event, event, nullptr, WinHookProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
if (hook)
{
m_staticWinEventHooks.emplace_back(hook);
}
else
{
Logger::error(L"Failed to initialize win event hooks");
}
}
}
void WindowCreationHandler::HandleWinHookEvent(DWORD event, HWND window) noexcept
{
switch (event)
{
//case EVENT_OBJECT_UNCLOAKED:
//case EVENT_OBJECT_SHOW:
case EVENT_OBJECT_CREATE:
{
if (m_windowCreatedCallback)
{
m_windowCreatedCallback(window);
}
}
break;
default:
break;
}
}