-
Notifications
You must be signed in to change notification settings - Fork 5
/
FormSearch.cpp
134 lines (120 loc) · 3.76 KB
/
FormSearch.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
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
#include "GameAPI.h"
#include "GameForms.h"
#include "GameData.h"
#include "GeckUtility.h"
#include <CommCtrl.h>
extern HWND g_MainHwnd;
namespace FormSearch
{
constexpr int IDD_INPUTDIALOG = 101;
constexpr int IDC_INPUTEDIT = 1001;
bool DoLookupForm(HWND hwndDlg)
{
char formName[256];
GetDlgItemText(hwndDlg, IDC_INPUTEDIT, formName, sizeof(formName));
if (*formName)
{
auto form = LookupFormByName(formName);
if (!form)
{
char* endPtr = nullptr;
if (int formID = strtoul(formName, &endPtr, 16); endPtr && !*endPtr)
{
form = LookupFormByID(formID);
}
}
if (form)
{
OpenForm(form, g_MainHwnd);
}
else
{
return false;
}
}
return true;
}
WNDPROC originalEditProc;
LRESULT CALLBACK InputEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_KEYDOWN)
{
if (wParam == VK_RETURN)
{
auto parent = GetParent(hwnd);
if (DoLookupForm(parent))
{
EndDialog(parent, IDOK);
return TRUE;
}
return FALSE;
}
else if (wParam == VK_ESCAPE)
{
EndDialog(GetParent(hwnd), IDCANCEL);
return TRUE;
}
else if (wParam == 'A' && GetKeyState(VK_CONTROL) < 0)
{
// Select All
SendMessage(hwnd, EM_SETSEL, 0, -1);
return TRUE;
}
}
return CallWindowProc(originalEditProc, hwnd, msg, wParam, lParam);
}
BOOL CALLBACK InputDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_COMMAND)
{
switch (LOWORD(wParam))
{
case IDOK:
{
if (DoLookupForm(hwndDlg))
{
DestroyWindow(hwndDlg);
}
return TRUE;
}
case IDCANCEL:
{
DestroyWindow(hwndDlg);
return TRUE;
}
}
}
return FALSE;
}
void ShowInputDialog(HINSTANCE hInstance, HWND hwndParent) {
// Create the dialog window
HWND hwndDlg = CreateWindowEx(WS_EX_DLGMODALFRAME,
WC_DIALOG, "Lookup Form",
WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, 200, 100,
hwndParent, NULL, hInstance, NULL);
HWND hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL,
10, 10, 180, 20,
hwndDlg, (HMENU)IDC_INPUTEDIT, hInstance, NULL);
HWND hwndOK = CreateWindowEx(0, "BUTTON", "OK",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
50, 40, 50, 20,
hwndDlg, (HMENU)IDOK, hInstance, NULL);
HWND hwndCancel = CreateWindowEx(0, "BUTTON", "Cancel",
WS_CHILD | WS_VISIBLE,
110, 40, 50, 20,
hwndDlg, (HMENU)IDCANCEL, hInstance, NULL);
SetWindowLongPtr(hwndDlg, DWLP_DLGPROC, (LONG_PTR)InputDialogProc);
originalEditProc = (WNDPROC)SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)InputEditSubclassProc);
// Set focus to the edit control
SetFocus(hwndEdit);
// Show the dialog window
ShowWindow(hwndDlg, SW_SHOW);
}
void Show()
{
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(nullptr);
ShowInputDialog(hInstance, g_MainHwnd);
}
}