PioRey Posted July 9, 2010 Share Posted July 9, 2010 Hi All, I'm just new to AutoIt and looking for a code that will focus on the treeview of an application and then get the child node of it. Anyone have an idea? Thanks. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 9, 2010 Share Posted July 9, 2010 Look at _GUICtrlTreeView_GetFirstChild() and the various other _GuiCtrlTreeView* functions in the help file. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PioRey Posted July 14, 2010 Author Share Posted July 14, 2010 Can you give a sample script? The treeview structure on that window is something like this: Application Name | --Groups | ---New Group Name 1 | ---New Group Name 2 | ---New Group Name 3 What I want to do is get the children of the parent node 'Groups'. Thanks. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 14, 2010 Share Posted July 14, 2010 1. ControlGetHandle() to ID the treeview control 2. _GuiCtrlTreeView_FindItem() to ID the 'Groups' item 3. _GuiCtrlTreeView_GetFirstChild() to ID the first child item 4. Loop on _GuiCtrlTreeView_GetNextSibling() to ID successive child items Working demo: expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiTreeView.au3> Global $hGUI, $hTreeView, $hTemp, $idButton $hGUI = GUICreate("TreeView Find Item", 400, 300) $hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 380, 240) $hTemp = _GUICtrlTreeView_Add($hTreeView, 0, "Application") For $x = 0 To 3 _GUICtrlTreeView_Add($hTreeView, $hTemp, StringFormat("[%02d] New Item", $x)) Next $hTemp = _GUICtrlTreeView_AddChild($hTreeView, $hTemp, "Groups") For $x = 4 To 7 _GUICtrlTreeView_Add($hTreeView, $hTemp, StringFormat("[%02d] New Item", $x)) Next For $x = 0 To 9 _GUICtrlTreeView_AddChild($hTreeView, $hTemp, StringFormat("New Group Name [%02d]", $x)) Next $idButton = GUICtrlCreateButton("TEST", 100, 260, 100, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $idButton _GetGroupsChildren() EndSwitch WEnd ; Find all treeview children of "Groups" node ; Note this function discovers its own IDs for the GUI, TreeView, and items Func _GetGroupsChildren() Local $hWnd, $hTV, $hTMP, $sText $hWnd = WinGetHandle("[CLASS:AutoIt v3 GUI; TITLE:TreeView Find Item]", "") $hTV = ControlGetHandle($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]") $hTMP = _GUICtrlTreeView_FindItem($hTV, "Groups") If $hTMP Then $hTMP = _GUICtrlTreeView_GetFirstChild($hTV, $hTMP) If $hTMP Then $sText = _GUICtrlTreeView_GetText($hTV, $hTMP) & " (hwnd = " & $hTMP & ")" While 1 $hTMP = _GUICtrlTreeView_GetNextSibling($hTV, $hTMP) If $hTMP Then $sText &= @CRLF & _GUICtrlTreeView_GetText($hTV, $hTMP) & " (hwnd = " & $hTMP & ")" Else MsgBox(64, "Done", "'Groups' item has the following child items:" & @CRLF & $sText) ExitLoop EndIf WEnd Else MsgBox(16, "Error", "'Groups' item has no child items") EndIf Else MsgBox(16, "Error", "'Groups' item not found") EndIf EndFunc ;==>_GetGroupsChildren Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PioRey Posted July 15, 2010 Author Share Posted July 15, 2010 Thanks for the code, but when I try to apply this, why the controlID of the application always change every time I open it? Is there anyway to know this without going to the Window Info and getting the controlID of that control in the application? Thanks a lot. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 15, 2010 Share Posted July 15, 2010 That's not uncommon for the control ID to change. Use something that doesn't change to get the handle. Note the demo uses "[CLASS:SysTreeView32; INSTANCE:1]" to identify the control. What are you using? What else have you tried? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PioRey Posted July 19, 2010 Author Share Posted July 19, 2010 I finally solve that problem, here's the code: $CntrlID = ControlGetHandle($appName, "", "[CLASS:WindowsForms10.SysTreeView32.app.0.378734a; INSTANCE:1]") now my problem is (since I'm new in AutoIt), how will I send mouse clicks to the application that I want to automate? It has a treeview node of 'Groups', right click on that and select 'Create New Group', a dialog box will open with two textboxes, a Group Name and a Description, I usually put only the Group Name in the textbox and then click the 'OK' button. Can you help me on this? Really appreciate your help. Thanks a lot. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 19, 2010 Share Posted July 19, 2010 Back to the help file: 1. _GUICtrlTreeView_ClickItem() to click on the treeview item. 2. Handle the context menu. 3. Handle the popup dialog. Step (2) might be problematic depending on exactly what kind of context menu comes up, whether it has hot keys available (like "!c" for "&Create"), etc. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PioRey Posted July 21, 2010 Author Share Posted July 21, 2010 Thanks.. got it now.. After creating the script, running it will show the mouse clicks on the screen, want I want to do is hide it. How can I do it in the script? Thanks. 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