-
Notifications
You must be signed in to change notification settings - Fork 10
/
apputils.h
79 lines (60 loc) · 1.88 KB
/
apputils.h
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
#pragma once
// ABC for monitoring system window creation.
// Post a message to the client window whenever a window is created.
//
class WindowCreationMonitor {
public:
virtual ~WindowCreationMonitor() {}
virtual bool init(HWND wnd, int msgId) = 0;
virtual bool term() = 0;
};
// Window creation monitor that uses SetWinEventHook().
//
class EventHookWindowCreationMonitor : public WindowCreationMonitor, boost::noncopyable {
public:
EventHookWindowCreationMonitor() {}
~EventHookWindowCreationMonitor() { term(); }
bool init(HWND wnd, int msgId);
bool term();
private:
static HWINEVENTHOOK hook;
static HWND wnd;
static int msgId;
static VOID CALLBACK proc(HWINEVENTHOOK hook, DWORD event,
HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime);
};
// Window creation monitor that uses a global hook in a DLL (deprecated).
//
class HookDllWindowCreationMonitor : public WindowCreationMonitor, boost::noncopyable {
private:
typedef bool (*initF)(HWND wnd, int msgId);
typedef bool (*termF)();
public:
HookDllWindowCreationMonitor() : dll(0), dllInitFunc(0), dllTermFunc(0) {}
~HookDllWindowCreationMonitor() { term(); }
bool init(HWND wnd, int msgId);
bool term();
private:
HMODULE dll;
initF dllInitFunc;
termF dllTermFunc;
};
class Options;
// Autopin checking of created windows.
// Remembers the time each window is added, so when checking
// it only processes those that have passed the autopin delay.
//
class PendingWindows {
public:
void add(HWND wnd);
void check(HWND wnd, const Options& opt);
protected:
struct Entry {
HWND wnd;
DWORD time;
Entry(HWND h = 0, DWORD t = 0) : wnd(h), time(t) {}
};
std::vector<Entry> entries;
bool timeToChkWnd(DWORD t, const Options& opt);
bool checkWnd(HWND target, const Options& opt);
};