LxP Posted March 3, 2006 Share Posted March 3, 2006 (edited) Sometimes it can be difficult to automate some software for one of a few reasons: Perhaps different fields share a common control ID. Perhaps the GUI designer overlapped many controls, so AutoIt Window Info won't show you the one that you actually have your mouse over. This script aims to provide a solution. The idea is for you to populate such a GUI with different values in each field, and then allow this script to 'capture' that window. It will then group controls sharing the same text values and display their ClassNameNNs, which is generally** an excellent way to reliably differentiate between controls. Download: FindClassesByText.au3 Operation: Prepare the window that you wish to automate. Start this script. Click the Capture button. Activate the other window by clicking on it. Return to the script's window and browse the assembled TreeView. ** Proven not to work with .NET applications; _ControlGetHandleByPos() may be your only hope there. v1.2 (29/May/2013): Add "Copy Item" and "Copy All" buttons to copy information from the TreeView to the clipboard (thanks to the idea) Show control text as an AutoIt string definition (with macros as appropriate) instead of just naively wrapping it in single quotes v1.1 (27/May/2013): Adjust for script-breaking changes in AutoIt v3.2.12.0 (thanks to ) v1.0 (4/Mar/2006): Initial release Edited May 29, 2013 by LxP ibrahem 1 Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted March 3, 2006 Moderators Share Posted March 3, 2006 (edited) Great work, this will be very useful. Now I see how you were able to figure out the ClassNameNNs of that Trackit Audit program I had. It would be nice to have the ability to copy the ClassNameNNs, or possibly a double click to send to SciTE. Edited March 3, 2006 by big_daddy Link to comment Share on other sites More sharing options...
LxP Posted March 4, 2006 Author Share Posted March 4, 2006 Great work, this will be very useful. Now I see how you were able to figure out the ClassNameNNs of that Trackit Audit program I had.Thanks! I wish I had this script around when I helped you out. It would be nice to have the ability to copy the ClassNameNNs, or possibly a double click to send to SciTE.Yes; I agree. I didn't spend too long looking at how I could make a TreeView item interactive. I'll look at that the next time I work with AutoIt. Link to comment Share on other sites More sharing options...
litlmike Posted March 6, 2006 Share Posted March 6, 2006 LXP, the script you made is awesome! I have tried it on a bunch of windows and it works lovely! Thanks for taking the time to do that!However, sadly, for the problematic ACT! Build 6.0.0.679 Window, I still cannot get even your script to bring me the solution. As of right now, there is no way to capture the info that your awesome script returned (like copy/paste), so I cannot show you ALL of what I got back. But I will describe what info your script gave me so you can help us figure out what is going on.I will add the info/problem in the our previous post, so we don't bog down your post here (the link below)PostThanks again LXP! The script works for all of my other windows! _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
GrungeRocker Posted March 6, 2006 Share Posted March 6, 2006 it's really nice!i will use it soon!thanks! [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted March 7, 2006 Moderators Share Posted March 7, 2006 (edited) I hope you don't mind, but I added a copy feature to your script. To be honest I learned a lot having to conform with your type of scripting.See updated script below. Edited March 17, 2006 by big_daddy Link to comment Share on other sites More sharing options...
LxP Posted March 8, 2006 Author Share Posted March 8, 2006 I hope you don't mind, but I added a copy feature to your script.I don't mind at all! I like your addition very much; transcribing window information otherwise is definitely not fun. Ideally, I suppose there would be a button that copies all information to the clipboard in a format similar to this perhaps: 'Text contained in control with special characters substituted out' ClassNameNN ClassNameNN ClassNameNN 'Text contained in control with special characters substituted out' ClassNameNN ClassNameNN ClassNameNN 'Etc.' Etc Etc Etc ...but I don't see myself doing this in the near future. Link to comment Share on other sites More sharing options...
MHz Posted March 8, 2006 Share Posted March 8, 2006 I did a messagebox to get the individual lines in a paragraph. Not the ideal method, as you describe, but it works until a more suitable method is adopted as you describe, LxP. Mostly changes to the last func. I did change the size of the Gui to something alittle smaller though. ctrlbypos.au3 Much nicer with the Copy functions added in. Saves on manually labour. Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted March 8, 2006 Moderators Share Posted March 8, 2006 It isn't the prettiest thing in the world, but she works. If a single ClassNameNN is selected it will copy only that one item to the clipboard. If a parent item is selected then it will copy all of it's child items to the clipboard. FindClassesByText.au3 Link to comment Share on other sites More sharing options...
litlmike Posted March 10, 2006 Share Posted March 10, 2006 It isn't the prettiest thing in the world, but she works. If a single ClassNameNN is selected it will copy only that one item to the clipboard. If a parent item is selected then it will copy all of it's child items to the clipboard. FindClassesByText.au3 This script is wonderful. Since I do not know how to do this, I have to ask for help. Is it possible to make a 'Copy All' feature? In that, I would like to test EVERY control on the window to trouble shoot my controls. In that, when I can't find a ControlID/ClassNameNN, it would be great to paste it into Scite, then run my script for every control. I know that would mean like 300 items, but as a last resort, when all else fails, it would be great to have. THanks. _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
LxP Posted March 10, 2006 Author Share Posted March 10, 2006 Is it possible to make a 'Copy All' feature? In that, I would like to test EVERY control on the window to trouble shoot my controls. In that, when I can't find a ControlID/ClassNameNN, it would be great to paste it into Scite, then run my script for every control. I know that would mean like 300 items, but as a last resort, when all else fails, it would be great to have.The original script contains a function called WinGetControlIDs() which prepares a list of all ClassNameNNs for a window. You can use it in this fashion: Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text') For $I = 1 To $ClassNameNNs[0] $ID = $ClassNameNNs[$I] ; (and then perform some action where $ID will contain one particular ClassNameNN) Next ...to perform some task on every single control. Link to comment Share on other sites More sharing options...
litlmike Posted March 10, 2006 Share Posted March 10, 2006 The original script contains a function called WinGetControlIDs() which prepares a list of all ClassNameNNs for a window. You can use it in this fashion: Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text') For $I = 1 To $ClassNameNNs[0] $ID = $ClassNameNNs[$I] ; (and then perform some action where $ID will contain one particular ClassNameNN) Next ...to perform some task on every single control. I understand a little bit, but be patient as I am still young in my programming knowledge. So for example, would this be correct? Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text') For $I = 1 To $ClassNameNNs[0] $ID = $ClassNameNNs[$I] ControlCommand ("Eudora", "", $ID, "ShowDropDown", "") Next Oh, and could you help a noob out and tell me what "[$I]", and "[0]" does? Or where to read more about it? Thanks! _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 I understand a little bit, but be patient as I am still young in my programming knowledge. So for example, would this be correct? Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text') For $I = 1 To $ClassNameNNs[0] $ID = $ClassNameNNs[$I] ControlCommand ("Eudora", "", $ID, "ShowDropDown", "") Next Oh, and could you help a noob out and tell me what "[$I]", and "[0]" does? Or where to read more about it? Thanks!Hmmm... I would take a "gander" at Array and For/Next Loop in the help file. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
LxP Posted March 10, 2006 Author Share Posted March 10, 2006 So for example, would this be correct? Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text') For $I = 1 To $ClassNameNNs[0] $ID = $ClassNameNNs[$I] ControlCommand ("Eudora", "", $ID, "ShowDropDown", "") NextAlmost. You need to appropriately set the 'Window title' and 'Window text' placeholders in the first line (the 'Window text' one can be removed if not needed). This code will run the ShowDropDown command on every control of the Eudora window: Local $ID, $ClassNameNNs = WinGetControlIDs('Eudora') For $I = 1 To $ClassNameNNs[0] $ID = $ClassNameNNs[$I] ControlCommand('Eudora', '', $ID, 'ShowDropDown') Next It will also do it rather fast, so you may not see much. Perhaps you'd like to add a Sleep(500) between the ControlCommand() line and Next to pause for half a second between each attempt. WinGetControlIDs() returns an array, which is one variable capable of holding multiple values at once. These multiple values are known as elements of the array. If $Array were an array with 5 elements, you could access these elements as $Array[0] to $Array[4]. You are not limited to entering a literal number between the square brackets to access a certain element. If you have some number in another variable you can use that variable to determine which element is accessed, e.g. -- ; Declare an array of 5 elements Local $Array[5] ; Declare a variable with a number Local $Num = 2 ; Set element 2 (the third element) of $Array $Array[$Num] = 'Ding!' You can use the For..Next construct to run through each element of an array. You first need to determine how many times to run the loop, in this case how many useful elements there are in the array. WinGetControlIDs() (along with a few other AutoIt-native functions returning an array) uses element 0 specially -- it contains a count of the remaining elements. By programming a loop to run from 1 to that count, we can access each element of that array in turn. This is what is being done above. (Hopefully I'll remember this post when I next work on my tutorial...) Link to comment Share on other sites More sharing options...
MuffettsMan Posted January 29, 2008 Share Posted January 29, 2008 not to bump an old post but does this still work... or is there alternate more updated methods to attempt to obtain controlID's? running the script seems to spit back info into the gui when focusing on normal windows (that also return data in the window info tool) however comes up with nothing on the windows that don't give anything in the win info tool either >.< specificly - trying to get control id info for a World of warcraft window - by fluke or miracle i can controlsend keystrokes to it but controlclick won't work with the same logic - i assume because there are no controlclick cords in the win info tool Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
vtr Posted July 24, 2008 Share Posted July 24, 2008 Hi, many thanks for the script, clicking "Copy to clipboard" returns C:\Program Files\AutoIt3\Include\FindClassesByText.au3 (327) : ==> Subscript used with non-Array variable.: If StringInStr($a_Item[0], "'") <> 0 Then If StringInStr($a_Item^ ERROR Is this still supported? Would be useful to have. Link to comment Share on other sites More sharing options...
martin Posted July 25, 2008 Share Posted July 25, 2008 Hi, many thanks for the script, clicking "Copy to clipboard" returns C:\Program Files\AutoIt3\Include\FindClassesByText.au3 (327) : ==> Subscript used with non-Array variable.: If StringInStr($a_Item[0], "'") <> 0 Then If StringInStr($a_Item^ ERROR Is this still supported? Would be useful to have.I'm not at all sure about this quick change but it seems to work if you want to copy the class name selected in the treeview. expandcollapse popup; ============================================================================== ; CopyTreeViewItem(): ; Copies the selected TreeViewItem to the clipboard. ; ============================================================================== Func CopyTreeViewItem() Local $a_Item[2] $a_Item[0] = GUICtrlRead($Handles[$HAN_TREE], 1);text $a_Item[1] = GUICtrlRead($Handles[$HAN_TREE]);id ConsoleWrite($a_Item & @CRLF) Local $a_NextItem Local $a_FirstChild Local $a_Child[2] Local $a_Check Dim $avArray[1] If Not @error then;and isarray($a_Item) Then ; Check to see if it is a parent item If StringInStr($a_Item[0], "'") <> 0 Then;[0] ; Get first child of selected TreeViewItem $a_FirstChild = GUICtrlSendMsg($Handles[$HAN_TREE], $TVM_GETNEXTITEM, _ $TVGN_CHILD, GUICtrlGetHandle($a_Item[1])) ; Select the first child item GUICtrlSendMsg($Handles[$HAN_TREE], $TVM_SELECTITEM, $TVGN_CARET, _ $a_FirstChild) While 1 ; Read selected item $a_Child[1] = GUICtrlRead($Handles[$HAN_TREE], 1) $a_Child[0] = GUICtrlRead($Handles[$HAN_TREE]) ; This is ugly, please help me revise! If $a_Check == 0 Then ExitLoop ; Insert selected child text into array $avArray[UBound($avArray) - 1] = $a_Child[0] ReDim $avArray[UBound($avArray) + 1] ; Get the control id of the next child $a_NextItem = GUICtrlSendMsg($Handles[$HAN_TREE], $TVM_GETNEXTITEM, _ $TVGN_NEXT, GUICtrlGetHandle($a_Child[1])) ; Select the next child GUICtrlSendMsg($Handles[$HAN_TREE], $TVM_SELECTITEM, $TVGN_CARET, _ $a_NextItem) ; This is also ugly! $a_Check = $a_NextItem WEnd _ArrayToClip($avArray) Else ClipPut($a_Item[0]) EndIf EndIf EndFunc ;==>CopyTreeViewItem Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
vtr Posted July 28, 2008 Share Posted July 28, 2008 Great, thanks a lot, will test in the office tomorrow. Link to comment Share on other sites More sharing options...
oldguy Posted January 2, 2009 Share Posted January 2, 2009 (edited) Does this script still work? I tried it and I get an error about $GUI_SS_DEFAULT_GUI not being declared. +>13:58:13 Starting AutoIt3Wrapper v.1.10.1.14 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X86 ANSI) >Running AU3Check (1.54.13.0) from:C:\Program Files\AutoIt3 C:\autoitscripts\FindClassesByText.au3(63,29) : WARNING: $GUI_SS_DEFAULT_GUI: possibly used before declaration. BitOR($GUI_SS_DEFAULT_GUI, ~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\autoitscripts\FindClassesByText.au3(63,42) : WARNING: $WS_SIZEBOX: possibly used before declaration. BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\autoitscripts\FindClassesByText.au3(63,59) : WARNING: $WS_MAXIMIZEBOX: possibly used before declaration. BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\autoitscripts\FindClassesByText.au3(68,53) : WARNING: $BS_MULTILINE: possibly used before declaration. Default, Default, Default, Default, $BS_MULTILINE) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\autoitscripts\FindClassesByText.au3(101,47) : WARNING: $WS_EX_CLIENTEDGE: possibly used before declaration. $GUI_SS_DEFAULT_TREEVIEW, $WS_EX_CLIENTEDGE) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\autoitscripts\FindClassesByText.au3(63,29) : ERROR: $GUI_SS_DEFAULT_GUI: undeclared global variable. BitOR($GUI_SS_DEFAULT_GUI, ~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\autoitscripts\FindClassesByText.au3 - 1 error(s), 5 warning(s) Any ideas how to get the script to work, downgrade my version of auto it? Edited January 2, 2009 by oldguy Link to comment Share on other sites More sharing options...
ptrex Posted January 2, 2009 Share Posted January 2, 2009 @oldguy Maybe you can get you going. FindClassesByText_New.au3 Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now