Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/09/2024 in all areas

  1. In UIA code, an application top window is identified by the window control type being either $UIA_WindowControlTypeId or $UIA_PaneControlTypeId. E.g. the Chrome top window is a Pane control. Thus, not all application top windows can be identified solely through the $UIA_WindowControlTypeId. And the window must be a direct child of the Desktop. UIA code to identify all application top windows: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) ; --- Or condition to find window/control --- ConsoleWrite( "--- Or condition to find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pOrCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_WindowControlTypeId, $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_PaneControlTypeId, $pCondition1 ) $oUIAutomation.CreateOrCondition( $pCondition0, $pCondition1, $pOrCondition1 ) If Not $pOrCondition1 Then Return ConsoleWrite( "$pOrCondition1 ERR" & @CRLF ) ConsoleWrite( "$pOrCondition1 OK" & @CRLF ) ; --- $oUIElement methods --- ConsoleWrite( "--- $oUIElement methods ---" & @CRLF ) Local $pElements ;$oDesktop.FindAll( $TreeScope_Children, $pCondition0, $pElements ) ; Windows only $oDesktop.FindAll( $TreeScope_Children, $pOrCondition1, $pElements ) ; Windows and Panes ConsoleWrite( "$oDesktop.FindAll()" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) Local $oUIElementArray1, $iLength1 ; $pElements is a pointer to an UI Automation element array $oUIElementArray1 = ObjCreateInterFace( $pElements, $sIID_IUIAutomationElementArray, $dtag_IUIAutomationElementArray ) $oUIElementArray1.Length( $iLength1 ) If Not $iLength1 Then Return ConsoleWrite( "$iLength1 = 0 ERR" & @CRLF ) ConsoleWrite( "$iLength1 = " & $iLength1 & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) Local $pElement1, $oElement1 Local $sClassName1, $sLocalizedControlType1, $sName1, $hNativeWindowHandle1 For $i = 0 To $iLength1 - 1 $oUIElementArray1.GetElement( $i, $pElement1 ) $oElement1 = ObjCreateInterface( $pElement1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) $oElement1.GetCurrentPropertyValue( $UIA_ClassNamePropertyId, $sClassName1 ) Switch $sClassName1 Case "Progman", "Shell_TrayWnd" ContinueLoop EndSwitch ConsoleWrite( @CRLF & "$sClassName1 = " & $sClassName1 & @CRLF ) $oElement1.GetCurrentPropertyValue( $UIA_LocalizedControlTypePropertyId, $sLocalizedControlType1 ) ConsoleWrite( "$sLocalizedControlType1 = " & $sLocalizedControlType1 & @CRLF ) $oElement1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName1 ) ConsoleWrite( "$sName1 = " & $sName1 & @CRLF ) $oElement1.GetCurrentPropertyValue( $UIA_NativeWindowHandlePropertyId, $hNativeWindowHandle1 ) ConsoleWrite( "$hNativeWindowHandle1 = " & HWnd( $hNativeWindowHandle1 ) & @CRLF ) Next EndFunc Note the Switch section to exclude windows that are not considered normal windows: Switch $sClassName1 Case "Progman", "Shell_TrayWnd" ContinueLoop EndSwitch Output: $oUIAutomation OK $oDesktop OK --- Code Snippets --- --- Or condition to find window/control --- $pOrCondition1 OK --- $oUIElement methods --- $oDesktop.FindAll() --- Code Snippets --- $iLength1 = 11 --- Code Snippets --- $sClassName1 = SciTEWindow $sLocalizedControlType1 = window $sName1 = D:\Programmering\AutoIt\Temp\UIA related issues\How does UIA Spy identify these windows\tst00.au3 - SciTE $hNativeWindowHandle1 = 0x000000000002056C $sClassName1 = Notepad++ $sLocalizedControlType1 = window $sName1 = D:\Programmering\AutoIt\Temp\UIA related issues\How does UIA Spy identify these windows\tst00.au3 - Notepad++ $hNativeWindowHandle1 = 0x000000000006036A $sClassName1 = Chrome_WidgetWin_1 $sLocalizedControlType1 = pane $sName1 = Kind LarsJ, how does UIA Spy identify these windows? - AutoIt General Help and Support - AutoIt Forums - Microsoft Edge $hNativeWindowHandle1 = 0x00000000000201E4 $sClassName1 = AutoIt v3 GUI $sLocalizedControlType1 = window $sName1 = UIASpy - UI Automation Spy Tool $hNativeWindowHandle1 = 0x000000000005035E $sClassName1 = MozillaWindowClass $sLocalizedControlType1 = window $sName1 = Mozilla Firefox $hNativeWindowHandle1 = 0x00000000000905EE $sClassName1 = Chrome_WidgetWin_1 $sLocalizedControlType1 = pane $sName1 = about:blank - Google Chrome $hNativeWindowHandle1 = 0x000000000001043C $sClassName1 = IEFrame $sLocalizedControlType1 = window $sName1 = Blank Page - Internet Explorer $hNativeWindowHandle1 = 0x0000000000020480 $sClassName1 = CabinetWClass $sLocalizedControlType1 = window $sName1 = How does UIA Spy identify these windows $hNativeWindowHandle1 = 0x0000000000030246 $sClassName1 = CabinetWClass $sLocalizedControlType1 = window $sName1 = UIASpy $hNativeWindowHandle1 = 0x00000000000502B8
    1 point
  2. Nine

    Mouse click plus UDF

    Finally found how to do it ! #include <Constants.au3> #include <WinAPISysWin.au3> #include <WinAPIError.au3> #include <WinAPIConv.au3> _Main () Func _Main () Local $ctrl_handle Run ("notepad.exe") Local $hWnd = WinWaitActive ("[CLASS:Notepad]", "") Local $tPoint = DllStructCreate($tagPOINT) DllStructSetData($tPoint, "X", 500) DllStructSetData($tPoint, "Y", 500) _WinAPI_ScreenToClient ($hWnd, $tPoint) MsgBox (0,"Test",DllStructgetData($tPoint, "X") & "/" & DllStructGetData($tPoint, "Y")) Local $thWnd = $hWnd While True $ctrl_handle = _WinAPI_ChildWindowFromPointEx ($hWnd, $tPOINT) if not $ctrl_handle then MsgBox (0,"Error","Failure in finding the child window") Exit endif if $ctrl_handle = $thWnd then ExitLoop $thWnd = $ctrl_handle Wend MsgBox (0,"Handle", $thWnd) _MouseClickPlus($thWnd, "right", DllStructgetData($tPoint, "X"), DllStructGetData($tPoint, "Y"), 1) $tPoint = 0 EndFunc Func _MouseClickPlus($hWnd, $sButton = 'left', $vX = '', $vY = '', $iClicks = 1) Local $MK_LBUTTON = 0x0001 Local $WM_LBUTTONDOWN = 0x0201 Local $WM_LBUTTONUP = 0x0202 Local $MK_RBUTTON = 0x0002 Local $WM_RBUTTONDOWN = 0x0204 Local $WM_RBUTTONUP = 0x0205 Local $WM_MOUSEMOVE = 0x0200 If $sButton = 'left' Then $Button = $MK_LBUTTON $ButtonDown = $WM_LBUTTONDOWN $ButtonUp = $WM_LBUTTONUP ElseIf $sButton = 'right' Then $Button = $MK_RBUTTON $ButtonDown = $WM_RBUTTONDOWN $ButtonUp = $WM_RBUTTONUP EndIf If $vX = "" Or $vY = "" Then $MouseCoord = MouseGetPos() $vX = $MouseCoord[0] $vY = $MouseCoord[1] EndIf Local $stPoint = _MakeLong($vX, $vY) Local $i = 0 For $i = 1 To $iClicks _PostMessage($hWnd, $WM_MOUSEMOVE, 0, $stPoint) _PostMessage($hWnd, $ButtonDown, $Button, $stPoint) _PostMessage($hWnd, $ButtonUp, $Button, $stPoint) Next EndFunc Func _MakeLong($LoWord,$HiWord) Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF)) EndFunc Func _PostMessage($hWnd, $iMsg, $iwParam, $ilParam) Local $aResult, $err $aResult = DllCall("User32.dll", "bool", "PostMessageA", "hwnd", $hWnd, "int", $iMsg, "int", $iwParam, "int", $ilParam) $err = _WinAPI_GetLastError () if $err or not $aResult[0] then MsgBox (0,"Error","Access denied in post message with error " & $err) Exit endif Return $aResult[0] EndFunc
    1 point
×
×
  • Create New...