Leaderboard
Popular Content
Showing content with the highest reputation on 05/08/2019 in all areas
-
Use AutoIt v5.0.0; it has inbuilt AI that codes everything for you automatically, and also googles the latest stable release telepathically. Plus it tells better jokes than Alexa and Siri.3 points
-
This example is about using Microsoft UI Automation APIs in AutoIt. Ie. it's about using interfaces, objects, methods, properties and constants as they are defined directly by Microsoft. In AutoIt, the definitions are contained in CUIAutomation2.au3 by junkew. The definitions are copied from corresponding C/C++ header files and customized the AutoIt language. This example is not about the functions in UIAWrappers.au3 by junkew. The purpose of the example is to show how to use Microsoft UI Automation APIs directly without any intermediate AutoIt functions. A major advantage of this approach is that the Microsoft documentation directly can be used as AutoIt documentation. Other major advantages are that there is no need for documenting and maintaining a set of intermediate AutoIt functions. Without intermediate AutoIt functions the code will be very fast. All Microsoft functions can be used this way eg. functions for event handling. New interfaces, objects, methods, properties and constants can easily be added simply by adding the definitions to CUIAutomation2.au3. Is this approach difficult? Not at all as the examples will show. The example is inspired by this comment of mLipok. Including documentation and pictures, even a simple Notepad automation can be somewhat comprehensive. Therefore a new example. First post will be a list of examples. The examples themselves are reviewed in the following posts. In all examples UIASpy is used to get element information. Topics Using UIASpy UIASpy thread Automating Notepad. Very detailed example. Automating Notepad with Sample code - step by step Automating Notepad with Sample code - all at once Automating Notepad - Windows XP Automating Notepad - Classic Click Save As... issue Automating Notepad context menu. Event handler example. Chrome - Clicking an extension. Compact summary example. Other spy tools Using Microsoft Inspect.exe simplespy.au3 by junkew How to topics If UI Automation or the UIASpy tool is new to you, then you should start reading the How to topics Various topics Console and terminal windows Console application (3 posts) Terminal program (several posts) Examples Patterns (actions) Code snippets Real examples UIA updates UIA events Threads UI Automation UDFs contains all include files. UIASpy - UI Automation Spy Tool is a GUI tool that provides information about windows and controls and their interconnection and provides functionality to generate sample code. UIASpy is essential for creating UI Automation code. UI Automation Events is about implementing event handlers and includes GUIs to detect events. IUIAutomation MS framework automate chrome, FF, IE, .... created by junkew August 2013 is the first AutoIt thread on UIA code. Zip-file The zip contains source files for all examples. Note that UI Automation UDFs must be installed in the Includes folder. You need AutoIt 3.3.12 or later. Tested on Windows XP, Windows 7 and Windows 10. Comments and questions about using UIA code are welcome. Let me know if there are any issues. Questions about the functions in UIAWrappers.au3 should be asked in junkew's thread. UIAExamples.7z1 point
-
No, I want you to explain why you need this as this feels not legitimate to me! Everybody else, please stay out of this part of the conversation... I will separate these posts into its own thread to leave the Example thread open. Jos1 point
-
BatMan22, You don't necessarily have to go through all the controls in the chain from the top window to the target control. You can usually go directly from a window to the target control. In your case with two windows and the target control in the second window, it's usually enough to identify and find three windows/controls: Window: XX XX... Window: ODBC... Table: Grid This code should work: ; --- Find window/control --- ; Application top window ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "OMain", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ; Second window, child window ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "ODBC;DRIVER=SQL Server Native Client 10.0;SERVER=tcp:XXX-SQL\XXX_BACKEND;UID=huan;PWD=;Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=LIMS_BACKEND;", $pCondition2 ) ;$oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_WindowControlTypeId, $pCondition2 ) ; I prefer this rather than a long string If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) Local $pWindow2, $oWindow2 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition2, $pWindow2 ) ; oWindow1 $oWindow2 = ObjCreateInterface( $pWindow2, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oWindow2 ) Then Return ConsoleWrite( "$oWindow2 ERR" & @CRLF ) ConsoleWrite( "$oWindow2 OK" & @CRLF ) ; --- Find window/control --- ; Table control inside the grid, parent of the rows and columns ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition5 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TableControlTypeId, $pCondition5 ) If Not $pCondition5 Then Return ConsoleWrite( "$pCondition5 ERR" & @CRLF ) ConsoleWrite( "$pCondition5 OK" & @CRLF ) Local $pTable1, $oTable1 $oWindow2.FindFirst( $TreeScope_Descendants, $pCondition5, $pTable1 ) ; oWindow2 $oTable1 = ObjCreateInterface( $pTable1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oTable1 ) Then Return ConsoleWrite( "$oTable1 ERR" & @CRLF ) ConsoleWrite( "$oTable1 OK" & @CRLF ) Now for your real problem. If there are two grid controls (or other controls) next to each other and there is no difference in the names, FindFirst will find the first of the two controls. Usually the left control. Controls are usually created from left to right and from top to bottom. If FindFirst finds the wrong one of two controls then it's in any case the other control that's correct. In that situation, you use FindAll instead of FindFirst. FindFirst returns a pointer to the control. FindAll returns an array of pointers to the two controls. In your case, the second pointer with array index 1 is the correct one. The first pointer has array index 0. Replace the code to find the table control with this code: ; --- Find window/control --- ; Table control inside the grid, parent of the rows and columns ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition5 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TableControlTypeId, $pCondition5 ) If Not $pCondition5 Then Return ConsoleWrite( "$pCondition5 ERR" & @CRLF ) ConsoleWrite( "$pCondition5 OK" & @CRLF ) Local $pElements ; $pElements is a pointer to an UI Automation element array $oWindow2.FindAll( $TreeScope_Descendants, $pCondition5, $pElements ) ; oWindow2 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 ) Local $pTable1, $oTable1 $oUIElementArray1.GetElement( 1, $pTable1 ) ; Array index 1 = second table $oTable1 = ObjCreateInterface( $pTable1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oTable1 ) Then Return ConsoleWrite( "$oTable1 ERR" & @CRLF ) ConsoleWrite( "$oTable1 OK" & @CRLF ) Now you can just add the rest of your code (starting with the custom controls). And now it should be the correct grid control. See Code snippets for more information on element arrays.1 point
-
Thanks for your feedback guys I just released a new Hotfix Update of Version 1.09 with the latest fixes. (And updated french language for 1.09 , thx to Swirti) The Working Dir Bug should also be fixed now. @Mbee1 point
-
@Earthshine - I don't think you are appreciating why he wants to do it, and the likely benefits to him at least. Since when do smart people just accept the current status quo? Life is a journey and about pushing boundaries and learning while growing. It's not like he isn't aware of those other options etc.1 point
-
A little bit of googling, and I found GSpread.NET. I have never used it, so I cannot say how good it is. You may be able to use it with the Excel UDF, but I'm not certain. Adam1 point
-
That string needs to be unique per script though. Here is another way to use the _Singleton command. $status = _Singleton("unique-name-here", 1) If $status = 0 Then ; Attempt to retore and activate a non-active or minimized window. If @Compiled = 1 Then $pid = ProcessExists(@ScriptName) $exe = @ScriptName Else $pid = ProcessExists("AutoIt3.exe") $exe = "AutoIt3.exe" EndIf $script = @AutoItPID If $script <> $pid Then $wins = WinList($Scriptname, "") For $w = 1 to $wins[0][0] $handle = $wins[$w][1] If WinGetProcess($handle, "") = $pid Then WinSetState($handle, "", @SW_RESTORE) WinActivate($handle, "") ExitLoop EndIf Next Exit EndIf EndIf or $exist = _Singleton("use-unique-name", 1) If $exist = 0 Then If @Compiled = 1 Then $pid = ProcessExists(@ScriptName) $exe = @ScriptName Else $pid = ProcessExists("AutoIt3.exe") $exe = "AutoIt3.exe" EndIf $script = @AutoItPID $ans = MsgBox(262177, "Close Running Instance Query", _ "This program is already running." & @LF & @LF & _ "Do you want to close it for this new instance?" & @LF & @LF & _ "NOTE - If all work has been saved, then OK" & @LF & _ "could be clicked, else click CANCEL." & @LF & @LF & _ $pid & " (" & $exe & ") " & $script & @LF & @LF & _ "(will default to CANCEL in 30 seconds)", 30) If $ans = 1 Then If $pid <> $script Then ProcessClose($pid) Else MsgBox(262192, "Close Error", "OK process failed!", 0) Exit EndIf ElseIf $ans = 2 Or $ans = -1 Then Exit EndIf EndIf Extracted from a couple of my programs, with slight modification.1 point
-
1 point