-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfrmResults.pas
253 lines (222 loc) · 6.48 KB
/
frmResults.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
unit frmResults;
{$MODE Delphi}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, Menus;
type
TResults = class(TForm)
popListData: TPopupMenu;
Savelistdata1: TMenuItem;
TreeView1: TTreeView;
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure Savelistdata1Click(Sender: TObject);
private
procedure GetWinInfoText(wnd: HWND; ParentNode: TTreeNode);
function GetWinInfoClassName(wnd: HWND; ParentNode: TTreeNode): String;
procedure GetWinInfoStyle(wnd: HWND; ParentNode: TTreeNode);
procedure GetWinInfoExtendedStyle(wnd: HWND; ParentNode: TTreeNode);
procedure GetWinInfoPlacement(wnd: HWND; ParentNode: TTreeNode);
procedure GetWinInfoListData(wnd: HWND; ParentNode: TTreeNode);
procedure GetWinInfoChildren(wnd: HWND; ParentNode: TTreeNode);
public
procedure GetWinInfo(wnd: HWND; ParentNode: TTreeNode);
end;
var
Results: TResults;
implementation
uses StyleNames, WindowEnumerator;
{$R *.lfm}
function GetClassNameAsString(wnd: HWND): String;
var
class_name: array [0..100] of Char;
len: Integer;
begin
len := GetClassName(wnd, class_name, 100);
if len > 0 then
Result := class_name
else
Result := '';
end;
procedure TResults.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
if (Assigned(Node) and (Node.Text = '[List Data]')) then
TreeView1.PopupMenu := popListData
else
TreeView1.PopupMenu := nil;
end;
procedure TResults.Savelistdata1Click(Sender: TObject);
var
f: TextFile;
n: TTreeNode;
i: Integer;
function RemoveTag(const s: String): String;
var
pos1: Integer;
begin
pos1 := Pos('=', s);
Result := Copy(s, pos1 + 2, Length(s) - pos1 - 1);
end;
begin
AssignFile(f, 'c:\listdata.csv');
Rewrite(f);
n := TreeView1.Selected;
for i := 0 to n.Count - 1 do
begin
WriteLn(f, i, ';', RemoveTag(n.Items[i].Items[0].Text), ';',
RemoveTag(n.Items[i].Items[1].Text));
end;
CloseFile(f);
end;
procedure TResults.GetWinInfo(wnd: HWND; ParentNode: TTreeNode);
var
class_name: String;
begin
if IsWindow(wnd) then
begin
TreeView1.Items.AddChild(ParentNode, 'Handle = ' + IntToStr(wnd));
GetWinInfoText(wnd, ParentNode);
class_name := GetWinInfoClassName(wnd, ParentNode);
TreeView1.Items.AddChild(ParentNode, 'Parent Handle = ' + IntToStr(GetParent(wnd)));
GetWinInfoStyle(wnd, ParentNode);
GetWinInfoExtendedStyle(wnd, ParentNode);
GetWinInfoPlacement(wnd, ParentNode);
{ CompareText for case-insensitive comparison }
if CompareText(class_name, 'COMBOBOX') = 0 then
begin
GetWinInfoListData(wnd, ParentNode);
end;
GetWinInfoChildren(wnd, ParentNode);
end
else
TreeView1.Items.AddChild(ParentNode, 'Handle = (INVALID HANDLE)');
end;
procedure TResults.GetWinInfoText(wnd: HWND; ParentNode: TTreeNode);
var
len: Integer;
Text: PChar;
begin
len := GetWindowTextLength(wnd) + 1;
GetMem(Text, len);
GetWindowText(wnd, Text, len);
TreeView1.Items.AddChild(ParentNode, 'Caption = ' + Text);
FreeMem(Text);
end;
function TResults.GetWinInfoClassName(wnd: HWND; ParentNode: TTreeNode): String;
begin
Result := GetClassNameAsString(wnd);
TreeView1.Items.AddChild(ParentNode, 'Class name = ' + Result);
end;
procedure TResults.GetWinInfoStyle(wnd: HWND; ParentNode: TTreeNode);
var
style: Integer;
list: TStringList;
node1: TTreeNode;
i: Integer;
begin
style := GetWindowLong(wnd, GWL_STYLE);
list := GetWindowStyleNames(style);
with TreeView1.Items do
begin
node1 := AddChild(ParentNode, 'Style');
AddChild(node1, 'Value = ' + IntToStr(style));
for i := 0 to list.Count - 1 do
AddChild(node1, list[i]);
end;
list.Free();
end;
procedure TResults.GetWinInfoExtendedStyle(wnd: HWND; ParentNode: TTreeNode);
var
style: Integer;
list: TStringList;
node1: TTreeNode;
i: Integer;
begin
style := GetWindowLong(wnd, GWL_EXSTYLE);
list := GetExtendedWindowStyleNames(style);
with TreeView1.Items do
begin
node1 := AddChild(ParentNode, 'Extended Style');
AddChild(node1, 'Value = ' + IntToStr(style));
for i := 0 to list.Count - 1 do
AddChild(node1, list[i]);
end;
list.Free();
end;
procedure TResults.GetWinInfoPlacement(wnd: HWND; ParentNode: TTreeNode);
var
R1, R2: TRect;
node1: TTreeNode;
begin
GetWindowRect(wnd, R1);
Windows.GetClientRect(wnd, R2);
with TreeView1.Items do
begin
node1 := AddChild(ParentNode, 'Placement');
AddChild(node1, 'Left = ' + IntToStr(R1.Left));
AddChild(node1, 'Top = ' + IntToStr(R1.Top));
AddChild(node1, 'Width = ' + IntToStr(R1.Right - R1.Left));
AddChild(node1, 'Height = ' + IntToStr(R1.Bottom - R1.Top));
AddChild(node1, 'ClientWidth = ' + IntToStr(R2.Right));
AddChild(node1, 'ClientHeight = ' + IntToStr(R2.Bottom));
end;
end;
procedure TResults.GetWinInfoListData(wnd: HWND; ParentNode: TTreeNode);
var
i, cbcount: Integer;
node1, node2: TTreeNode;
itemtext: array [0..300] of Char;
begin
with TreeView1.Items do
begin
node1 := AddChild(ParentNode, '[List Data]');
cbcount := SendMessage(wnd, CB_GETCOUNT, 0, 0);
for i := 1 to cbcount do
begin
SendMessage(wnd, CB_GETLBTEXT, i - 1, Longint(@itemtext));
node2 := AddChild(node1, 'Item #' + IntToStr(i));
AddChild(node2, 'Text = ' + itemtext);
AddChild(node2, 'Data = ' + IntToStr(SendMessage(wnd,
CB_GETITEMDATA, i - 1, 0)));
end;
end;
end;
type
TTreeNodeChildConsumer = class
private
ParentNode: TTreeNode;
ChildrenRootNode: TTreeNode;
ChildCount: Integer;
Form: TResults;
public
constructor Create(Form: TResults; ParentNode: TTreeNode);
procedure Consume(wnd: HWND);
end;
constructor TTreeNodeChildConsumer.Create(Form: TResults; ParentNode: TTreeNode);
begin
Self.Form := Form;
Self.ParentNode := ParentNode;
Self.ChildrenRootNode := nil;
Self.ChildCount := 0;
end;
procedure TTreeNodeChildConsumer.Consume(wnd: HWND);
var
node2: TTreeNode;
begin
if not Assigned(ChildrenRootNode) then
ChildrenRootNode := Form.TreeView1.Items.AddChild(ParentNode,
'Children information');
Inc(ChildCount);
node2 := Form.TreeView1.Items.AddChild(ChildrenRootNode, 'Child #' +
IntToStr(ChildCount));
Form.GetWinInfo(Integer(wnd), node2);
end;
procedure TResults.GetWinInfoChildren(wnd: HWND; ParentNode: TTreeNode);
var
consumer: TTreeNodeChildConsumer;
begin
consumer := TTreeNodeChildConsumer.Create(Self, ParentNode);
EnumerateChildWindows(wnd, consumer.Consume);
consumer.Free;
end;
end.