Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/17/2019 in all areas

  1. pixelsearch

    CSV file editor

    Hi everybody The script below (901f) allows to wander easily through a listview, selecting any item or subitem by using the 4 direction keys. The Enter key is also managed and allows to fire an event (as double-click does) With the help of mikell (many thanks !) and after several tests based on 1000 rows & 6 columns, we succeeded to code a clear WM_NOTIFY function, which is simple (though solid) and should be reusable without any modification in other scripts dealing with basic listviews (we didn't use or check any particular style for the listview) Trapping the Enter key has been done by using a dummy control + Accelerators, though we spent the whole last week trapping it in another way, using Yashied's Wsp.dll (without any problem) . Finally we choosed the dummy control option... to have a smaller code. Version 901f (Nov 11, 2019) : the pic below shows how the selected subitem appears, with its specific background colour (light blue) Version 901f code : #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPIvkeysConstants.au3> Global $hGUI = GUICreate("Wandering through ListView (901f)", 460, 500) Global $idListView = GUICtrlCreateListView _ (" Col 0 | Col 1| Col 2| Col 3", 15, 60, 430, 400) Global $hListView = GuiCtrlGetHandle($idListView) For $iRow = 0 To 99 $sRow = StringFormat("%2s", $iRow) GUICtrlCreateListViewItem( _ "Row " & $sRow & " / Col 0 |" & _ "Row " & $sRow & " / Col 1 |" & _ "Row " & $sRow & " / Col 2 |" & _ "Row " & $sRow & " / Col 3", $idListView) Next Global $g_iColumnCount = _GUICtrlListView_GetColumnCount($idListView) -1 Global $g_iItem = -1, $g_iSubItem = -1 ; item/subitem selected in ListView control Global $idDummy_Dbl_Click = GUICtrlCreateDummy() Global $idDummy_Enter = GUICtrlCreateDummy() Global $aAccelKeys[1][2] = [["{ENTER}", $idDummy_Enter]] GUISetAccelerators($aAccelKeys) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Case $idDummy_Dbl_Click MsgBox($MB_TOPMOST, "Double-click activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) Case $idDummy_Enter If _WinAPI_GetFocus() = $hListView And $g_iItem > -1 Then MsgBox($MB_TOPMOST, "Enter activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) EndIf EndSwitch WEnd ;============================================ Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Static $bMouseDown = False, $bNotXP = Not (@OSVersion = "WIN_XP") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iColor = 0xFF000000 ; this is $CLR_DEFAULT in ColorConstants.au3 If $iItem = $g_iItem And $iSubItem = $g_iSubItem Then $iColor = 0xFFFFC0 ; light blue for 1 subitem (BGR) EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) Return $CDRF_NEWFONT Case $LVN_KEYDOWN If $bMouseDown Or $g_iItem = -1 Then Return 1 ; don't process Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) Local $iVK = DllStructGetData($tInfo, "VKey") Switch $iVK Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_SPACE ; spacebar would select the whole row Return 1 EndSwitch Case $NM_RELEASEDCAPTURE $bMouseDown = True Local $iItemSave = $g_iItem Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) $g_iItem = $aHit[0] $g_iSubItem = $aHit[1] If $g_iItem = -1 And $iItemSave > -1 Then _GUICtrlListView_RedrawItems($hListview, $iItemSave, $iItemSave) EndIf Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case BitOr($LVIS_FOCUSED, $LVIS_SELECTED) $g_iItem = DllStructGetData($tInfo, "Item") _GUICtrlListView_SetItemSelected($hListview, $g_iItem, False) EndSwitch Case $NM_CLICK, $NM_RCLICK $bMouseDown = False Case $NM_DBLCLK $bMouseDown = False If $g_iItem > -1 Then GUICtrlSendToDummy($idDummy_Dbl_Click) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Version 901k (Dec 16, 2019) What started with a simple "wander through listview" has turned now to a functional CSV file editor, which can be useful to modify your CSV files with AutoIt : Here are the instructions to use the script, based on a CSV file starting like this : street,city,zip,state,beds,baths,sq__ft,type,sale_date,price,latitude,longitude 3526 HIGH ST,SACRAMENTO,95838,CA,2,1,836,Residential,Wed May 21 00:00:00 EDT 2008,59222,38.631913,-121.434879 51 OMAHA CT,SACRAMENTO,95823,CA,3,1,1167,Residential,Wed May 21 00:00:00 EDT 2008,68212,38.478902,-121.431028 ... 1) Import options : comma delimited (default) No need to change anything if your CSV is comma delimited (other options are Semicolon delimited, Tab delimited) 2) Import options : First row = headers (default = checked) * Keep it checked if the 1st row of your imported file contains headers (that's the case in our example) * UNcheck it if the 1st row contains data, making listview headers appear like this : Col 0 | Col 1 | Col 2 ... 3) Import your CSV file : Only now the listview will be created dynamically. As soon as it is populated, GUI becomes resizable/maximizable, which can be helpful during modifications of a listview containing many columns. 4) Selection color : light blue (default) You can change the selected cell background color by clicking the "Selection color" button : this will open Windows color picker. 5) Editing a listview cell : done by Enter key (or double-click), this is how the edited cell will appear : * Please note that the edited background color (green in the pic) depends on each computer theme. It is not related to the selected background we discussed in 4) * Validate your modification with Enter key, or cancel the modification (revert) with Escape Key 6) Edit Font size : 15 (default) 15 was good in the precedent pic, the edited cell had its content "RIO LINDA" perfectly aligned with all other cells (on my computer). Here again, the font height required depends on each computer : if you want the edited font to be bigger (or smaller), just use the updown control. 7) Chained Edit ? (default = No) * "No" => when you finish editing a cell (Enter key), the same cell stays selected. * "Horizontally" => If checked, edition will automatically continue with the cell on its right. * "Vertically" => If checked, edition will automatically continue with the cell below. This feature can be very useful when you modify cells of a whole colum (vertically) or cells by row (horizontally) 8 ) Inserting a blank line (not in Gui) : press the "Ins" key : 9) Deleting a line (not in Gui) : press the "Del" key : 10) Export CSV file : Filename automatically suggested for export will be : Filename import & actual date & actual time, for example : Import name = "Sales Results.csv" => suggested Export name = "Sales Results_2019-12-16 16:00:59.csv" Version 901m (Dec 18, 2019) Yesterday, mikell suggested to import the csv file by dropping it directly into the GUI, good idea This new version 901m allows it. Now there are 2 ways to import the csv file : * Import button * Drag and drop into the large droppable zone, as shown in the pic below (this zone will be reused to create the listview at same coords) Version 901n (Dec 20, 2019) As t0nZ got tons of csv files, pipe "|" separated, here is a new version allowing this 4th separator Version 901p (Dec 25, 2019) New functionality : now you can drag headers to reorder columns. It may help some users who need it while editing their file. Exported CSV file will be saved according to the new columns order. Version 901r (Dec 29, 2019) New functionality : Numeric sort on any column (right click on column header) It is recommended to backup (export) your file before sorting, just in case you need a copy of it, unsorted. Version 901s (Dec 30, 2019) 1 functionality added : String sort (right click on column header) Numeric sort is alright in most cases, but sometimes we also need a String sort like shown in the following picture. Both ways of sorting (numeric and string) are found in this new release. Version 901t (Jan 3, 2020) 3 functionalities added Rename Header , Insert Column , Delete Column (right click on column header to display its context menu) Version 901u (Jan 6, 2020) 1 functionality added : Natural sort. Thanks to jchd for the idea and Melba23 for his function ArrayMultiColSort() included in the script. Though this natural sort isn't fully implemented, it should work when numbers precede letters (see pic below or better, try it on the "street" column found in the downloadable csv test file below) Natural sort duration + listview update are fast, maybe because of the new function _BufferCreate() described here and now added to the script. Version 901w (Jan 10, 2020) Two functionalities added : 1) Close File button, which allows to import other csv file(s) during the same session 2) Import speed has been improved because the listview control is now populated directly by an Array and not anymore by GUICtrlCreateListViewItem() This explains why, in this version, there are no more Control id's for listview items, allowing to empty the listview content in a snap with this line of code : _SendMessage($g_hListView, $LVM_DELETEALLITEMS) That's what it took to add the Close File button and import several csv files during the same session, avoiding id leaks. Please report if any issue is encountered. Version 901x (Jan 14, 2020) One minor functionality added : number of rows is now displayed just under the listview, it may be handy sometimes. Other minor changes included (natural sort speed improved) Credits : Many thanks to Czardas for his function _CSVSplit() and guinness for his function _SaveCSV(), guys you did a great job. Thanks to Musashi : your suggestions and time passed on testing beta versions of the script, that was really helpful and challenging. Not sure I would have ended this script without your detailed reports. Mikell : the 1st step above (901f) that we wrote together, it all started from here. Your knowledge and kindness are legendary ! Not forgetting all other persons who were inspiring : LarsJ, Melba23, jpm, that list could be endless... Download link : version 901x - Jan 14, 2020 (minor update on Jan 15) 901x - CSV file editor.au3 Test csv file (986 rows/12cols) : Sacramento real estate transactions.csv
    1 point
  2. 27 November 2019: Uploaded a new SciTe4AutoIt3.exe v19.1127.1402.0 installer. This version contains the new SciTE 4.2.0 version. Check below for all other updates to the included utilities. ==> SciTE4AutoIt3 v19.1127.1402.0 Enjoy, Jos Addition/Changes/Fixes in the current installer: -------------------------------------------------------------------------------------------------- 27-11-2019 *** Merged the SciTE v 4.2.0 by Neil Hodgson with our own version of SciTE. (Jos) *** Updated AutoIt3Wrapper v19.1127.1402.0 (Jos)     - 19.102.1901.1 added encoding retrieval for UTF8/ANSI files so they are properly written back     - 19.102.1901.2 Exit script with 999 when update resource copy failed .     - 19.102.1901.3 Fix incrementing version number now before running au3stripper to ensure it contains the new version when increment before is requested.     - 19.102.1901.4 increment version before au3stripper when increment before is Y     - 19.102.1901.5 also update fileversion info in case of a3x compile when requested.     - 19.102.1901.7 change au3check and tidy  stop on error logic to allow for other editor programs.     - 19.102.1901.8-11 Changes to allow the program to be run by other editors.     - 19.102.1901.12 Updates Stop and Restartconsole message to indicate in case the HotKeys aren't set in case of second instance                      HotKeys are ony set when the Editor program has the focus to allow for multiple instances.     - 19.102.1901.13 Updated _RefreshSystemTray, which wasn't working anymore since a long time     - 19.102.1901.14 Added WinClose for the Shelled Script to nicely close that process before ultimately killing it when still needed. *** Updated Au3Stripper v19.1127.1402.0 (Jos)     - 19.102.1901.2 Fixed not removing #pragma lines from Included files.     - 19.102.1901.5 Fixed ternary stripping issue *** Updated SciTEConfig v19.1127.1402.0 (Jos)     - 19.524.1057.1 Fixed creation of includes.txt in userdir and  added some extra logging for adding includes to includes.txt - Some small updates to standard themes. *** Updated Tidy v19.1127.1402.0 (Jos)     - 19.524.1057.1: Fix tidy issue adding space after closing > on #include statement. -------------------------------------------------------------------------------------------------- ==> ScitillaHistory page containing all SciTE-Scintilla updates. ==> Visit the SciTE4AutoIt3 Download page for the latest versions ==> Check the online documentation for an overview of all extra's you get with this installer.
    1 point
  3. This function is used to find a control that is at a specified position from a known control (Anchor). This is loosely based on the UFT Object Repository feature called Visual Relation Identifier edit: 12/19 added option 4 to search for a control that is contained within the area of the Anchor control itself. I needed this to find a fake scrollbar inside a fake edit box for an ancient app I'm automating. Example: I want to find the first Button to the Right of the Label that says "To Continue, Click Here >" ;Get the handle to that label which will be our Anchor point.     $hAnchor = ControlGetHandle("My Application", "", "[TEXT:To Continue, Click Here >]") ;Find the first button to the right of our Anchor point     $hwnd = _ControlFind_VisualRelation(1, "Button", 3, $hAnchor) ;Now click on that control     ControlClick("My Application", "", $hwnd) Below is a much larger example that I used when building the function to assist with the more advanced features such as Padding, Visibility, and Debugging along with the function #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <StaticConstants.au3> #include "_VisualRelationIdentifier.au3" $hGUI = GUICreate("Visual Relation TestApp", 600, 400) $hInfo = GUICtrlCreateLabel("F1 = find Left, F2 = Find Top, F3 = Find Right, F4 = find Bottom", 5, 3, 590, 17, $SS_CENTER) $Edit = GUICtrlCreateEdit("This is the Anchor Control", 200, 150, 200, 100) $hContained = GUICtrlCreateInput("Contained", 220, 210, 100, 20) GUICtrlCreateLabel("Search Padding: ", 350, 23, 200, 17, $SS_RIGHT) $hPadding = GUICtrlCreateInput("0", 550, 20, 40, 20) GUICtrlCreateUpdown(-1) GUICtrlCreateLabel("Instance: ", 350, 48, 200, 17, $SS_RIGHT) $hInstance = GUICtrlCreateInput("1", 550, 45, 40, 20) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 999, 1) ;Controls on the left of the Anchor, not created in the order they are displayed GUICtrlCreateLabel("Label", 10, 133, 80, 17) GUICtrlCreateButton("btn1", 10, 155, 80, 20) GUICtrlCreateButton("btn2", 95, 130, 100, 20) ;Technically Above, but adding padding should catch this on left GUICtrlCreateButton("btn3", 95, 155, 100, 20) GUICtrlCreateButton("btn4", 95, 230, 100, 20) GUICtrlCreateButton("btn5", 95, 180, 100, 20) GUICtrlCreateButton("btn6", 10, 255, 80, 20) ;Technically below, but adding padding should catch this on left GUICtrlCreateButton("btn7", 95, 255, 100, 20) ;Technically below, but adding padding should catch this on left GUICtrlCreateButton("btn8", 95, 205, 100, 20) ;Controls on the Top of the Anchor GUICtrlCreateLabel("Label", 10, 30, 100, 17) GUICtrlCreateButton("btn9", 10, 50, 100, 20) ;Could be Above, or Left with enough padding GUICtrlCreateButton("btn10", 120, 50, 100, 20) ;Could be Above, or Left with enough padding GUICtrlCreateButton("btn11", 450, 75, 100, 20) ;Could be Above, or Right with enough padding GUICtrlCreateButton("btn12", 120, 75, 100, 20) ;Could be Above, or Left with enough padding GUICtrlCreateButton("btn13", 230, 50, 100, 20) GUICtrlCreateButton("btn14", 230, 75, 100, 20) GUICtrlCreateButton("btn15", 10, 75, 100, 20) ;Could be Above, or Left with enough padding GUICtrlCreateButton("btn16", 230, 125, 100, 20) GUICtrlCreateButton("btn17", 340, 100, 100, 20) ;Could be Above, or Right with enough padding GUICtrlCreateButton("btn18", 340, 125, 100, 20) ;Could be Above, or Right with enough padding GUICtrlCreateButton("btn19", 230, 100, 100, 20) GUICtrlCreateButton("btn20", 450, 100, 100, 20) ;Could be Above, or Right with enough padding ;Controls on the Right of the Anchor GUICtrlCreateLabel("Label", 410, 153, 80, 17) GUICtrlCreateButton("btn21", 410, 175, 80, 20) GUICtrlCreateButton("btn22", 500, 225, 80, 20) GUICtrlCreateButton("btn23", 500, 175, 80, 20) GUICtrlCreateButton("btn24", 500, 200, 80, 20) GUICtrlCreateButton("btn25", 500, 150, 80, 20) GUICtrlCreateButton("btn26", 410, 200, 80, 20) GUICtrlCreateButton("btn27", 410, 225, 80, 20) ;Controls on the Bottom of the Anchor GUICtrlCreateLabel("Label", 205, 253, 80, 17) GUICtrlCreateButton("btn28", 500, 251, 80, 20) GUICtrlCreateButton("btn29", 440, 280, 100, 20) GUICtrlCreateButton("btn30", 10, 280, 100, 20) GUICtrlCreateButton("btn31", 220, 280, 100, 20) GUICtrlCreateButton("btn32", 110, 280, 100, 20) GUICtrlCreateButton("btn33", 330, 280, 100, 20) GUICtrlCreateButton("btn34", 10, 310, 100, 20) GUICtrlCreateButton("btn35", 410, 251, 80, 20) GUICtrlCreateButton("btn36", 110, 305, 100, 20) GUICtrlCreateButton("btn37", 440, 350, 100, 20) GUISetState(@SW_SHOW, $hGUI) $hEdit = ControlGetHandle($hGUI, "", $Edit) HotKeySet("{F1}", "_GetLeft") ;Adjust Padding and Instance within the GUI HotKeySet("{F2}", "_GetAbove") ;Adjust Padding and Instance within the GUI HotKeySet("{F3}", "_GetRight") ;Adjust Padding and Instance within the GUI HotKeySet("{F4}", "_GetBelow") ;Adjust Padding and Instance within the GUI HotKeySet("{F5}", "_GetContained") ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ;Get the control that is contained within the area of the Anchor control Func _GetContained() _GUICtrlEdit_AppendText($hEdit, @CRLF & "F5 (Get Contained Within)") ;Update the Edit to show what was selected $Foundhwnd = _ControlFind_VisualRelation(GUICtrlRead($hInstance), "Edit", 4, $hEdit, 0, True, True) ;Find the first button to the left of Anchor where Vertical padding is +- Specified If @error Then MsgBox(0, "Error " & @error, "Failed to find the specified control Button" & GUICtrlRead($hInstance)) Return EndIf ControlSetText($hGUI, "", $Foundhwnd, "FOUND!") ;Update the text for the control it identified ConsoleWrite("Handle returned = (" & $Foundhwnd & ")" & @CRLF) GUICtrlSetData($hInfo, "Buttons renamed to order they were found. The requested control changed to FOUND!") EndFunc Func _GetLeft() _GUICtrlEdit_AppendText($hEdit, @CRLF & "F1 [Get Button" & GUICtrlRead($hInstance) & " to Left, " & GUICtrlRead($hPadding) & " padding]") ;Update the Edit to show what was selected $Foundhwnd = _ControlFind_VisualRelation(GUICtrlRead($hInstance), "Button", 2, $hEdit, GUICtrlRead($hPadding), True, True) ;Find the first button to the left of Anchor where Vertical padding is +- Specified If @error Then MsgBox(0, "Error " & @error, "Failed to find the specified control Button" & GUICtrlRead($hInstance)) Return EndIf ControlSetText($hGUI, "", $Foundhwnd, "FOUND!") ;Update the text for the control it identified ConsoleWrite("Handle returned = (" & $Foundhwnd & ")" & @CRLF) GUICtrlSetData($hInfo, "Buttons renamed to order they were found. The requested control changed to FOUND!") EndFunc Func _GetAbove() _GUICtrlEdit_AppendText($hEdit, @CRLF & "F2 (Get Above selected)") ;Update the Edit to show what was selected $Foundhwnd = _ControlFind_VisualRelation(GUICtrlRead($hInstance), "Button", 0, $hEdit, GUICtrlRead($hPadding), True, True) ;Find the first button above the anchor where Horizontal padding is +- specified If @error Then MsgBox(0, "Error " & @error, "Failed to find the specified control Button" & GUICtrlRead($hInstance)) Return EndIf ControlSetText($hGUI, "", $Foundhwnd, "FOUND!") ;Update the text for the control it identified ConsoleWrite("Handle returned = (" & $Foundhwnd & ")" & @CRLF) GUICtrlSetData($hInfo, "Buttons renamed to order they were found. The requested control changed to FOUND!") EndFunc Func _GetRight() _GUICtrlEdit_AppendText($hEdit, @CRLF & "F3 (Get Right selected)") ;Update the Edit to show what was selected $Foundhwnd = _ControlFind_VisualRelation(GUICtrlRead($hInstance), "Button", 3, $hEdit, GUICtrlRead($hPadding), True, True) ;Find the first button to the left of Anchor where Vertical padding is +- Specified If @error Then MsgBox(0, "Error " & @error, "Failed to find the specified control Button" & GUICtrlRead($hInstance)) Return EndIf ControlSetText($hGUI, "", $Foundhwnd, "FOUND!") ;Update the text for the control it identified ConsoleWrite("Handle returned = (" & $Foundhwnd & ")" & @CRLF) GUICtrlSetData($hInfo, "Buttons renamed to order they were found. The requested control changed to FOUND!") EndFunc Func _GetBelow() _GUICtrlEdit_AppendText($hEdit, @CRLF & "F4 (Get Below selected)") ;Update the Edit to show what was selected $Foundhwnd = _ControlFind_VisualRelation(GUICtrlRead($hInstance), "Button", 1, $hEdit, GUICtrlRead($hPadding), True, True) If @error Then MsgBox(0, "Error " & @error, "Failed to find the specified control Button" & GUICtrlRead($hInstance)) Return EndIf ControlSetText($hGUI, "", $Foundhwnd, "FOUND!") ;Update the text for the control it identified ConsoleWrite("Handle returned = (" & $Foundhwnd & ")" & @CRLF) GUICtrlSetData($hInfo, "Buttons renamed to order they were found. The requested control changed to FOUND!") EndFunc The Function which needs Melba23's _ArrayMultiColSort : #include-once #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include "ArrayMultiColSort.au3" ;----------------------------------------------------------------------------------------------------- ; Name........... _ControlFind_VisualRelation ; Description.... Find a specific control depending on its location to a known control (Anchor point) ; Control search order is closest to the control and cascade out in direction specified ; Syntax......... _ControlFind_VisualRelation($iInstance, $sClass, $sDirection, $hAnchor) ; Parameters .... $iInstance = which instance found from the Anchor ; 1 = First control found in direction specified from Anchor ; 2 = Second control found in the direction specified from Anchor ; etc... ; $sClass = Class name of the control, do not use ClassnameNN or any other type ; $sDirection = 0 = Above Anchor, 1 = Below Anchor, 2 = Left of Anchor, 3 = Right of Anchor, 4 = Fully contained within Anchor (Padding is ignored) ; $hAnchor = hwnd of the known control we are identifying from ; $iPadding = amount to + or - from each side of Anchor size to match control within, Default = 0 ; ex: 10, Above: find the control above the Anchor where x between (Anchor X - 10 and Anchor X + Anchor W + 10) ; ex: 5, Right: find the control to the right of the Anchor where Y between (Anchor Y - 5 and Anchor Y + Anchor H + 5) ; $bIsVisible = True = Only identify those controls that are visible (Default). False will return any control visible or not. ; $bDebug = True will draw lines on the screen where its searching, Default = False ; Return values.. Success = Returns the hwnd ; Failure = Sets @error ; 1 = The Anchor was not passed as a hwnd ; 2 = Failed to find the parent window of the Anchor ; 3 = Unable to identify the position of the Anchor control ; 4 = Could not find any of the specified Classes within the Anchor window ; 5 = Could not find the Instance specified in the position specified ; Author ........ BigDaddyO ; Modified by.... ; Remarks ....... requires Include: WinAPI.au3, WindowsConstants.au3, Melba23's _ArrayMultiColSort (https://www.autoitscript.com/forum/topic/155442-arraymulticolsort-new-release-06-april-2019/) ; Example........ $sClassnameNN = _ControlFind_VisualRelation(1, "Button", 2, $hEdit, 0) ;----------------------------------------------------------------------------------------------------- Func _ControlFind_VisualRelation($iInstance, $sClass, $sDirection, $hAnchor, $iPadding = 0, $bIsVisible = True, $bDebug = False) ;Ensure the $hAnchor is a handle If IsHWnd($hAnchor) = 0 Then Return SetError(1) ;Get the handle for the window the $hAnchor control is in $hAnchorWin = _WinAPI_GetAncestor($hAnchor, $GA_ROOT) If IsHWnd($hAnchorWin) = 0 Then Return SetError(2) If $bDebug Then ConsoleWrite("Anchor Window Handle = (" & $hAnchorWin & ")" & @CRLF) ;Get the current position of the Anchor control $aAnchorPos = ControlGetPos($hAnchorWin, "", $hAnchor) If @error Then Return SetError(3) If $bDebug Then ConsoleWrite("Anchor Window position: x=" & $aAnchorPos[0] & ", y=" & $aAnchorPos[1] & @CRLF) Local $iInstanceFound = 0 Local $inst = 0 ;The control instance that we are looking at Local $v = 0 ;The control count we are adding to the search array Local $aFound[9999][5] ;[][0] = hwnd, [][1] = X coord, [][2] = Y coord, [][3] = x + w, [][4] = y + h ;Find every Control with the specified $sClass THAT IS CURRENTLY VISIBLE ;Need to keep the Control Find loop # seperate from the Array Storage to ignore the hidden controls! While 1 $inst += 1 $hCtrl = ControlGetHandle($hAnchorWin, "", "[CLASS:" & $sClass & "; INSTANCE:" & $inst & "]") If @error Then If $inst = 1 Then Return SetError(4) ;Did not find any of the Class type in the window Else ExitLoop ;No more of this Class were found stop looking and start trying to match the requested area EndIf EndIf If $bIsVisible Then ;Do we only want the visible controls? If ControlCommand($hAnchorWin, "", $hCtrl, "IsVisible", "") = 0 Then ContinueLoop EndIf $v += 1 ;If we got this far, we need to add this control to our array $aCtrlPos = ControlGetPos($hAnchorWin, "", $hCtrl) If $bDebug = True Then ConsoleWrite($sClass & $v & " - hwnd(" & $hCtrl & ") found at " & $aCtrlPos[0] & ", " & $aCtrlPos[1] & @CRLF) ControlSetText($hAnchorWin, "", $hCtrl, $sClass & $v) EndIf ;Save this control: Handle, X1, Y1, X2, Y2 $aFound[$v - 1][0] = $hCtrl ;Save the Instance # so we can find again $aFound[$v - 1][1] = $aCtrlPos[0] ;X coord of left side $aFound[$v - 1][2] = $aCtrlPos[1] ;Y coord of top $aFound[$v - 1][3] = $aCtrlPos[0] + $aCtrlPos[2] ;X coord of right side $aFound[$v - 1][4] = $aCtrlPos[1] + $aCtrlPos[3] ;Y coord of bottom WEnd ;~ ;Resize and rearrange the found controls so they cascase out from the Anchor control ReDim $aFound[$v][5] ;Now to get the control at the location we were looking for Local $iFoundInstance = 0 Switch $sDirection Case 0 ;Above Anchor control and within the X padding ;0 = TOP: SORT BY Y DESCENDING, THEN BY X ASCENDING Local $aSortData[][] = [[2, 1],[1,0]] _ArrayMultiColSort($aFound, $aSortData) If $bDebug = True Then ;Draw lines to show where it was looking $hVRIgdi = _GDIPlus_Startup(Default, True) $hVRIgraphic = _GDIPlus_GraphicsCreateFromHWND($hAnchorWin) $hVRIpen = _GDIPlus_PenCreate(0xFFFF0000) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] - $iPadding, $aAnchorPos[1], $aAnchorPos[0] - $iPadding, 0, $hVRIpen) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] + $aAnchorPos[2] + $iPadding, $aAnchorPos[1], $aAnchorPos[0] + $aAnchorPos[2] + $iPadding, 0, $hVRIpen) EndIf ;Loop through the control found array For $d = 0 to UBound($aFound) - 1 If $aFound[$d][0] = $hAnchor Then ContinueLoop ;Possible that we will see the anchor if looking for the same class type ;If the right of the control is greater than the left of the Anchor minus the padding, AND the left of the control is less than the Anchor plus the padding If ( $aFound[$d][3] >= ($aAnchorPos[0] - $iPadding) ) and ( $aFound[$d][1] <= ($aAnchorPos[0] + $aAnchorPos[2] + $iPadding) ) Then ;if the top of the control is less than the top of the Anchor If $aFound[$d][2] <= $aAnchorPos[1] Then $iFoundInstance += 1 If $iFoundInstance = $iInstance Then If $bDebug = True Then ;Move the mouse to the center of the control we will be returning $aWinPos = WinGetPos($hAnchorWin, "") $aClient = WinGetClientSize($hAnchorWin, "") $iAddX = ($aWinPos[2] - $aClient[0] - 2) ;Generate the X Coord that the ControlGetPos will reference from $iAddY = ($aWinPos[3] - $aClient[1] - 2) ;Generate the Y Coord that the ControlGetPos will reference from $x = $aWinPos[0] + $aFound[$d][1] + (($aFound[$d][3] - $aFound[$d][1]) / 2) + $iAddX $y = $aWinPos[1] + $aFound[$d][2] + (($aFound[$d][4] - $aFound[$d][2]) / 2) + $iAddY MouseMove($x, $y, 0) EndIf Return $aFound[$d][0] Else ContinueLoop EndIf Else ContinueLoop ;This control is not within the Vertical limits of the Anchor and Padding EndIf Else ContinueLoop ;This control is not within the Horizontal limits of the Anchor and Padding EndIf Next Case 1 ;Below Anchor control and within the X padding ;1 = BOTTOM: SORT BY Y ASCENDING, THEN BY X ASCENDING Local $aSortData[][] = [[2, 0],[1,0]] _ArrayMultiColSort($aFound, $aSortData) If $bDebug = True Then ;Draw lines to show where it was looking $hVRIgdi = _GDIPlus_Startup(Default, True) $hVRIgraphic = _GDIPlus_GraphicsCreateFromHWND($hAnchorWin) $hVRIpen = _GDIPlus_PenCreate(0xFFFF0000) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] - $iPadding, $aAnchorPos[1] + $aAnchorPos[3], $aAnchorPos[0] - $iPadding, $aAnchorPos[1] + 1000, $hVRIpen) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] + $aAnchorPos[2] + $iPadding, $aAnchorPos[1] + $aAnchorPos[3], $aAnchorPos[0] + $aAnchorPos[2] + $iPadding, $aAnchorPos[1] + 1000, $hVRIpen) EndIf ;Loop through the control found array For $d = 0 to UBound($aFound) - 1 If $aFound[$d][0] = $hAnchor Then ContinueLoop ;Possible that we will see the anchor if looking for the same class type ;If the right of the control is greater than the left of the Anchor minus the padding, AND the left of the control is less than the Anchor plus the padding If ( $aFound[$d][3] >= ($aAnchorPos[0] - $iPadding) ) and ( $aFound[$d][1] <= ($aAnchorPos[0] + $aAnchorPos[2] + $iPadding) ) Then ;if the top of the control is greater than the bottom of the Anchor If $aFound[$d][2] >= ($aAnchorPos[1] + $aAnchorPos[3]) Then $iFoundInstance += 1 If $iFoundInstance = $iInstance Then If $bDebug = True Then ;Move the mouse to the center of the control we will be returning $aWinPos = WinGetPos($hAnchorWin, "") $aClient = WinGetClientSize($hAnchorWin, "") $iAddX = ($aWinPos[2] - $aClient[0] - 2) ;Generate the X Coord that the ControlGetPos will reference from $iAddY = ($aWinPos[3] - $aClient[1] - 2) ;Generate the Y Coord that the ControlGetPos will reference from $x = $aWinPos[0] + $aFound[$d][1] + (($aFound[$d][3] - $aFound[$d][1]) / 2) + $iAddX $y = $aWinPos[1] + $aFound[$d][2] + (($aFound[$d][4] - $aFound[$d][2]) / 2) + $iAddY MouseMove($x, $y, 0) EndIf Return $aFound[$d][0] Else ContinueLoop EndIf Else ContinueLoop ;This control is not within the Vertical limits of the Anchor and Padding EndIf Else ContinueLoop ;This control is not within the Horizontal limits of the Anchor and Padding EndIf Next Case 2 ;Left of Anchor control and within the Y padding ;2 = LEFT: SORT BY Y ASCENDING, THEN BY X DESCENDING SO CLOSEST CONTROL WOULD BE 1 Local $aSortData[][] = [[1, 1],[2,0]] _ArrayMultiColSort($aFound, $aSortData) If $bDebug = True Then ;Draw lines to show where it was looking $hVRIgdi = _GDIPlus_Startup(Default, True) $hVRIgraphic = _GDIPlus_GraphicsCreateFromHWND($hAnchorWin) $hVRIpen = _GDIPlus_PenCreate(0xFFFF0000) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0], $aAnchorPos[1] - $iPadding, 0, $aAnchorPos[1] - $iPadding, $hVRIpen) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0], $aAnchorPos[1] + $aAnchorPos[3] + $iPadding, 0, $aAnchorPos[1] + $aAnchorPos[3] + $iPadding, $hVRIpen) EndIf ;Loop through the control found array For $d = 0 to UBound($aFound) - 1 If $aFound[$d][0] = $hAnchor Then ContinueLoop ;Possible that we will see the anchor if looking for the same class type If $bDebug Then ConsoleWrite("Is " & ControlGetText($hAnchorWin, "", $aFound[$d][0]) & " bottom (" & $aFound[$d][4] & ") located vertically below " & ($aAnchorPos[1] - $iPadding) & " and top (" & $aFound[$d][2] & ") is above " & ($aAnchorPos[1] + $aAnchorPos[3] + $iPadding) ) ;If the top of the control is above the bottom of the anchor plus the padding AND the bottom of the control is below the top of the Anchor minus the padding If ( $aFound[$d][2] <= ($aAnchorPos[1] + $aAnchorPos[3] + $iPadding) ) and ( $aFound[$d][4] > ($aAnchorPos[1] - $iPadding) ) Then If $bDebug Then ConsoleWrite(@TAB & "YES" & @CRLF) If $bDebug Then ConsoleWrite(@TAB & "Is the controls Left (" & $aFound[$d][1] & ") located horizontally left of " & $aAnchorPos[0] ) ;If the left of the control is < the left of the Anchor If $aFound[$d][1] < $aAnchorPos[0] Then If $bDebug Then ConsoleWrite(@TAB & "YES" & @CRLF) $iFoundInstance += 1 If $iFoundInstance = $iInstance Then If $bDebug = True Then ;Move the mouse to the center of the control we will be returning $aWinPos = WinGetPos($hAnchorWin, "") $aClient = WinGetClientSize($hAnchorWin, "") $iAddX = ($aWinPos[2] - $aClient[0] - 2) ;Generate the X Coord that the ControlGetPos will reference from $iAddY = ($aWinPos[3] - $aClient[1] - 2) ;Generate the Y Coord that the ControlGetPos will reference from $x = $aWinPos[0] + $aFound[$d][1] + (($aFound[$d][3] - $aFound[$d][1]) / 2) + $iAddX $y = $aWinPos[1] + $aFound[$d][2] + (($aFound[$d][4] - $aFound[$d][2]) / 2) + $iAddY MouseMove($x, $y, 0) EndIf Return $aFound[$d][0] Else ContinueLoop EndIf Else If $bDebug Then ConsoleWrite(@TAB & "NO" & @CRLF) ContinueLoop ;This control is not within the Horizontal limits Left of the Anchor EndIf Else If $bDebug Then ConsoleWrite(@TAB & "NO" & @CRLF) ContinueLoop ;This control is not within the Vertical limits of the Anchor and Padding EndIf Next Case 3 ;Right of Anchor control ;3 = RIGHT: SORT BY Y ASCENDING, THEN BY X ASCENDING Local $aSortData[][] = [[1, 0],[2,0]] _ArrayMultiColSort($aFound, $aSortData) If $bDebug = True Then ;Draw lines to show where it was looking $hVRIgdi = _GDIPlus_Startup(Default, True) $hVRIgraphic = _GDIPlus_GraphicsCreateFromHWND($hAnchorWin) $hVRIpen = _GDIPlus_PenCreate(0xFFFF0000) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] + $aAnchorPos[2], $aAnchorPos[1] - $iPadding, $aAnchorPos[0] + 1000, $aAnchorPos[1] - $iPadding, $hVRIpen) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] + $aAnchorPos[2], $aAnchorPos[1] + $aAnchorPos[3] + $iPadding, $aAnchorPos[0] + 1000, $aAnchorPos[1] + $aAnchorPos[3] + $iPadding, $hVRIpen) EndIf ;Loop through the control found array For $d = 0 to UBound($aFound) - 1 If $aFound[$d][0] = $hAnchor Then ContinueLoop ;Possible that we will see the anchor if looking for the same class type ;If the top of the control is above the bottom of the anchor plus the padding AND the bottom of the control is below the top of the Anchor minus the padding If ( $aFound[$d][2] <= ($aAnchorPos[1] + $aAnchorPos[3] + $iPadding) ) and ( $aFound[$d][4] > ($aAnchorPos[1] - $iPadding) ) Then ;If the Right of the control is > the Right of the Anchor If $aFound[$d][3] > ($aAnchorPos[0] + $aAnchorPos[2]) Then $iFoundInstance += 1 If $iFoundInstance = $iInstance Then If $bDebug = True Then ;Move the mouse to the center of the control we will be returning $aWinPos = WinGetPos($hAnchorWin, "") $aClient = WinGetClientSize($hAnchorWin, "") $iAddX = ($aWinPos[2] - $aClient[0] - 2) ;Generate the X Coord that the ControlGetPos will reference from $iAddY = ($aWinPos[3] - $aClient[1] - 2) ;Generate the Y Coord that the ControlGetPos will reference from $x = $aWinPos[0] + $aFound[$d][1] + (($aFound[$d][3] - $aFound[$d][1]) / 2) + $iAddX $y = $aWinPos[1] + $aFound[$d][2] + (($aFound[$d][4] - $aFound[$d][2]) / 2) + $iAddY MouseMove($x, $y, 0) EndIf Return $aFound[$d][0] Else ContinueLoop EndIf Else ContinueLoop ;This control is not within the Horizontal limits Right of the Anchor EndIf Else ContinueLoop ;This control is not within the Vertical limits of the Anchor and Padding EndIf Next Case 4 ;Contained within the Anchor controls area ;4 = Contained Within: SORT BY Y ASCENDING, THEN BY X ASCENDING Local $aSortData[][] = [[1, 0],[2,0]] _ArrayMultiColSort($aFound, $aSortData) If $bDebug = True Then ;Draw lines to show where it was looking $hVRIgdi = _GDIPlus_Startup(Default, True) $hVRIgraphic = _GDIPlus_GraphicsCreateFromHWND($hAnchorWin) $hVRIpen = _GDIPlus_PenCreate(0xFFFF0000) _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] - 1, $aAnchorPos[1] - 1, $aAnchorPos[0] + $aAnchorPos[2] + 1, $aAnchorPos[1] - 1, $hVRIpen) ;Draw across the tope _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] + $aAnchorPos[2] + 1, $aAnchorPos[1] - 1, $aAnchorPos[0] + $aAnchorPos[2] + 1, $aAnchorPos[1] + $aAnchorPos[3] + 1, $hVRIpen) ;Draw down right side _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] + $aAnchorPos[2] + 1, $aAnchorPos[1] + $aAnchorPos[3] + 1, $aAnchorPos[0] - 1, $aAnchorPos[1] + $aAnchorPos[3] + 1, $hVRIpen) ;Draw across bottom _GDIPlus_GraphicsDrawLine($hVRIgraphic, $aAnchorPos[0] - 1, $aAnchorPos[1] + $aAnchorPos[3] + 1, $aAnchorPos[0] - 1, $aAnchorPos[1] - 1, $hVRIpen) ;Draw up left side EndIf ;Loop through the control found array For $d = 0 to UBound($aFound) - 1 If $aFound[$d][0] = $hAnchor Then ContinueLoop ;Possible that we will see the anchor if looking for the same class type ;Move through them to ensure they are completely contained within the area of the Known Control If $aFound[$d][1] >= $aAnchorPos[0] and $aFound[$d][3] <= $aAnchorPos[0] + $aAnchorPos[2] and $aFound[$d][2] >= $aAnchorPos[1] and $aFound[$d][4] <= $aAnchorPos[1] + $aAnchorPos[3] Then $iFoundInstance += 1 If $iFoundInstance = $iInstance Then If $bDebug = True Then ;Move the mouse to the center of the control we will be returning $aWinPos = WinGetPos($hAnchorWin, "") $aClient = WinGetClientSize($hAnchorWin, "") $iAddX = ($aWinPos[2] - $aClient[0] - 2) ;Generate the X Coord that the ControlGetPos will reference from $iAddY = ($aWinPos[3] - $aClient[1] - 2) ;Generate the Y Coord that the ControlGetPos will reference from $x = $aWinPos[0] + $aFound[$d][1] + (($aFound[$d][3] - $aFound[$d][1]) / 2) + $iAddX $y = $aWinPos[1] + $aFound[$d][2] + (($aFound[$d][4] - $aFound[$d][2]) / 2) + $iAddY MouseMove($x, $y, 0) EndIf Return $aFound[$d][0] Else ContinueLoop EndIf Else ContinueLoop ;This control is not within the Vertical limits of the Anchor and Padding EndIf Next ;~ $aFound[$v - 1][0] = $hCtrl ;Save the Instance # so we can find again ;~ $aFound[$v - 1][1] = $aCtrlPos[0] ;X coord of left side ;~ $aFound[$v - 1][2] = $aCtrlPos[1] ;Y coord of top ;~ $aFound[$v - 1][3] = $aCtrlPos[0] + $aCtrlPos[2] ;X coord of right side ;~ $aFound[$v - 1][4] = $aCtrlPos[1] + $aCtrlPos[3] ;Y coord of bottom EndSwitch Return SetError(5) ;If we got this far, then we found something but not the instance we wanted. EndFunc Any feedback you could offer would be appreciated as aside from my test gui and my one app I needed this for I haven't done a lot of testing. Thanks
    1 point
  4. GUICtrlSetData($idComboBox, "Item 2|Item 3|Item 2|Item3") ; will work with or without ending "|" GUICtrlSetData($idComboBox, "Item 2") ; will not add to combo, will set default as help file GUICtrlSetData($idComboBox, "Item 2|") ; will add to combo, not described in help file I removed it from my post because I didn't want to hack OP thread, but I suppose it is kind of late now
    1 point
  5. mikell

    How to get JS values?

    Sorry. I tried to have a look at the "https://........" website but it failed
    1 point
  6. argumentum

    _ReadIniSectionNames

    ...I used to have a happy face DB. So it happens, chr(1) is a pappy face in Terminal font. the chr(2) is a color inverted happy face too. Those where the delimiters for my databaseish scheme. Read, split and was human readable. In your case, a TAB delimited table may be easier than an INI styled file. You can use the _array to/from file(). So it would meet your requirement of notepad editable database. Basically, if you can read/write to file, is the bases of holding data ( data base ). INI styled or what not is all the same in the case of notapad editable db As the DB grows, searching may need flexibility in querying the data. SQL92 was to get us all to agree but you are a one man team. I use ( at times ) what others came up with as a "ready made" solution, ex: SQLite. A blob in an INI file would take Str2Bin to keep it a one-liner. ok, new bottom line: Use industry standards or come up with your own. If is functional, it functioned.
    1 point
  7. There : #include <Constants.au3> #include <GUIConstants.au3> Local $hGUI = GUICreate ("Test", 300, 300, -1, -1,-1, $WS_EX_ACCEPTFILES) Local $idDummy = GUICtrlCreateLabel ("",0,0,300,300) GUICtrlSetState(-1, $GUI_DROPACCEPTED+$GUI_DISABLE) Local $idButton = GUICtrlCreateButton ("OK", 100,200,100,30) GUISetState () While True Switch GUIGetMsg () Case $GUI_EVENT_CLOSE, $idButton ExitLoop Case $GUI_EVENT_DROPPED ConsoleWrite ("dropped " & @GUI_DropId & @CRLF) EndSwitch WEnd
    1 point
  8. UIA updates The examples here show how Sample code (created through the Detail info listview page and the Sample code menu in UIASpy) looks when the code is generated under different Windows modes (Options | Windows | Mode menu in UIASpy). Note the version differences in CLSID_CUIAutomation as well as the main $oUIAutomation and $oUIElement objects. When you select Windows mode through the Options | Windows | Mode menu, UIASpy will generate correct Sample code for this Windows version and use the correct CLSID_CUIAutomation version and the correct versions of the main $oUIAutomation and $oUIElement objects. Code is stored in Examples\7) UIA updates\Notepad\ folder. The examples show code generated under Windows 7, Windows 8, Windows 8.1, Windows 10 First (1507) and Windows 10 Last (1809) modes. The code boxes below show code for Windows 7 and Windows 10 Last modes. Windows 7 mode (Notepad-W7.au3): #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\UIA_Constants.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.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 ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pWindow1 ) ; $TreeScope_Children to find application top window $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) ; (much faster) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pEdit1, $oEdit1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition1, $pEdit1 ) ; $TreeScope_Descendants to find window controls $oEdit1 = ObjCreateInterface( $pEdit1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oEdit1 ) Then Return ConsoleWrite( "$oEdit1 ERR" & @CRLF ) ConsoleWrite( "$oEdit1 OK" & @CRLF ) EndFunc The code can be executed under Windows XP, Windows Vista, Windows 7 and later versions. Windows 10 Last (1809) mode (Notepad-W10Last.au3): #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\UIA_Constants.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) 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_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pEdit1, $oEdit1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition1, $pEdit1 ) $oEdit1 = ObjCreateInterface( $pEdit1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oEdit1 ) Then Return ConsoleWrite( "$oEdit1 ERR" & @CRLF ) ConsoleWrite( "$oEdit1 OK" & @CRLF ) EndFunc The code can be executed under Windows 10 version 1809 and later versions. Output in SciTE console for all examples: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pCondition0 OK $oWindow1 OK --- Find window/control --- $pCondition1 OK $oEdit1 OK New zip-file at bottom of first post.
    1 point
×
×
  • Create New...