-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdlginvestigate.cpp
More file actions
184 lines (166 loc) · 5.07 KB
/
Copy pathdlginvestigate.cpp
File metadata and controls
184 lines (166 loc) · 5.07 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// dlginvestigate.cpp
#include "misc.h"
#include "engine.h"
#include "focus.h"
#include "hook.h"
#include "mayurc.h"
#include "stringtool.h"
#include "target.h"
#include "windowstool.h"
#include "vkeytable.h"
#include "dlginvestigate.h"
#include <iomanip>
#include <cstdint>
///
class DlgInvestigate
{
HWND m_hwnd; ///
UINT m_WM_MAYU_MESSAGE; ///
DlgInvestigateData m_data; ///
public:
///
DlgInvestigate(HWND i_hwnd)
: m_hwnd(i_hwnd),
m_WM_MAYU_MESSAGE(RegisterWindowMessage(
addSessionId(WM_MAYU_MESSAGE_NAME).c_str())) {
m_data.m_engine = NULL;
m_data.m_hwndLog = NULL;
}
/// WM_INITDIALOG
BOOL wmInitDialog(HWND /* i_focus */, LPARAM i_lParam) {
m_data = *reinterpret_cast<DlgInvestigateData *>(i_lParam);
setSmallIcon(m_hwnd, IDI_ICON_mayu);
setBigIcon(m_hwnd, IDI_ICON_mayu);
return TRUE;
}
/// WM_DESTROY
BOOL wmDestroy() {
unsetSmallIcon(m_hwnd);
unsetBigIcon(m_hwnd);
return TRUE;
}
/// WM_CLOSE
BOOL wmClose() {
ShowWindow(m_hwnd, SW_HIDE);
return TRUE;
}
/// WM_COMMAND
BOOL wmCommand(int /* i_notifyCode */, int i_id, HWND /* i_hwndControl */) {
switch (i_id) {
case IDOK: {
ShowWindow(m_hwnd, SW_HIDE);
return TRUE;
}
}
return FALSE;
}
/// WM_focusNotify
BOOL wmFocusNotify(bool i_isFocused, HWND i_hwndFocus) {
if (m_data.m_engine &&
i_hwndFocus == GetDlgItem(m_hwnd, IDC_CUSTOM_scancode))
m_data.m_engine->enableLogMode(i_isFocused);
return TRUE;
}
/// WM_targetNotify
BOOL wmTargetNotify(HWND i_hwndTarget) {
wchar_t className[GANA_MAX_ATOM_LENGTH];
bool ok = false;
if (GetClassName(i_hwndTarget, className, NUMBER_OF(className))) {
if (_wcsicmp(className, L"ConsoleWindowClass") == 0) {
wchar_t titleName[1024];
if (GetWindowText(i_hwndTarget, titleName, NUMBER_OF(titleName)) == 0)
titleName[0] = L'\0';
{
Acquire a(&m_data.m_engine->m_log, LogLevel::Debug);
m_data.m_engine->m_log << L"HWND: " << std::hex
<< static_cast<DWORD>(reinterpret_cast<uintptr_t>(i_hwndTarget))
<< std::dec << std::endl;
}
Acquire a(&m_data.m_engine->m_log, LogLevel::Info);
m_data.m_engine->m_log << L"CLASS: " << className << std::endl;
// same escaping as the hook applies, so that the title reads
// the same whichever path reported it
m_data.m_engine->m_log << L"TITLE: \""
<< escapeControlChars(titleName) << L"\"" << std::endl;
ok = true;
}
}
if (!ok)
CHECK_TRUE( PostMessage(i_hwndTarget, m_WM_MAYU_MESSAGE,
MayuMessage_notifyName, 0) );
return TRUE;
}
/// WM_vkeyNotify
BOOL wmVkeyNotify(int i_nVirtKey, int /* i_repeatCount */,
BYTE /* i_scanCode */, bool i_isExtended,
bool /* i_isAltDown */, bool i_isKeyup) {
Acquire a(&m_data.m_engine->m_log, LogLevel::Info);
m_data.m_engine->m_log
<< (i_isExtended ? L" E-" : L" ")
<< L"0x" << std::hex << std::setw(2) << std::setfill(L'0')
<< i_nVirtKey << std::dec << L" &VK( "
<< (i_isExtended ? L"E-" : L" ")
<< (i_isKeyup ? L"U-" : L"D-");
for (const VKeyTable *vkt = g_vkeyTable; vkt->m_name; ++ vkt) {
if (vkt->m_code == i_nVirtKey) {
m_data.m_engine->m_log << vkt->m_name << L" )" << std::endl;
return TRUE;
}
}
m_data.m_engine->m_log << L"0x" << std::hex << std::setw(2)
<< std::setfill(L'0') << i_nVirtKey << std::dec
<< L" )" << std::endl;
return TRUE;
}
BOOL wmMove(int /* i_x */, int /* i_y */) {
RECT rc1, rc2;
GetWindowRect(m_hwnd, &rc1);
GetWindowRect(m_data.m_hwndLog, &rc2);
MoveWindow(m_data.m_hwndLog, rc1.left, rc1.bottom,
rcWidth(&rc2), rcHeight(&rc2), TRUE);
return TRUE;
}
};
//
INT_PTR CALLBACK dlgInvestigate_dlgProc(HWND i_hwnd, UINT i_message,
WPARAM i_wParam, LPARAM i_lParam)
{
DlgInvestigate *wc;
getUserData(i_hwnd, &wc);
if (!wc)
switch (i_message) {
case WM_INITDIALOG:
wc = setUserData(i_hwnd, new DlgInvestigate(i_hwnd));
return wc->wmInitDialog(reinterpret_cast<HWND>(i_wParam), i_lParam);
}
else
switch (i_message) {
case WM_MOVE:
return wc->wmMove(static_cast<short>(LOWORD(i_lParam)),
static_cast<short>(HIWORD(i_lParam)));
case WM_COMMAND:
return wc->wmCommand(HIWORD(i_wParam), LOWORD(i_wParam),
reinterpret_cast<HWND>(i_lParam));
case WM_CLOSE:
return wc->wmClose();
case WM_DESTROY:
return wc->wmDestroy();
case WM_APP_notifyFocus:
return wc->wmFocusNotify(!!i_wParam,
reinterpret_cast<HWND>(i_lParam));
case WM_APP_targetNotify:
return wc->wmTargetNotify(reinterpret_cast<HWND>(i_lParam));
case WM_APP_notifyVKey:
return wc->wmVkeyNotify(
static_cast<int>(i_wParam), static_cast<int>(i_lParam & 0xffff),
static_cast<BYTE>((i_lParam >> 16) & 0xff),
!!(i_lParam & (1 << 24)),
!!(i_lParam & (1 << 29)),
!!(i_lParam & (1 << 31)));
case WM_NCDESTROY:
delete wc;
return TRUE;
}
return FALSE;
}