Skip to content

Commit

Permalink
bug fix and change the icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun committed May 29, 2017
1 parent 3ef169e commit 225fb63
Show file tree
Hide file tree
Showing 5 changed files with 4,978 additions and 200 deletions.
222 changes: 90 additions & 132 deletions Thread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
interface

uses
Classes, windows, SysUtils, Forms, ActiveX, Variants, ComCtrls, dialogs, Oleacc, iAccessible2Lib_tlb, MSHTML_tlb,
Classes, windows, SysUtils, Forms, ActiveX, Variants, ComCtrls, dialogs, WinAPI.Oleacc, iAccessible2Lib_tlb, MSHTML_tlb,
UIAutomationClient_TLB, ISimpleDOM, IntList;

type
Expand All @@ -17,7 +17,6 @@ TreeThread = class(TThread)
UIEle: IUIAutomationElement;
iID: integer;
procedure ReflexACC(ParentNode: TTreeNode; ParentAcc: iAccessible; iID: integer);
function Get_RoleText(Acc: IAccessible; Child: integer): string;
protected
iAcc, pac, getcAcc, tAcc: IAccessible;
pNode, rNode, sNode, RootNode: TTreeNode;
Expand Down Expand Up @@ -80,36 +79,37 @@ procedure TreeThread.Execute;
begin
GetAcc := procedure
begin
UIAuto.ElementFromIAccessible(iAcc, iID, UIEle);
UIAuto.ElementFromIAccessible(iAcc, iID, UIEle);
end;
try
frmMSAAV.bTer := false;
hr := CoCreateInstance(CLASS_CUIAutomation, nil, CLSCTX_INPROC_SERVER, IID_IUIAutomation, UIAuto);

if (UIAuto = nil) or (hr <> S_OK) then
begin
Exit;
try
CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
frmMSAAV.bTer := false;
hr := CoCreateInstance(CLASS_CUIAutomation, nil, CLSCTX_INPROC_SERVER,
IID_IUIAutomation, UIAuto);

end;
if (UIAuto = nil) or (hr <> S_OK) then
begin
Exit;

CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
try
sNode := nil;
Synchronize(GetAcc);
ReflexACC(RootNode, pac, 0);
end;

except
end;
try
sNode := nil;
Synchronize(GetAcc);
ReflexACC(RootNode, pac, 0);

if Terminated then
begin
frmMSAAV.bTer := True;
snode := nil;
end;
except
end;

finally
CoUninitialize;
if Terminated then
begin
frmMSAAV.bTer := True;
sNode := nil;
end;

finally
CoUninitialize;
end;
end;


Expand All @@ -122,141 +122,99 @@ function VarHaveValue(v: variant): boolean;

end;

function TreeThread.Get_RoleText(Acc: IAccessible; Child: integer): string;
var
PC:PChar;
ovValue, ovChild: OleVariant;
begin
ovChild := Child;
Acc.Get_accRole(ovChild, ovValue);
try

if not VarHaveValue(ovValue) then
begin
Result := None;
end
else
begin
if VarIsNumeric(ovValue) then
begin
PC := StrAlloc(255);
try
GetRoleTextW(ovValue, PC, StrBufSize(PC));
Result := PC;
finally
StrDispose(PC);
end;
end
else if VarIsStr(ovValue) then
begin
Result := VarToStr(ovValue);
end;
end;
except
Result := None;
end;
end;



procedure TreeThread.ReflexACC(ParentNode: TTreeNode; ParentAcc: iAccessible; iID: integer);
var
cAcc, tAcc: iAccessible;
iChild, i, iCH, iSame: integer;
iObtain: plongint;
cNode: TTreeNode;
oc: OleVariant;
iDis: iDispatch;
Role: string;
TD: PTreeData;
Sync, {SName, }SCnt, SCld: TThreadProcedure;
bOK: boolean;
AddTreeItem, {SName, }SCnt, SCld: TThreadProcedure;
Comp1: IUIAutomationElement;
hr: HResult;
aChildren : array of TVariantArg;
begin
if Terminated then Exit;
Sync := procedure
begin
New(TD);
TD^.Acc := cAcc;
TD^.uiEle := nil;
TD^.iID := iCH;
pNode := cNode;
rNode := wndMSAAV.TreeView1.Items.AddChildObject(pNode, '', Pointer(TD));

TBList.Add(Integer(rNode.ItemId));
if sNode = nil then
if Terminated then
Exit;
AddTreeItem := procedure
begin
New(TD);
TD^.Acc := cAcc;
TD^.UIEle := nil;
TD^.iID := iCH;
pNode := cNode;
rNode := wndMSAAV.TreeView1.Items.AddChildObject(pNode, '', Pointer(TD));
TBList.Add(integer(rNode.ItemId));
if sNode = nil then
begin
if SUCCEEDED(UIAuto.ElementFromIAccessible(cAcc, iCH, Comp1)) then
begin
if SUCCEEDED(UIAuto.ElementFromIAccessible(cAcc, iCH, Comp1)) then
UIAuto.CompareElements(UIEle, Comp1, iSame);
if iSame <> 0 then
begin
UIAuto.CompareElements(UIEle, Comp1, iSame);
if iSame <> 0 then
begin
sNode := rnode;
sNode.Expanded := true;
wndMSAAV.TreeView1.SetFocus;
wndMSAAV.TreeView1.TopItem := sNode;
sNode := rNode;
sNode.Expanded := True;
// wndMSAAV.TreeView1.SetFocus;
wndMSAAV.TreeView1.TopItem := sNode;

sNode.Selected := True;
end;
sNode.Selected := True;
end;
end;
end;
end;
end;

{SName := procedure
begin
cAcc.Get_accName(ovChild, ws);
if ws = '' then ws := None;
Role := Get_ROLETExt(cAcc, ovChild);
end; }
SCnt := procedure
begin
cAcc.Get_accChildCount(iChild);
end;

SCnt := procedure
SCld := procedure
var
i: integer;
begin
cAcc.Get_accChildCount(iChild);
SetLength(aChildren, iChild);
for i := 0 to iChild - 1 do
begin
cAcc.Get_accChildCount(iChild);
VariantInit(OleVariant(aChildren[i]));
end;



SCld := procedure
begin
cAcc.Get_accChild(oc, iDis);
tAcc := iDis as IACCESSIBLE;
if tAcc <> nil then
bOK := True;
end;

cNode := ParentNode;
cAcc := ParentAcc;
iCH := iID;
oc := iID;
Synchronize(Sync);


cNode := rNode;

Synchronize(SCnt);

for i := 0 to iChild - 1 do
if AccessibleChildren(cAcc, 0, iChild, @aChildren[0], iObtain) = S_OK then
begin
bOK := False;
if Terminated then Break;
sleep(1);
iDis := nil;
oc := i+1;

tAcc := nil;
Synchronize(SCld);
if bOK then
for i := 0 to integer(iobtain) - 1 do
begin
if Terminated then
Break;
tAcc := nil;
if aChildren[i].vt = VT_DISPATCH then
begin
ReflexACC(cNode, tAcc, 0);
hr := IDispatch(aChildren[i].pdispVal).QueryInterface(IID_IACCESSIBLE, tAcc);
if Assigned(tAcc) and (hr = S_OK) then
begin
ReflexACC(cNode, tAcc, 0);
end;
end
else
else if aChildren[i].vt = VT_I4 then
begin
iCH := aChildren[i].lVal;
Synchronize(AddTreeItem);
end;
end;
end;

iCH := i + 1;
Synchronize(Sync);
end;

cNode := ParentNode;
cAcc := ParentAcc;
iCH := iID;

end;
end;
Synchronize(AddTreeItem);

cNode := rNode;
Synchronize(SCld);
end;

constructor TreeThread4UIA.Create(UIA: IUIAutomation; iEle, pEle: IUIAutomationElement; NoneText: string; CreateSuspended: boolean = True; Reflex: boolean = True; pNode: TTreenode = nil);
Expand Down
Loading

0 comments on commit 225fb63

Please sign in to comment.