forked from ThePacielloGroup/aviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMSAAV.pas
8162 lines (7479 loc) · 271 KB
/
frmMSAAV.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit frmMSAAV;
(*
aViewer is an accessibility API object inspection tool.
Copyright (C) 2014 The Paciello Group
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, System.UITypes, System.Types,
Dialogs, ImgList, ComCtrls, ToolWin, StdCtrls, ShellAPI,
IniFiles, ActnList, CommCtrl, FocusRectWnd, ClipBrd,
ActiveX, MSHTML_tlb, ExtCtrls, Shlobj, WinAPI.oleacc,
iAccessible2Lib_tlb, ISimpleDOM, Actions,
Menus, Thread, TipWnd, UIAutomationClient_TLB, AccCTRLs,
frmSet, Math, IntList, StrUtils, PermonitorApi, Multimon, VirtualTrees,
System.ImageList;
const
IID_IServiceProvider: TGUID = '{6D5140C1-7436-11CE-8034-00AA006009FA}';
P2WDEF = 350;
P4HDEF = 250;
type
PNodeData = ^TNodeData;
TNodeData = record
Value1: String;
Value2: string;
Acc: IAccessible;
iID: integer;
end;
PTreeData = ^TTreeData;
TTreeData = record
Acc: IAccessible;
uiEle: IUIAUTOMATIONELEMENT;
iID: integer;
end;
{PIE = ^FIE;
FIE = record
Iweb: IWebBrowser2;
end; }
PCP = ^TCP;
TCP = record
CP: IConnectionPoint;
Cookie: integer;
end;
PUIA = ^TUIA;
TUIA = record
ID: integer;
PName: string;
Value: OleVariant;
end;
TwndMSAAV = class(TForm, IUIAutomationFocusChangedEventHandler)
ImageList1: TImageList;
ActionList1: TActionList;
acFocus: TAction;
acCursor: TAction;
acRect: TAction;
acCopy: TAction;
acOnlyFocus: TAction;
Timer1: TTimer;
acParent: TAction;
acChild: TAction;
acPrevS: TAction;
acNextS: TAction;
acHelp: TAction;
FontDialog1: TFontDialog;
Panel1: TPanel;
Toolbar1: TAccToolbar;
tbFocus: TToolButton;
tbCursor: TToolButton;
ToolButton3: TToolButton;
tbRectAngle: TToolButton;
ToolButton5: TToolButton;
tbCopy: TToolButton;
ToolButton2: TToolButton;
tbOnlyFocus: TToolButton;
ToolButton1: TToolButton;
tbParent: TToolButton;
tbChild: TToolButton;
tbPrevS: TToolButton;
tbNextS: TToolButton;
ToolButton4: TToolButton;
tbHelp: TToolButton;
acMSAAMode: TAction;
tbMSAAMode: TToolButton;
PopupMenu1: TPopupMenu;
mnuReg: TMenuItem;
mnuUnreg: TMenuItem;
ImageList2: TImageList;
tbRegister: TToolButton;
Splitter1: TSplitter;
Timer2: TTimer;
tbShowTip: TToolButton;
acShowTip: TAction;
MainMenu1: TMainMenu;
mnuView: TMenuItem;
mnuSelD: TMenuItem;
mnuMSAA: TMenuItem;
mnuARIA: TMenuItem;
mnuHTML: TMenuItem;
mnuIA2: TMenuItem;
mnuUIA: TMenuItem;
Panel2: TPanel;
PB1: TAccClrBtn;
Panel4: TPanel;
PB3: TAccClrBtn;
Panel5: TPanel;
Splitter2: TSplitter;
Panel3: TPanel;
PB2: TAccClrBtn;
acTVcol: TAction;
acTLCol: TAction;
acMMCol: TAction;
mnuColl: TMenuItem;
mnuTV: TMenuItem;
mnuTL: TMenuItem;
mnuCode: TMenuItem;
Memo1: TAccMemo;
TreeView1: TAccTreeView;
mnuTVCont: TMenuItem;
mnuTarget: TMenuItem;
mnuAll: TMenuItem;
acSetting: TAction;
mnuBln: TMenuItem;
mnublnMSAA: TMenuItem;
mnublnIA2: TMenuItem;
mnublnCode: TMenuItem;
mnuLang: TMenuItem;
ImageList3: TImageList;
N1: TMenuItem;
mnuTVSave: TMenuItem;
SaveDlg: TSaveDialog;
PopupMenu2: TPopupMenu;
mnuSAll: TMenuItem;
mnuSSel: TMenuItem;
mnuTVSAll: TMenuItem;
mnuTVSSel: TMenuItem;
mnuSave: TMenuItem;
mnuOpenB: TMenuItem;
mnuOAll: TMenuItem;
mnuOSel: TMenuItem;
mnuTVOpen: TMenuItem;
mnuTVOAll: TMenuItem;
mnuTVOSel: TMenuItem;
mnuSelMode: TMenuItem;
TreeList1: TVirtualStringTree;
acTreeFocus: TAction;
acListFocus: TAction;
acMemoFocus: TAction;
acTriFocus: TAction;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure acFocusExecute(Sender: TObject);
procedure acCursorExecute(Sender: TObject);
procedure acCopyExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure acRectExecute(Sender: TObject);
procedure acOnlyFocusExecute(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure acParentExecute(Sender: TObject);
procedure acChildExecute(Sender: TObject);
procedure acPrevSExecute(Sender: TObject);
procedure acNextSExecute(Sender: TObject);
procedure acHelpExecute(Sender: TObject);
procedure Toolbar1Enter(Sender: TObject);
procedure Toolbar1Exit(Sender: TObject);
procedure acMSAAModeExecute(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure TreeList1Change(Sender: TObject; Node: TTreeNode);
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure TreeView1Deletion(Sender: TObject; Node: TTreeNode);
procedure FormDestroy(Sender: TObject);
procedure acShowTipExecute(Sender: TObject);
procedure mnuMSAAClick(Sender: TObject);
procedure acTVcolExecute(Sender: TObject);
procedure acTLColExecute(Sender: TObject);
procedure acMMColExecute(Sender: TObject);
procedure Splitter1Moved(Sender: TObject);
procedure Splitter2Moved(Sender: TObject);
procedure mnuTargetClick(Sender: TObject);
procedure mnuAllClick(Sender: TObject);
procedure acSettingExecute(Sender: TObject);
procedure TreeView1Hint(Sender: TObject; const Node: TTreeNode;
var Hint: string);
procedure TreeList1Deletion(Sender: TObject; Node: TTreeNode);
//procedure TreeView1Addition(Sender: TObject; Node: TTreeNode);
procedure TreeList1Click(Sender: TObject);
procedure TreeList1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure TreeView1Expanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
procedure TreeView1Addition(Sender: TObject; Node: TTreeNode);
procedure PopupMenu2Popup(Sender: TObject);
procedure mnuTVSAllClick(Sender: TObject);
procedure mnuTVSSelClick(Sender: TObject);
procedure mnuSAllClick(Sender: TObject);
procedure mnuSSelClick(Sender: TObject);
procedure mnuTVOAllClick(Sender: TObject);
procedure mnuOAllClick(Sender: TObject);
procedure mnuTVOSelClick(Sender: TObject);
procedure mnuOSelClick(Sender: TObject);
procedure mnuSelModeClick(Sender: TObject);
procedure TreeList1GetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure acTreeFocusExecute(Sender: TObject);
procedure acListFocusExecute(Sender: TObject);
procedure acMemoFocusExecute(Sender: TObject);
procedure acTriFocusExecute(Sender: TObject);
private
{ Private declarations }
HTMLs: array [0..2, 0..1] of string;
HTMLsFF: array [0..2, 0..1] of string;
ARIAs: array [0..1, 0..1] of string;
IA2Sts: array [0..17] of string;
sHTML, sTxt, sTypeIE, sTypeFF, sARIA: string;
bSelMode: Boolean;
iFocus, iRefCnt, ShowSrcLen: integer;
hHook: THandle;
LangList, ClsNames: TStringList;
rType, rTarg: string;
arPT: array [0..2] of TPoint;
lMSAA: array[0..11] of string;
lIA2: array [0..14] of string;
lUIA: array [0..61] of string;
Roles: array [0..42] of string;
StyleID: array [0..16] of string;
oldPT: TPoint;
WndFocus, WndLabel, WndDesc, WndTarg: TwndFocusRect;
WndTip: TfrmTipWnd;
hRgn1, hRgn2, hRgn3: hRgn;
None, ConvErr, HelpURL, DllPath, APPDir, sTrue, sFalse: string;
Created: boolean;
CEle: IHTMLElement;
SDom: ISImpleDOMNode;
UIEle: IUIAutomationElement;
TreeTH: TreeThread;
UIATH: TreeThread4UIA;
Treemode: boolean;
//UIA: IUIAutomation;
P2W, P4H: integer;
flgMSAA, flgIA2, flgUIA, flgUIA2: integer;
TipText, TipTextIA2: string;
sNode: TTreeNode;
pNode: TTreeNode;
sRC: TRect;
hWndTip: THandle;
iDefIndex: integer;
ti: TOOLINFO;
TransPath, SPath, TransDir: string;
UIAuto : IUIAutomation;
iAcc, accRoot, DocAcc: IAccessible;
VarParent: variant;
iMode: integer;
ExTip: boolean;
UIAMode: boolean;
DefFont, DefW, DefH: integer;
ScaleX, ScaleY, DefX, DefY: double;
sMSAAtxt: string;
procedure ExecOnlyFocus;
function MSAAText(pAcc: IAccessible = nil; TextOnly: boolean = false): string;
function MSAAText4UIA(TextOnly: boolean = false): string;
function MSAAText4Tip(pAcc: IAccessible = nil): string;
function MSAAText4HTML(pAcc: IAccessible = nil; tab: string = ''): string;
function IA2Text4HTML(pAcc: IAccessible = nil; tab: string = ''): string;
function HTMLText: string;
function HTMLText4FF: string;
function ARIAText: string;
function SetNodeData(pNode: PVirtualNode; Text1, Text2: string; Acc: iAccessible; iID: integer): PVirtualNode;
function SetIA2Text(pAcc: IAccessible = nil; SetTL: boolean = True): string;
function UIAText: string;
function GetEleName(Acc: IAccessible): string;
procedure SizeChange;
procedure ExecMSAAMode(sender: TObject);
//Thread terminate
procedure ThDone(Sender: TObject);
procedure ReflexID(sID: string; isEle: ISimpleDOMNODE; Labelled: boolean = true);
procedure ShowBalloonTip(Control: TWinControl; Icon: integer; Title: string; Text: string; RC: TRect; X, Y:integer; Track:boolean = false);
procedure SetBalloonPos(X, Y:integer);
procedure ReflexACC(ParentNode: TTreeNode; ParentAcc: IAccessible);
procedure ReflexIA2Rel(pNode: pVirtualNode; ia2: IAccessible2);
function GetSameAcc: boolean;
function IsSameUIElement(ia1, ia2: IAccessible): boolean;
procedure SetTreeMode(pNode: TTreeNode);
function AccIsNull(tAcc: IAccessible): boolean;
function UIAEIsNull(tEle: IUIAutomationelement): boolean;
procedure mnuLangChildClick(Sender: TObject);
procedure ReflexTV(cNode: TTreeNode; var HTML: string; var iCnt: integer; ForSel: boolean = false);
function Get_RoleText(Acc: IAccessible; Child: integer): string;
function GetIA2Role(iRole: integer): string;
function GetIA2State(iRole: integer): string;
procedure ExecCmdLine;
function GetTVAllItems: string;
function GetTVSelItems: string;
procedure WMDPIChanged(var Message: TMessage); message WM_DPICHANGED;
protected
{ Protected declarations }
public
{ Public declarations }
procedure GetNaviState(AllFalse: boolean = false);
procedure Load;
function GetOpeMode(CName: string): integer;
function LoadLang: string;
procedure ShowRectWnd(bkClr: TColor);
procedure ShowRectWnd2(bkClr: TColor; RC:TRect);
procedure ShowLabeledWnd(bkClr: TColor; RC:TRect);
procedure ShowDescWnd(bkClr: TColor; RC:TRect);
procedure ShowTargWnd(bkClr: TColor; RC:TRect);
procedure ShowTipWnd;
function ShowMSAAText:boolean;
procedure ShowText4UIA;
procedure WMCopyData(var Msg: TWMCopyData); Message WM_COPYDATA;
Procedure SetAbsoluteForegroundWindow(HWND: hWnd);
function GetWindowNameLC(Wnd: HWND): string;
function HandleFocusChangedEvent(const sender: IUIAutomationElement): HResult; stdcall;
end;
var
wndMSAAV: TwndMSAAV;
ac: IAccessible;
DMode: boolean;
bTer: boolean;
refNode: TTreeNode;
refVNode: PVirtualNode;
TBList: TIntegerList;
implementation
{$R *.dfm}
function DoubleToInt(d: double): integer;
begin
SetRoundMode(rmUP);
Result := Trunc(SimpleRoundTo(d));
end;
function GetLastErrorStr(ErrorCode: Integer): String;
const
MAX_MES = 512;
var
Buf: PChar;
begin
Buf := AllocMem(MAX_MES);
try
FormatMessage(Format_Message_From_System, Nil, ErrorCode,
(SubLang_Default shl 10) + Lang_Neutral,
Buf, MAX_MES, Nil);
finally
Result := Buf;
FreeMem(Buf);
end;
end;
function IntToBoolStr(i: integer): string;
begin
Result := 'True';
if i = 0 then
Result := 'False';
end;
function TruncPow(i, t:integer): integer;
begin
Result := Trunc(IntPower(i, t));
end;
function IsWinVista: boolean;
var
VI: TOSVersionInfo;
begin
Result := False;
FillChar(VI, SizeOf(VI), 0);
VI.dwOSVersionInfoSize := SizeOf(VI);
if GetVersionEx(VI) then
begin
if (VI.dwMajorVersion >= 6) then
Result := True;
end;
end;
function IsLimited: boolean;
var
hProcess, hToken : THandle;
pt: TTokenElevationType;
dwLength: DWORD;
begin
Result := True;
if not IsWinVista then
begin
Result := False;
Exit;
end;
hProcess := GetCurrentProcess();
if OpenProcessToken(hProcess, TOKEN_QUERY {or TOKEN_QUERY_SOURCE}, hToken) then
begin
if GetTokenInformation(hToken, Windows.TTokenInformationClass(TokenElevationType), @pt, sizeOf(@pt), dwLength) then
begin
if pt <> TokenElevationTypeLimited then
Result := False;
CloseHandle(hToken);
end;
end;
end;
function DeleteCRLF(d: widestring): widestring;
var
s: widestring;
begin
s := StringReplace(d, #10,' ' ,[rfReplaceAll , rfIgnoreCase ]);
s := StringReplace(s, #13,'' ,[rfReplaceAll , rfIgnoreCase ]);
result := s;
end;
function VarHaveValue(v: variant): boolean;
begin
result := true;
if VarType(v) = varEmpty then result := false;
if VarIsEmpty(v) then result := false;
if VarIsClear(v) then result := false;
end;
procedure ShowErr(Msg: string);
begin
if Dmode then
MessageDlg(Msg , mtError, [mbOK], 0);
end;
function Execute(FileName, Param: string; RunAdmin: boolean = false): cardinal;
var
op: string;
begin
if RunAdmin then
op := 'runas'
else
op := 'open';
result := ShellExecute(0, Pchar(op), Pchar(FileName), Pchar(Param), nil, SW_SHOWNORMAL);
end;
function GetMyDocPath: string;
var
IIDList: PItemIDList;
buffer: array [0..MAX_PATH - 1] of char;
begin
IIDList := nil;
Result := '';
if SUCCEEDED(SHGetSpecialFolderLocation(Application.Handle, CSIDL_PERSONAL, IIDList)) then
begin
if not SHGetPathFromIDList(IIDList, buffer) then
begin
raise Exception.Create('A virtual diractory cannot be acquired.');
end
else
Result := StrPas(Buffer);
end;
end;
procedure WinEventProc(hWinEventHook: THandle; event: DWORD; hwnd: HWND;
idObject, idChild: Longint; idEventThread, dwmsEventTime: DWORD); stdcall;
var
vChild: variant;
i:cardinal;
pAcc: IAccessible;
s: string;
iDis: iDispatch;
function SetiAcc: HResult;
begin
result := AccessibleObjectFromEvent(hwnd, idObject, idChild, @pAcc, vChild);
wndMSAAV.UIAuto.GetFocusedElement(wndMSAAV.UIEle);
end;
begin
case event of
EVENT_OBJECT_FOCUS:
begin
try
i := GetWindowLong(hwnd, GWL_HINSTANCE);
if i = hInstance then
begin
exit;
end;
s := wndMSAAV.GetWindowNameLC(hwnd);
wndMSAAV.iMode := wndMSAAV.GetOpeMode(s);
if (not wndMSAAV.acMSAAMode.Checked) then
begin
if (wndMSAAV.acOnlyFOcus.Checked) then
begin
if SUCCEEDED(SetiAcc) then
begin
wndMSAAV.UIAMode := False;
wndMSAAV.varParent := vChild;
wndMSAAV.iAcc := pAcc;
//iDis := pAcc.accParent;
pAcc.Get_accParent(iDis);
wndMSAAV.accRoot := iDis as IAccessible;
wndMSAAV.ShowRectWnd(clYellow);
end;
end
else
begin
if wndMSAAV.iMode <> 2 then
begin
if (wndMSAAV.acFocus.Checked) then
begin
if SUCCEEDED(SetiAcc) then
begin
wndMSAAV.varParent := vChild;
wndMSAAV.iAcc := pAcc;
wndMSAAV.UIAMode := False;
pAcc.Get_accParent(iDis);
wndMSAAV.accRoot := iDis as IAccessible;
if (wndMSAAV.acRect.Checked) then
begin
wndMSAAV.ShowRectWnd(clRed);
end;
wndMSAAV.Timer2.Enabled := false;
wndMSAAV.Timer2.Enabled := True;
end;
end;
end;
end;
end
else
begin
if (wndMSAAV.acFocus.Checked) then
begin
if SUCCEEDED(SetiAcc) then
begin
wndMSAAV.varParent := vChild;
wndMSAAV.iAcc := pAcc;
wndMSAAV.UIAMode := False;
pAcc.Get_accParent(iDis);
wndMSAAV.accRoot := iDis as IAccessible;
if (wndMSAAV.acRect.Checked) then
begin
wndMSAAV.ShowRectWnd(clRed);
end;
wndMSAAV.Timer2.Enabled := false;
wndMSAAV.Timer2.Enabled := True;
end;
end;
end;
except
on E:Exception do
ShowErr(E.Message);
end;
end;
end;
end;
function TwndMSAAV.HandleFocusChangedEvent(const sender: IUIAutomationElement): HResult;
var
Wnd: hwnd;
pInt: Pointer;
i: cardinal;
rc: UIAutomationClient_tlb.tagRECT;
iVW: IUIAutomationTreeWalker;
edgeEle: IUIAutomationElement;
function IsEdge: boolean;
var
FID, CName: widestring;
pEle, cEle: IUIAutomationElement;
iCnt: integer;
begin
(*Name = Microsoft Edge //Top window
┗ClassName=Internet Explorer_Server FID=InternetExplorer //IWebBrowser??
┗FID=InternetExplorer //Element
*)
Result := False;
edgeEle := nil;
cEle := sender;
cEle.Get_CurrentFrameWorkID(FID);
if not (LowerCase(FID) = 'internetexplorer') then
Exit;
for iCnt := 0 to 30 do
begin
cEle.Get_CurrentName(CName);
if LowerCase(CName) = 'microsoft edge' then
begin
Result := True;
edgeEle := cEle;
Break;
end
else
begin
iVW.GetParentElement(cEle, pEle);
cEle := pEle;
if cEle = nil then
Break;
end;
end;
end;
begin
Result := S_OK;
UIAuto.Get_ControlViewWalker(iVW);
if IsEdge and Assigned(edgeEle) then
begin
UIEle := sender;
EdgeEle.Get_CurrentNativeWindowHandle(pInt);
Wnd := HWND(pInt);
i := GetWindowLong(Wnd, GWL_HINSTANCE);
if i = hInstance then exit;
if (not wndMSAAV.acMSAAMode.Checked) then
begin
if (wndMSAAV.acOnlyFOcus.Checked) then
begin
iAcc := nil;
UIAMode := True;
UIEle.Get_CurrentBoundingRectangle(RC);
ShowRectWnd2(clYellow, Rect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top));
end
else
begin
if (wndMSAAV.acFocus.Checked) then
begin
iAcc := nil;
UIAMode := True;
UIEle.Get_CurrentBoundingRectangle(RC);
ShowRectWnd2(clRed, Rect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top));
Timer2.Enabled := false;
Timer2.Enabled := True;
end;
end;
end
else
begin
if (wndMSAAV.acFocus.Checked) then
begin
iAcc := nil;
UIAMode := True;
UIEle.Get_CurrentBoundingRectangle(RC);
ShowRectWnd2(clRed, Rect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top));
Timer2.Enabled := false;
Timer2.Enabled := True;
end;
end;
end;
end;
function TwndMSAAV.Get_RoleText(Acc: IAccessible; Child: integer): string;
var
PC:PChar;
ovValue, ovChild: OleVariant;
begin
ovChild := Child;
//ovValue := Acc.accRole[ovChild];
Acc.Get_accRole(ovChild, ovValue);
Result := None;
try
//if (IDispatch(ovValue) = nil) then
if VarHaveValue(ovValue) then
begin
//GetMem(PC,255);
if VarIsNumeric(ovValue) then
begin
PC := StrAlloc(255);
GetRoleTextW(ovValue, PC, StrBufSize(PC));
Result := PC;
StrDispose(PC);
end
else if VarIsStr(ovValue) then
begin
Result := VarToStr(ovValue);
end;
end;
except
on E:Exception do
ShowErr(E.Message);
end;
end;
function TwndMSAAV.GetIA2Role(iRole: integer): string;
var
PC:PChar;
ovValue: OleVariant;
begin
case iRole of
1025..1067: result := Roles[iRole - 1025];
else
begin
PC := StrAlloc(255);
ovValue := iROle;
GetRoleTextW(ovValue, PC, StrBufSize(PC));
result := PC;
StrDispose(PC);
end;
end;
end;
function TwndMSAAV.GetIA2State(iRole: integer): string;
begin
Result := '';
if (iRole and IA2_STATE_ACTIVE) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[0];
end;
if (iRole and IA2_STATE_ARMED) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[1];
end;
if (iRole and IA2_STATE_DEFUNCT) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[2];
end;
if (iRole and IA2_STATE_EDITABLE) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[3];
end;
if (iRole and IA2_STATE_HORIZONTAL) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[4];
end;
if (iRole and IA2_STATE_ICONIFIED) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[5];
end;
if (iRole and IA2_STATE_INVALID_ENTRY) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[6];
end;
if (iRole and IA2_STATE_MANAGES_DESCENDANTS) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[7];
end;
if (iRole and IA2_STATE_MODAL) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[8];
end;
if (iRole and IA2_STATE_MULTI_LINE) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[9];
end;
if (iRole and IA2_STATE_OPAQUE) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[10];
end;
if (iRole and IA2_STATE_REQUIRED) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[11];
end;
if (iRole and IA2_STATE_SELECTABLE_TEXT) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[12];
end;
if (iRole and IA2_STATE_SINGLE_LINE) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[13];
end;
if (iRole and IA2_STATE_STALE) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[14];
end;
if (iRole and IA2_STATE_SUPPORTS_AUTOCOMPLETION) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[15];
end;
if (iRole and IA2_STATE_TRANSIENT) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[16];
end;
if (iRole and IA2_STATE_VERTICAL) <> 0 then
begin
if Result <> '' then Result := result + ', ';
Result := Result + IA2Sts[17];
end;
end;
Procedure TwndMSAAV.SetAbsoluteForegroundWindow(HWND: hWnd);
var
nTargetID, nForegroundID : Integer;
sp_time: Integer;
begin
nForegroundID := GetWindowThreadProcessId(GetForegroundWindow, nil);
nTargetID := GetWindowThreadProcessId(hWnd, nil );
AttachThreadInput(nTargetID, nForegroundID, TRUE );
SystemParametersInfo( SPI_GETFOREGROUNDLOCKTIMEOUT,0,@sp_time,0);
SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT,0,Pointer(0),0);
Application.ProcessMessages;
SetForegroundWindow(hWnd);
SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT,0,@sp_time,0);
AttachThreadInput(nTargetID, nForegroundID, FALSE );
end;
procedure TwndMSAAV.ExecCmdLine;
var
i: Integer;
d: string;
begin
if ParamCount > 0 then
begin
DMode := False;
for i := 1 to ParamCount do
begin
d := LowerCase(ParamStr(i));
if (d = '-fronly') or (d = '/fronly') then
begin
acOnlyFocus.Checked := True;
tbOnlyFocus.Down := True;
ExecOnlyFocus;
end
else if (d = '-d') or (d = '/d') then
DMode := True;
end;
end;
end;
procedure TwndMSAAV.WMCopyData(var Msg: TWMCopyData);
var
List: TStringList;
i: integer;
d: string;
begin
if msg.CopyDataStruct.dwData=$00000325 then
begin
List := TStringList.Create;
try
SetString(d, PChar(Msg.CopyDataStruct.lpData),
Msg.CopyDataStruct.cbData div SizeOf(Char));
List.CommaText := d;
for i := 0 to List.Count - 1 do
begin
d := LowerCase(List[i]);
if (d = '-fronly') or (d = '/fronly') then
begin
acOnlyFocus.Checked := True;
tbOnlyFocus.Down := True;
ExecOnlyFocus;
end
else if (d = '-d') or (d = '/d') then
DMode := True;
end;
finally
List.Free;
end;
end;
end;
function GetMultiState(State: cardinal): widestring;
var
PC:PChar;
List: TStringList;
i: integer;
begin
List := TStringList.Create;
try
if (State and STATE_SYSTEM_ALERT_HIGH) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_ALERT_HIGH, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_ALERT_MEDIUM) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_ALERT_MEDIUM, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_ALERT_LOW) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_ALERT_LOW, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_ANIMATED) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_ANIMATED, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_BUSY) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_BUSY, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_CHECKED) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_CHECKED, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_COLLAPSED) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_COLLAPSED, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_DEFAULT) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_DEFAULT, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_EXPANDED) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_EXPANDED, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_EXTSELECTABLE) <> 0 then
begin
PC := StrAlloc(255);
GetStateTextW(STATE_SYSTEM_EXTSELECTABLE, PC, StrBufSize(PC));
List.Add(PC);
StrDispose(PC);
end;
if (State and STATE_SYSTEM_FLOATING) <> 0 then