Skip to content

Commit 5ae337d

Browse files
author
maul.esel
committed
change test.ahk to add custom exception handling
1 parent a3ed8fc commit 5ae337d

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

Misc/test.ahk

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,59 @@ ListLines Off
99
#include ..\
1010
#include Main.ahk
1111

12-
;std := ImportTypeLib("C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\StdOle2.Tlb")
13-
;picDisp := ComObjCreate("StdPicture")
12+
try {
13+
;std := ImportTypeLib("C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\StdOle2.Tlb")
14+
;picDisp := ComObjCreate("StdPicture")
1415

15-
;MsgBox % "Return value: " ITL_FormatError(std.StdFunctions.SavePicture("Ptr", ComObjUnwrap(picDisp), "Str", A_Desktop "\test.jpg", "Int")) " - " ErrorLevel " - " A_LastError
16+
;MsgBox % "Return value: " ITL_FormatError(std.StdFunctions.SavePicture("Ptr", ComObjUnwrap(picDisp), "Str", A_Desktop "\test.jpg", "Int")) " - " ErrorLevel " - " A_LastError
1617

17-
UIAutomation := ImportTypeLib(A_WinDir "\System32\UIAutomationCore.dll")
18+
UIAutomation := ImportTypeLib(A_WinDir "\System32\UIAutomationCore.dll")
1819

19-
myArray := UIAutomation.tagRECT[3]
20+
myArray := UIAutomation.tagRECT[3]
2021

21-
struct := myArray[0]
22-
struct.left := 16
22+
struct := myArray[0]
23+
struct.left := 16
2324

24-
rect := struct.Clone()
25-
rect.bottom := 42
26-
struct.top := 9
25+
rect := struct.Clone()
26+
rect.bottom := 42
27+
struct.top := 9
2728

28-
list := "TreeScope:`n"
29-
for field, value in UIAutomation.TreeScope
30-
list .= "`tTreeScope." field " = " value "`n"
31-
list .= "`nOrientationType:`n"
32-
for field, value in UIAutomation.OrientationType
33-
list .= "`tOrientationType." field " = " value "`n"
34-
list .= "`nstruct (tagRECT):`n"
35-
for field, value in struct
36-
list .= "`tstruct." field " = " value "`n"
37-
list .= "`nrect (tagRECT):`n"
38-
for field, value in rect
39-
list .= "`trect." field " = " value "`n"
40-
MsgBox % "Enumeration and structure fields:`n`n" list
29+
list := "TreeScope:`n"
30+
for field, value in UIAutomation.TreeScope
31+
list .= "`tTreeScope." field " = " value "`n"
32+
list .= "`nOrientationType:`n"
33+
for field, value in UIAutomation.OrientationType
34+
list .= "`tOrientationType." field " = " value "`n"
35+
list .= "`nstruct (tagRECT):`n"
36+
for field, value in struct
37+
list .= "`tstruct." field " = " value "`n"
38+
list .= "`nrect (tagRECT):`n"
39+
for field, value in rect
40+
list .= "`trect." field " = " value "`n"
41+
MsgBox % "Enumeration and structure fields:`n`n" list
4142

42-
automation := new UIAutomation.IUIAutomation(new UIAutomation.CUIAutomation())
43+
automation := new UIAutomation.IUIAutomation(new UIAutomation.CUIAutomation())
4344

44-
desktop := new UIAutomation.IUIAutomationElement(automation.GetRootElement())
45+
desktop := new UIAutomation.IUIAutomationElement(automation.GetRootElement())
46+
MsgBox % "The desktop:`n`n" GetElementInfo(desktop) "`n`nClick [OK] and wait 3 seconds."
4547

46-
MsgBox % "The desktop:`n`n" GetElementInfo(desktop) "`n`nClick [OK] and wait 3 seconds."
48+
sleep 3000
4749

48-
sleep 3000
50+
MouseGetPos,,,hwin
4951

50-
MouseGetPos,,,hwin
52+
request := new UIAutomation.IUIAutomationCacheRequest(automation.CreateCacheRequest())
53+
request.TreeScope := UIAutomation.TreeScope.Element|UIAutomation.TreeScope.Children
5154

52-
request := new UIAutomation.IUIAutomationCacheRequest(automation.CreateCacheRequest())
53-
request.TreeScope := UIAutomation.TreeScope.Element|UIAutomation.TreeScope.Children
55+
elem := new UIAutomation.IUIAutomationElement(automation.ElementFromHandleBuildCache(ComObjParameter(0x4000, hwin), request))
56+
MsgBox % "The window under the mouse:`n`n" GetElementInfo(elem)
5457

55-
elem := new UIAutomation.IUIAutomationElement(automation.ElementFromHandleBuildCache(ComObjParameter(0x4000, hwin), request))
56-
MsgBox % "The window under the mouse:`n`n" GetElementInfo(elem)
58+
pt := new UIAutomation.tagPOINT(), pt.x := 400, pt.y := 400
59+
elem2 := automation.ElementFromPoint(pt)
60+
MsgBox % "The element at 400,400:`n`n" GetElementInfo(elem2)
61+
62+
} catch ex {
63+
MsgBox 4112, Exception!, % "An exception occured`n`tin """ ex.What """`n`tin file """ ex.File """`n`tat line " ex.Line "!`n`nMessage: " ex.Message "`n`nDetails: " ex.Extra
64+
}
5765

5866
GetElementInfo(elem)
5967
{

0 commit comments

Comments
 (0)