-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
WindowEnumerator.pas
45 lines (34 loc) · 911 Bytes
/
WindowEnumerator.pas
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
unit WindowEnumerator;
{$mode Delphi}
interface
uses
Windows;
type
{ An object method that accepts a HWND }
TWndConsumer = procedure(Wnd: HWND) of object;
{ Calls the given consumer for every child window of the given window }
procedure EnumerateChildWindows(Wnd: HWND; Consumer: TWndConsumer);
implementation
type
{ Wrapper structure to hold the object procedure and pass it as a pointer }
PWrapper = ^TWrapper;
TWrapper = record
Consumer: TWndConsumer;
end;
{ Callback for Windows' EnumChildWindows }
function MyEnumChildrenProc(Wnd: HWND; Lp: LPARAM): BOOL; stdcall;
var
Wrapper: PWrapper;
begin
Wrapper := PWrapper(Lp);
Wrapper^.Consumer(Wnd);
Result := True;
end;
procedure EnumerateChildWindows(Wnd: HWND; Consumer: TWndConsumer);
var
Wrapper: TWrapper;
begin
Wrapper.Consumer := Consumer;
EnumChildWindows(Wnd, @MyEnumChildrenProc, LPARAM(@Wrapper));
end;
end.