-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlua_quik_resources_utils.pas
More file actions
121 lines (99 loc) · 3.72 KB
/
lua_quik_resources_utils.pas
File metadata and controls
121 lines (99 loc) · 3.72 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
unit lua_quik_resources_utils;
interface
uses windows, messages, sysutils;
function GetModuleName(Module: HMODULE): ansistring;
function GetWindowClassNameStr(hWnd: HWND): ansistring;
function GetWindowTextStr(hWnd: longint): ansistring;
function GetDialogTitleFromResource(aMod: hModule; aParent: HWND; aResId: longint): ansistring;
function GetMenuItemState(hWindow: HWND; idItem: longint): longint;
function get_quik_main_window: HWND;
function get_quik_child_window(hParentWnd: HWND; const acaption: ansistring): HWND;
implementation
const infoclassname = 'InfoClass';
const WM_ENDDUMMYDIALOG = WM_USER + $1000;
type pEnumParams = ^tEnumParams;
tEnumParams = record
pid : THandle;
caption : ansistring;
result : HWND;
end;
function GetModuleName(Module: HMODULE): ansistring;
var ModName: array[0..MAX_PATH] of char;
begin
fillchar(ModName, sizeof(ModName), 0);
SetString(Result, ModName, GetModuleFileName(Module, ModName, SizeOf(ModName)));
end;
function GetWindowClassNameStr(hWnd: HWND): ansistring;
begin setlength(result, 4096); setlength(result, GetClassNameA(hWnd, @result[1], length(result))); end;
function GetWindowTextStr(hWnd: longint): ansistring;
begin setlength(result, 4096); setlength(result, GetWindowTextA(hWnd, @result[1], length(result))); end;
function DummyDlgWindowProc (hWindow: HWND; Msg, wParam: WPARAM; lParam: LPARAM): HRESULT; stdcall;
begin
result:= 0;
if (Msg = WM_INITDIALOG) then EndDialog(hWindow, 0);
end;
function GetDialogTitleFromResource(aMod: HModule; aParent: HWND; aResId: longint): ansistring;
var hDialog: HWND;
begin
hDialog:= CreateDialogParamA(aMod, pAnsiChar(LPARAM(aResId)), aParent, @DummyDlgWindowProc, 0);
if (hDialog <> 0) then begin
result:= GetWindowTextStr(hDialog);
DestroyWindow(hDialog);
end else setlength(result, 0);
end;
function GetMenuItemState(hWindow: HWND; idItem: longint): longint;
var hMnu : HMENU;
i : longint;
begin
result:= -1;
hMnu:= GetMenu(hWindow);
i:= 0;
while (hMnu <> 0) and (result = -1) do begin
hMnu:= GetSubMenu(hMnu, i);
if (hMnu <> 0) then result:= GetMenuState(hMnu, idItem, MF_BYCOMMAND);
inc(i);
end;
end;
function EnumQUIKWindowsCB(hWindow: HWND; lParam: LPARAM): bool; stdcall;
var wnd_pid : THandle;
begin
result:= true;
if (CompareText(infoclassname, GetWindowClassNameStr(hWindow)) = 0) then begin
wnd_pid:= 0;
GetWindowThreadProcessId(hWindow, @wnd_pid);
result:= not ((wnd_pid = pEnumParams(lParam)^.pid) and IsWindowVisible(hWindow));
if not result then pEnumParams(lParam)^.result:= hWindow;
end;
end;
function get_quik_main_window: HWND;
var search_data : tEnumParams;
begin
search_data.pid:= GetCurrentProcessId;
search_data.result:= 0;
EnumChildWindows(HWND_DESKTOP, @EnumQUIKWindowsCB, LPARAM(@search_data));
result:= search_data.result;
end;
function EnumChildWindowsCB(hWindow: HWND; lParam: LPARAM): bool; stdcall;
var wnd_pid : THandle;
begin
if (lParam <> 0) then begin
if (AnsiCompareText(GetWindowTextStr(hWindow), pEnumParams(lParam)^.caption) = 0) then begin
wnd_pid:= 0;
GetWindowThreadProcessId(hWindow, @wnd_pid);
if (wnd_pid = pEnumParams(lParam)^.pid) then begin
pEnumParams(lParam)^.result:= hWindow;
result:= false;
end else result:= true;
end else result:= true;
end else result:= false;
end;
function get_quik_child_window(hParentWnd: HWND; const acaption: ansistring): HWND;
var search_data : tEnumParams;
begin
search_data.pid:= GetCurrentProcessId;
search_data.caption:= acaption;
search_data.result:= 0;
EnumChildWindows(hParentWnd, @EnumChildWindowsCB, LPARAM(@search_data));
result:= search_data.result;
end;
end.