Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

AutoItObject and struct tagPoint in method ElementFromPoint

$
0
0
If I have in C++ the definition
ElementFromPoint hresult([in] tagPOINT ;[out] IUIAutomationElement **)

How would this translate to AutoItObject syntax?
"ElementFromPoint hresult(ptr;ptr*);"

Should I use
Global $tStruct = DllStructCreate($tagPOINT) ; Create a structure that defines the point to be checked.
or
Global $tStruct =_AutoItObject_DllStructCreate($tagPoint)
\


trying to get this work based on
http://www.autoitscript.com/forum/topic/128406-interface-autoitobject-iuiautomation/

This part is not working


$aCall = $objUIAutomation.ElementFromPoint($tStruct,0)
consolewrite("convert to object ")

;~ $aCall = $objUIAutomation.GetFocusedElement(0)
$oUIElement = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationElement)
If IsObj($oUIElement) Then
ConsoleWrite("At leastwe have an element " & "[" & getPVal($oUIElement, $UIA_NamePropertyId) & "][" & getPVal($oUIElement, $UIA_ClassNamePropertyId) & "]" & @CRLF)

EndIf


full example

#include <WinAPI.au3>
#include <AutoItObject.au3>
#include "CUIAutomation.au3"

HotKeySet("{ESC}", "Close") ; Set ESC as a hotkey to exit the script.

HotKeySet("^m", "GetElementInfo") ; Set Hotkey Ctrl+M

;~ http://www.autoitscript.com/forum/topic/128406-interface-autoitobject-iuiautomation/
;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ff625914(v=vs.85).aspx

Global $oDesktop ;Desktop will be frequently the starting point

_AutoItObject_StartUp() ;Starting the autoit object library
;~ Global $tStruct = DllStructCreate($tagPOINT) ; Create a structure that defines the point to be checked.
Global $tStruct =_AutoItObject_DllStructCreate($tagPoint)

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc ;==>_ErrFunc

;~ The main object with acces to the windows automation api 3.0
Global $objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
If IsObj($objUIAutomation) Then
ConsoleWrite("At least it seems we have the core object to start with" & @CRLF)
EndIf

;~ Try to get the desktop as a generic reference/global for all samples
$aCall = $objUIAutomation.GetRootElement(0)
$oDesktop = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationElement)
If IsObj($oDesktop) Then
ConsoleWrite("At least it seems I have the desktop as a frequently used starting point" & @CRLF)
EndIf

while True
sleep(100)
WEnd

Func GetElementInfo()
Local $hWnd
local $oUIElement
ToolTip("")
Position() ; Update the X and Y elements with the X and Y co-ordinates of the mouse.
$aCall = $objUIAutomation.ElementFromPoint($tStruct,0)
consolewrite("convert to object ")

;~ $aCall = $objUIAutomation.GetFocusedElement(0)
$oUIElement = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationElement)
If IsObj($oUIElement) Then
ConsoleWrite("At leastwe have an element " & "[" & getPVal($oUIElement, $UIA_NamePropertyId) & "][" & getPVal($oUIElement, $UIA_ClassNamePropertyId) & "]" & @CRLF)

EndIf

EndFunc ;==>Example

Func Position()
$x=MouseGetPos(0)
$y=MouseGetPos(1)
DllStructSetData($tStruct, "x", $x)
DllStructSetData($tStruct, "y", $y)
;~ consolewrite($x & $y)
EndFunc ;==>Position

Func Close()
Exit
EndFunc ;==>Close


;~ Just return a single property or if its an array string them together
func getPVal($obj, $id)
local $tval
local $tStr
local $aCall

$aCall= $obj.GetCurrentPropertyValue($Id,0)
$tVal=$aCall[2]
$tStr=""
if isarray($tVal) Then
for $i=0 to ubound($tval)-1
$tStr=$tStr & $tVal[$i]
if $i <> ubound($tVal)-1 Then
$tStr=$tStr & ";"
endif
Next
;~ consolewrite($id & " is an array")
return $tStr
endIf
return $tVal
EndFunc



Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>