This repository has been archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUIAutomation_Extended.au3
587 lines (499 loc) · 31.3 KB
/
UIAutomation_Extended.au3
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
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#cs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name..................: UIAutomation_Extended
Description...........: MS UIAutomation Framework library for AutoIt; extended custom functions
Dependencies..........: UIAutomation environment settings; UIAutomation_Constants.au3; UIAutomation_Core.au3
Documentation.........: https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomation
Author................: [email protected]
Modified..............: 2021-05-11
Version...............: v0.4.7rc
#ce ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include-once
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <UIAutomation_Core.au3>
#include <UIAutomation_Constants.au3>
#Region FUNCTIONS_LIST
#cs ===================================================================================================================================
_UIA_Ext_CreateConditionByPropertyName($_oUIA_Interface, $_sPropertyName, $_sCondition)
_UIA_Ext_FindFirstElementByProperty($_oUIA_Interface, $_oParentElement, $_sPropertyValue, $_iPropertyId = $UIA_AutomationIdPropertyId)
_UIA_Ext_FindFirstElementByNameAndLocalizedControlType($_oUIA_Interface, $_oParentElement, $_sNamePropertyValue, $_sLocalizedControlTypePropertyValue)
_UIA_Ext_SetValue($_oElement, $_sValue)
_UIA_Ext_InvokeElement($_oElement)
_UIA_Ext_ToggleElement($_oElement)
_UIA_Ext_FindWindowByRegexTitle($_oUIA_Interface, $_oRootElement, $_sRegExTitle, $_bFindFirst = True)
_UIA_Ext_FindElementByRegexProperty($_oUIA_Interface, $_oWindowElement, $_sRegexPropertyValue, $_iPropertyId = $UIA_AutomationIdPropertyId, $_bFindFirst = True)
_UIA_Ext_GetControlNameFromId($_iControlId)
_UIA_Ext_GetControlIdFromName($_sControlName)
_UIA_Ext_GetPropertyIdFromName($_sPropertyName)
_UIA_Ext_SetWindowVisualState($_oWindowElement, $_iWindowVisualState = $WindowVisualState_Normal)
_UIA_Ext_CloseWindow($_oWindowElement)
_UIA_Ext_ResizeWindow($_oWindowElement, $_iWidth, $_iHeight)
_UIA_Ext_GetElementCoordinates($_oElement)
_UIA_Ext_MouseClick($_aCoord, $_sButton = "primary", $_iClicks = 1, $_bClickCenter = True, $_iXOffset = 0, $_iYOffset = 0)
_UIA_Ext_GetAllElementPropertyValues($_oElement, $_bOutputArray = True)
_UIA_Ext_DebugScanElements($_oUIA_Interface, $_oBaseElement, $_iTreeScope = $TreeScope_Descendants)
_UIA_Ext_HighlightElement($_oElement)
_UIA_Ext_DrawRectangle($tLeft, $tRight, $tTop, $tBottom, $color = 0xFF, $PenWidth = 3)
#ce ===================================================================================================================================
#EndRegion FUNCTIONS_LIST
#Region UIA_Extended_FUNCTIONS
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_CreateConditionByPropertyName($_oUIA_Interface, $_sPropertyName, $_sCondition)
Description ...: Creates condition object by supplied property name from $__UIA_SupportedPropertiesArray and condition description string
Syntax.........: -
Global vars....: $__UIA_SupportedPropertiesArray
Parameters.....:
Return values..: Success - returns condition object
Failure - returns FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_CreateConditionByPropertyName($_oUIA_Interface, $_sPropertyName, $_sCondition)
If NOT IsObj($_oUIA_Interface) Then Return SetError(100, 0, False)
Local $_iPropertyIndex = _ArrayBinarySearch($__UIA_SupportedPropertiesArray, $_sPropertyName)
If @error Then Return SetError(200+@error, @extended, False)
Local $_sPropertyId = $__UIA_SupportedPropertiesArray[$_iPropertyIndex][0]
Local $_oPropertyCondition = _UIA_CreatePropertyCondition($_oUIA_Interface, $_sPropertyId, $_sCondition)
If @error Then Return SetError(300+@error, @extended, False)
Return $_oPropertyCondition
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_FindFirstElementByProperty($_oUIA_Interface, $_oParentElement, $_sPropertyValue, $_iPropertyId = $UIA_AutomationIdPropertyId)
Description ...: Searches for first found element by value in selected property
Syntax.........: -
Global vars....: $TreeScope_Descendants, $UIA_AutomationIdPropertyId
Parameters.....:
Return values..: Success - returns first found element by property id/value
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_FindFirstElementByProperty($_oUIA_Interface, $_oParentElement, $_sPropertyValue, $_iPropertyId = $UIA_AutomationIdPropertyId)
If NOT ( (IsObj($_oUIA_Interface)) OR (IsObj($_oParentElement)) OR ($_sPropertyValue = "") OR (IsNumber($_iPropertyId)) ) Then Return SetError(100+@error, @extended, False)
Local $_oPropCondition = _UIA_CreatePropertyCondition($_oUIA_Interface, $_iPropertyId, $_sPropertyValue)
If @error Then Return SetError(200+@error, @extended, False)
Local $_oElement = _UIA_FindFirst($_oParentElement, $_oPropCondition, $TreeScope_Descendants)
If @error Then Return SetError(300+@error, @extended, False)
Return $_oElement
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_FindFirstElementByNameAndLocalizedControlType($_oUIA_Interface, $_oParentElement, $_sNamePropertyValue, $_sLocalizedControlTypePropertyValue)
Description ...: Searches for first found element by value in both name and localized control type property
Syntax.........: -
Global vars....: $TreeScope_Descendants, $UIA_NamePropertyId, $UIA_LocalizedControlTypePropertyId
Parameters.....:
Return values..: Success - returns first found element that matches both the name property value and the localized control type property value
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2021-05-11
#ce ===============================================================================================================================
Func _UIA_Ext_FindFirstElementByNameAndLocalizedControlType($_oUIA_Interface, $_oParentElement, $_sNamePropertyValue, $_sLocalizedControlTypePropertyValue)
If NOT ( (IsObj($_oUIA_Interface)) OR (IsObj($_oParentElement)) OR ($_sNamePropertyValue = "") OR ($_sLocalizedControlTypePropertyValue = "") ) Then Return SetError(100+@error, @extended, False)
Local $_oNamePropCondition = _UIA_CreatePropertyCondition($_oUIA_Interface, $UIA_NamePropertyId, $_sNamePropertyValue)
If @error Then Return SetError(200+@error, @extended, False)
Local $_oLocalizedControlTypePropCondition = _UIA_CreatePropertyCondition($_oUIA_Interface, $UIA_LocalizedControlTypePropertyId, $_sLocalizedControlTypePropertyValue)
If @error Then Return SetError(300+@error, @extended, False)
Local $_oPropCondition = _UIA_CreateAndCondition($_oUIA_Interface, $_oNamePropCondition, $_oLocalizedControlTypePropCondition)
If @error Then Return SetError(400+@error, @extended, False)
Local $_oElement = _UIA_FindFirst($_oParentElement, $_oPropCondition, $TreeScope_Descendants)
If @error Then Return SetError(500+@error, @extended, False)
Return $_oElement
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_SetValue($_oElement, $_sValue)
Description ...: Sets element value. If element is window - sets title
Syntax.........: -
Global vars....: $UIA_ControlTypePropertyId, $UIA_LegacyIAccessiblePatternId, $UIA_ValuePatternId
Parameters.....:
Return values..: Success - TRUE
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_SetValue($_oElement, $_sValue)
If NOT (IsObj($_oElement)) Then Return SetError(100+@error, @extended, False)
Local $_sControlType = _UIA_GetCurrentPropertyValue($_oElement, $UIA_ControlTypePropertyId)
If @error Then Return SetError(200+@error, @extended, False)
If ($_scontrolType = $UIA_WindowControlTypeId) Then
;-- if element is window, get handle
Local $_iHWnd = _UIA_CurrentNativeWindowHandle($_oElement)
If @error Then Return SetError(300+@error, @extended+1, False)
WinSetTitle(HWnd($_iHWnd), "", $_sValue)
If @error Then Return SetError(300+@error, @extended+2, False)
Else
_UIA_SetFocus($_oElement)
If @error Then Return SetError(300+@error, @extended+3, False)
Local $_oPattern = _UIA_GetCurrentPattern($_oElement, $UIA_LegacyIAccessiblePatternId)
If NOT IsObj($_oPattern) Then
$_oPattern = _UIA_GetCurrentPattern($_oElement, $UIA_ValuePatternId)
EndIf
If NOT IsObj($_oPattern) Then Return SetError(400+@error, @extended+4, False)
$_oPattern.SetValue($_sValue)
EndIf
Return True
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_InvokeElement($_oElement)
Description ...: Sets Invoke action (pattern) on element if it's available
Syntax.........: -
Global vars....: $UIA_InvokePatternId
Parameters.....:
Return values..: Success - TRUE
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_InvokeElement($_oElement)
If NOT IsObj($_oElement) Then Return SetError(1, 0, False)
Local $_oPattern = _UIA_GetCurrentPattern($_oElement, $UIA_InvokePatternId)
If NOT IsObj($_oPattern) Then Return SetError(2, 0, False)
$_oPattern.Invoke()
Return True
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_ToggleElement($_oElement)
Description ...: Changes the ToggleState of the element if the toggle pattern is available.
Syntax.........: https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtogglepattern-toggle
Global vars....: $UIA_TogglePatternId
Parameters.....:
Return values..: Success - TRUE
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2021.03.25
#ce ===============================================================================================================================
Func _UIA_Ext_ToggleElement($_oElement)
If NOT IsObj($_oElement) Then Return SetError(1, 0, False)
Local $_oPattern = _UIA_GetCurrentPattern($_oElement, $UIA_TogglePatternId)
If NOT IsObj($_oPattern) Then Return SetError(2, 0, False)
$_oPattern.Toggle()
Return True
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_FindWindowByRegexTitle($_oUIA_Interface, $_oRootElement, $_sRegExTitle, $_bFindFirst = True)
Description ...: Searches for window by Regular Expressions title
Syntax.........: -
Global vars....: $TreeScope_Children, $UIA_NamePropertyId
Parameters.....:
Return values..: Success - element object or array of element objects
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_FindWindowByRegexTitle($_oUIA_Interface, $_oRootElement, $_sRegExTitle, $_bFindFirst = True)
If NOT ( (IsObj($_oUIA_Interface)) OR (IsObj($_oRootElement)) OR ($_sRegExTitle="") ) Then Return SetError(100+@error, @extended, False)
Local $_oTRUECondition = _UIA_CreateTrueCondition($_oUIA_Interface)
Local $_oElementArray = _UIA_FindAll($_oRootElement, $_oTRUECondition, $TreeScope_Children)
If @error Then Return SetError(200+@error, @extended, False)
Local $_iLength = 0
$_oElementArray.Length($_iLength)
Local $_oElement, $_sElementName, $_aElementsFound
For $i = 0 To $_iLength-1
$_oElement = _UIA_GetElement($_oElementArray, $i)
$_sElementName = _UIA_GetCurrentPropertyValue($_oElement, $UIA_NamePropertyId)
If StringRegExp($_sElementName, $_sRegExTitle) Then
If $_bFindFirst Then Return $_oElement
Else
_ArrayAdd($_aElementsFound, $_oElement)
EndIf
Next
If Ubound($_aElementsFound) > 0 Then Return $_aElementsFound
Return SetError(300+@error, @extended, False)
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_FindElementByRegexProperty($_oUIA_Interface, $_oWindowElement, $_sRegexPropertyValue, $_iPropertyId = $UIA_AutomationIdPropertyId, $_bFindFirst = True)
Description ...: Searches for element by Regular Expressions value in selected property
Syntax.........: -
Global vars....: $TreeScope_Descendants, $UIA_AutomationIdPropertyId
Parameters.....:
Return values..: Success - element object or array of element objects
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_FindElementByRegexProperty($_oUIA_Interface, $_oWindowElement, $_sRegexPropertyValue, $_iPropertyId = $UIA_AutomationIdPropertyId, $_bFindFirst = True)
If NOT ( (IsObj($_oUIA_Interface)) OR (IsObj($_oWindowElement)) OR ($_sRegexPropertyValue="") OR (IsNumber($_iPropertyId)) ) Then Return SetError(100+@error, @extended, False)
Local $_oTRUECondition = _UIA_CreateTrueCondition($_oUIA_Interface)
Local $_oElementArray = _UIA_FindAll($_oWindowElement, $_oTRUECondition, $TreeScope_Descendants)
If @error Then Return SetError(200+@error, @extended, False)
Local $_iLength = 0
$_oElementArray.Length($_iLength)
Local $_oElement, $_sElementProperty, $_aElementsFound
For $i = 0 To $_iLength-1
$_oElement = _UIA_GetElement($_oElementArray, $i)
If @error Then Return SetError(300+@error, @extended+1, False)
$_sElementProperty = _UIA_GetCurrentPropertyValue($_oElement, $_iPropertyId)
If @error Then Return SetError(300+@error, @extended+2, False)
If StringRegExp($_sElementProperty, $_sRegexPropertyValue) Then
If $_bFindFirst Then Return $_oElement
Else
_ArrayAdd($_aElementsFound, $_oElement)
EndIf
Next
If Ubound($_aElementsFound) > 0 Then Return $_aElementsFound
Return SetError(400+@error, @extended, False)
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_GetControlNameFromId($_iControlId)
Description ...: Gets control type name from $__UIA_ControlArray
Syntax.........: -
Global vars....: $__UIA_ControlArray
Parameters.....:
Return values..: Success - returns control type name
Failure - returns FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_GetControlNameFromId($_iControlId)
If NOT IsNumber($_iControlId) Then Return SetError(100, 0, False)
Local $_index = _ArrayBinarySearch($__UIA_ControlArray, $_iControlId, 0, 0, 1)
If @error Then Return SetError(200+@error, @extended, False)
Return $__UIA_ControlArray[$_index][0]
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_GetControlIdFromName($_sControlName)
Description ...: Gets control type id from $__UIA_ControlArray
Syntax.........: -
Global vars....: $__UIA_ControlArray
Parameters.....:
Return values..: Success - returns control type id
Failure - returns FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_GetControlIdFromName($_sControlName)
If NOT IsString($_sControlName) Then Return SetError(100, 0, False)
Local $_tempString = StringUpper($_sControlName)
If StringLeft($_tempString, 4) <> "UIA_" Then $_tempString = "UIA_" & $_tempString & "Button" & "ControlTypeId" ;-- if string does not start with "UIA_"
If StringRight($_tempString, 7) = "CONTROL" Then $_tempString = $_tempString & "CONTROLTYPEID" ;-- if string ends with "CONTROL"
If StringRight($_tempString, 13) <> "CONTROLTYPEID" Then $_tempString = $_tempString & "CONTROLTYPEID" ;-- if string does not end with "CONTROLTYPEID"
Local $_index = _ArrayBinarySearch($__UIA_ControlArray, $_tempString, 0, 0, 0)
If @error Then Return SetError(200+@error, @extended, False)
Return $__UIA_ControlArray[$_index][1]
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_GetPropertyIdFromName($_sPropertyName)
Description ...: Gets property id from $__UIA_SupportedPropertiesArray
Syntax.........: -
Global vars....: $__UIA_SupportedPropertiesArray
Parameters.....:
Return values..: Success - returns property id
Failure - returns FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_GetPropertyIdFromName($_sPropertyName)
If NOT IsString($_sPropertyName) Then Return SetError(100, 0, False)
Local $_tempString = StringUpper($_sPropertyName)
Local $_index = _ArrayBinarySearch($__UIA_SupportedPropertiesArray, $_tempString, 0, 0, 0)
If @error Then Return SetError(200+@error, @extended, False)
Local $_iPropertyId = $__UIA_SupportedPropertiesArray[$_index][1]
Return $_iPropertyId
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_SetWindowVisualState($_oWindowElement, $_iWindowVisualState = $WindowVisualState_Normal)
Description ...: Sets window state (normal, minimized, maximized) and focuses on it
Syntax.........: -
Global vars....: $UIA_WindowPatternId, $WindowVisualState_Normal
Parameters.....:
Return values..: Success - TRUE
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_SetWindowVisualState($_oWindowElement, $_iWindowVisualState = $WindowVisualState_Normal)
If NOT (IsObj($_oWindowElement)) Then Return SetError(100, 0, False)
Local $_oPattern = _UIA_GetCurrentPattern($_oWindowElement, $UIA_WindowPatternId)
If NOT IsObj($_oPattern) Then Return SetError(200, 0, False)
$_oPattern.SetWindowVisualState($_iWindowVisualState)
_UIA_SetFocus($_oWindowElement)
If @error Then Return SetError(300+@error, @extended, False)
Return True
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_CloseWindow($_oWindowElement)
Description ...: Closes window
Syntax.........: -
Global vars....: $UIA_WindowPatternId
Parameters.....:
Return values..: Success - TRUE
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_CloseWindow($_oWindowElement)
If NOT (IsObj($_oWindowElement)) Then Return SetError(1, 0, False)
Local $_oPattern = _UIA_GetCurrentPattern($_oWindowElement, $UIA_WindowPatternId)
If NOT IsObj($_oPattern) Then Return SetError(2, 0, False)
$_oPattern.Close()
Return True
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_ResizeWindow($_oWindowElement, $_iWidth, $_iHeight)
Description ...: Sets window resolution
Syntax.........: -
Global vars....: $UIA_TransformPatternId
Parameters.....:
Return values..: Success - TRUE
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_ResizeWindow($_oWindowElement, $_iWidth, $_iHeight)
If NOT ( (IsObj($_oWindowElement)) OR (IsNumber($_iWidth)) OR (IsNumber($_iWidth)) ) Then Return SetError(100, 0, False)
Local $_oPattern = _UIA_GetCurrentPattern($_oWindowElement, $UIA_TransformPatternId)
If NOT IsObj($_oPattern) Then Return SetError(200+@error, @extended, False)
$_oPattern.Resize($_iWidth, $_iHeight)
Return True
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_GetAllElementPropertyValues($_oElement, $_bOutputArray = True)
Description ...: Extracts all element properties values available
Syntax.........: -
Global vars....: $__UIA_SupportedPropertiesArray
Parameters.....:
Return values..: Success - returns formatted string or array of element properties values
Failure - returns FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_GetAllElementPropertyValues($_oElement, $_bOutputArray = True)
If NOT IsObj($_oElement) Then Return SetError(1, 0, False)
Local $_sPropertyValue
Local $_sOutputString = @CRLF
Local $_aElementProperties
For $i = 0 To UBound($__UIA_SupportedPropertiesArray) - 1
;-- exclude the special ones:
If $__UIA_SupportedPropertiesArray[$i][1] <> $__UIA_SpecialProperty Then
$_sPropertyValue = _UIA_GetCurrentPropertyValue($_oElement, $__UIA_SupportedPropertiesArray[$i][1])
If @error Then Return SetError(2, 0, False)
If $_sPropertyValue <> "" Then
If $_bOutputArray Then
_ArrayAdd($_aElementProperties, "UIA_" & $__UIA_SupportedPropertiesArray[$i][0] & "|" & $_sPropertyValue)
Else
$_sOutputString = $_sOutputString & @TAB & @TAB & "UIA_" & $__UIA_SupportedPropertiesArray[$i][0] & ":= <" & $_sPropertyValue & ">" & @CRLF
EndIf
EndIf
EndIf
Next
If $_bOutputArray Then Return $_aElementProperties
Return $_sOutputString
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_DebugScanElements($_oUIA_Interface, $_oBaseElement, $_iTreeScope = $TreeScope_Descendants)
Description ...: Scans for element tree and returns formatted string or 2D array. Useful for debugging
Syntax.........: -
Global vars....: $TreeScope_Descendants
Parameters.....:
Return values..: Success - returns formatted string or 2D array of element tree
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_DebugScanElements($_oUIA_Interface, $_oBaseElement, $_iTreeScope = $TreeScope_Descendants)
If NOT ( (IsObj($_oUIA_Interface)) OR (IsObj($_oBaseElement)) OR (IsNumber($_iTreeScope)) ) Then Return SetError(1, 0, False)
Local $_oElement, $_sOutputString, $_sAllProperties
Local $_oTRUECondition = _UIA_CreateTrueCondition($_oUIA_Interface)
If NOT IsObj($_oTRUECondition) Then Return SetError(2, 0, False)
Local $_oElementArray = _UIA_FindAll($_oBaseElement, $_oTRUECondition, $_iTreeScope)
If NOT IsObj($_oElementArray) Then Return SetError(3, 0, False)
Local $_iLength = 0
$_oElementArray.Length($_iLength)
For $i = 0 To $_iLength - 1
$_oElement = _UIA_GetElement($_oElementArray, $i)
$_sAllProperties = _UIA_Ext_GetAllElementPropertyValues($_oElement, False)
$_sOutputString = $_sOutputString & "<elementinfo>" & $_sAllProperties & "</elementinfo>"
ConsoleWrite("["& $i &"] >> " & @TAB & $_sAllProperties & @CRLF)
Next
Return $_sOutputString
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_GetElementCoordinates($_oElement)
Description ...: Retrieves coordinates array for element position
Syntax.........: -
Global vars....: $UIA_BoundingRectanglePropertyId
Parameters.....:
Return values..: Success - returns coordinates array for element position
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_GetElementCoordinates($_oElement)
If NOT (IsObj($_oElement)) Then Return SetError(1, 0, False)
Local $_aCoord = StringSplit(_UIA_GetCurrentPropertyValue($_oElement, $UIA_BoundingRectanglePropertyId), ";")
If NOT IsArray($_aCoord) Then Return SetError(2, 0, False)
Return $_aCoord
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_MouseClick($_aCoord, $_sButton = "primary", $_iClicks = 1, $_bClickCenter = True, $_iXOffset = 0, $_iYOffset = 0)
Description ...: Send mouse clicks to specified coordinates
Syntax.........: -
Global vars....: -
Parameters.....: $_aCoord - use outout from _UIA_Ext_GetElementCoordinates()
Return values..: Success - TRUE
Failure - FALSE, sets @error + @extended
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_MouseClick($_aCoord, $_sButton = "primary", $_iClicks = 1, $_bClickCenter = True, $_iXOffset = 0, $_iYOffset = 0)
If NOT ( (IsArray($_aCoord)) OR ($_sButton="primary") OR ($_sButton="left") OR ($_sButton="right") OR ($_sButton="middle") OR ($_sButton="main") OR ($_sButton="menu") OR ($_sButton="secondary") ) Then Return SetError(100, @extended, False)
Local $x, $y
If $_bClickCenter Then
;-- find center:
$x = Int($_aCoord[1] + ($_aCoord[3] / 2))
$y = Int($_aCoord[2] + $_aCoord[4] / 2)
Else
;-- use provided coordinates with optional offset:
$x = Int($_aCoord[1] + $_iXOffset)
$y = Int($_aCoord[2] + $_iYOffset)
EndIf
MouseMove($x, $y, 1)
MouseClick($_sButton, $x, $y, $_iClicks, 1)
If @error Then Return SetError(200+@error, @extended, False)
Return True
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_HighlightElement($_oElement)
Description ...: Creates visual highlight on element boundaries. Useful for debugging
Syntax.........: -
Global vars....: $UIA_BoundingRectanglePropertyId
Parameters.....:
Return values..: -
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_HighlightElement($_oElement)
Local $_aCoords = StringSplit(_UIA_GetCurrentPropertyValue($_oElement, $UIA_BoundingRectanglePropertyId), ";")
_UIA_Ext_DrawRectangle($_aCoords[1], $_aCoords[3] + $_aCoords[1], $_aCoords[2], $_aCoords[4] + $_aCoords[2])
EndFunc
#cs #FUNCTION# ====================================================================================================================
Name...........: _UIA_Ext_DrawRectangle($tLeft, $tRight, $tTop, $tBottom, $color = 0xFF, $PenWidth = 3)
Description ...: Help function for _UIA_Ext_HighlightElement()
Syntax.........: -
Global vars....: -
Parameters.....:
Return values..: -
Author ........: [email protected]
Modified.......: 2020-01-31
#ce ===============================================================================================================================
Func _UIA_Ext_DrawRectangle($tLeft, $tRight, $tTop, $tBottom, $color = 0xFF, $PenWidth = 3)
Local $hDC, $hPen, $obj_orig, $x1, $x2, $y1, $y2
$x1 = $tLeft
$x2 = $tRight
$y1 = $tTop
$y2 = $tBottom
$hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
$hPen = _WinAPI_CreatePen($PS_SOLID, $PenWidth, $color)
$obj_orig = _WinAPI_SelectObject($hDC, $hPen)
_WinAPI_DrawLine($hDC, $x1, $y1, $x2, $y1) ; horizontal to right
_WinAPI_DrawLine($hDC, $x2, $y1, $x2, $y2) ; vertical down on right
_WinAPI_DrawLine($hDC, $x2, $y2, $x1, $y2) ; horizontal to left right
_WinAPI_DrawLine($hDC, $x1, $y2, $x1, $y1) ; vertical up on left
; refresh desktop (clear drawing)
_WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
; clear resources
_WinAPI_SelectObject($hDC, $obj_orig)
_WinAPI_DeleteObject($hPen)
_WinAPI_ReleaseDC(0, $hDC)
EndFunc
#EndRegion UIA_Extended_FUNCTIONS