Shravani Posted July 1, 2019 Share Posted July 1, 2019 Hi, I tried to use control tree view but unable to click on the item of the tree view, I am new to AutoIT and its been a couple of days I am trying to use all commands related to click but the items do not get clicked. Here is my program. #RequireAdmin #Region #AutoIt3Wrapper_UseX64=n #EndRegion #include<msgboxconstants.au3> #include <GuiTreeView.au3> #include<string.au3> Opt('WinTitleMatchMode', 2) Local $aList = WinList() Local $hWnd = 0 ; Loop through the array displaying only visable windows with a title. For $i = 1 To $aList[0][0] If $aList[$i][0] = "Select Processing to Perform" Then $hWnd = $aList[$i][1] EndIf Next If $hWnd Then MsgBox($MB_SYSTEMMODAL, "", "Window exists", 1) Else MsgBox($MB_SYSTEMMODAL, "", "Window does exists", 1) EndIf ;$sCtrlAdvMode = "[CLASS:SysTreeView32; INSTANCE:1]" $sCtrlAdvMode = "[ID:2070]" Local $hTree = ControlGetHandle($hWnd, "", $sCtrlAdvMode) MsgBox($MB_SYSTEMMODAL, "Treeview handle",$hTree, 1) If $hTree Then MsgBox($MB_SYSTEMMODAL, "", "Tree exists", 1) Else MsgBox($MB_SYSTEMMODAL, "", "Tree doesnot exists") EndIf ;Sleep(2000) WinSetOnTop($hWnd, "", $sCtrlAdvMode) ;Sleep (1000) ;WinSetOnTop("Select Processing to Perform","Tree1", 1) Local $sControl = ControlFocus("Select Processing to Perform", "Tree1", "[CLASS:SysTreeView32; INSTANCE:1]") ;Local $sControl = ControlGetFocus($hWnd) ; Display the control that has keyboard focus. If @error Then ConsoleWrite("ControlFocus = Error= " & $sControl & @CRLF) Else ConsoleWrite("ControlFocus = No Error= " & $sControl & @CRLF) EndIf Local $TreeCount = _GUICtrlTreeView_GetCount ($hTree) ConsoleWrite("Count of the items in tree view = " & $TreeCount & @CRLF) Local $Ret = ControlTreeView($hWnd, "Tree1", "[CLASS:SysTreeView32; INSTANCE:1]", "Collapse" ) ConsoleWrite("Collapse tree Item = " & $Ret & @CRLF) Local $Ret1 = ControlTreeView($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]", "Select", "#3") ConsoleWrite("Select tree Item = " & $Ret1 & @CRLF) Local $Ret2 =_GUICtrlTreeView_GetText($hWnd, 2) ConsoleWrite("Get text = " & $Ret2 & @CRLF) Local $Ret3 = _GUICtrlTreeView_GetSelection($hWnd) ConsoleWrite("Focus= " & $Ret3 & @CRLF) Local $Ret4= _GUICtrlTreeView_ClickItem($hWnd, 2) ConsoleWrite("Click Item = " & $Ret4 & @CRLF) ; Working code for selecting the button*********************************** ;Local $sControl = ControlGetHandle ($hWnd, "", "Button2" ) ;$sControl = ControlGetFocus($hWnd) ; ; Display the control that has keyboard focus. ;MsgBox($MB_SYSTEMMODAL, "", "The control that has keyboard focus in Notepad is: " & $sControl) ;Local $iRet = ControlClick($hWnd, "", $sControl) ;MsgBox($MB_SYSTEMMODAL, "Information", $iRet) ; Working code for selecting the button*********************************** Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 1, 2019 Moderators Share Posted July 1, 2019 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
LarsJ Posted July 1, 2019 Share Posted July 1, 2019 Checkboxes in treeviews (and listviews) are implemented as state images. Therefore you have to use techniques like demonstrated for a listview in this post to automate the checkboxes. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Zedna Posted July 2, 2019 Share Posted July 2, 2019 LarsJ is right but if there are no problems you can use simpler method using: _GUICtrlTreeView_FindItem() or _GUICtrlTreeView_FindItemEx() + _GUICtrlTreeView_SetChecked() Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
gsipos Posted August 25, 2019 Share Posted August 25, 2019 Dear All, I have exactly the same problem for checking and unchecking TreeView (CLASS:SysTreeView32) checkboxes in an external application. I tried four different methods I found so far in the forums but none of them worked. ControlTreeView _GUICtrlTreeView_SetChecked _GUICtrlTreeView_SetStateImageIndex ControlSysTreeView Bonus (no luck with them) Tried with ControlSend - Hit Space key on the selected item Mouse click on the checkbox Even though the application visually confirms that the checkbox is ticked, also when reading its state it says it is check. However, when executing the target application function related to the given child in the treeview, the app says there is nothing ticked. If I do it manually then the application gets my tick. I could not get it Spyed what messages it requires to have the checkbox really ticked. I am executing the AutoIt app and the target App on Win10 x64. I made sure to use the 32-bit version of AutoIt. Please find below a test code: expandcollapse popup#include <GuiTreeView.au3> #include "r_SysTreeView.au3" ; See: ; From: https://www.autoitscript.com/forum/topic/188897-cannot-check-systreeview32-item/?tab=comments#comment-1356905 ; and this: https://www.autoitscript.com/forum/topic/102481-controlsystreeview-treeviewitem/#comment-727417 Opt("WinTitleMatchMode", 2) ; Match any substring SetProgramme() Func SetProgramme() Local $hMainWnd = WinGetHandle("PowerLed V2.8", "") Local $sTreeViewID = "[CLASS:SysTreeView32; INSTANCE:1]" WinActivate( $hMainWnd ) ; Method #1 ; ControlTreeView -> Check ControlFocus($hMainWnd, "", $sTreeViewID ) ControlTreeView($hMainWnd, "", $sTreeViewID, "Check", "#0|#0" ) ConsoleWrite("ControlTreeView: " ) if ( ControlTreeView($hMainWnd, "", $sTreeViewID, "IsChecked", "#0|#0" ) ) Then ConsoleWrite("Checked" & @CRLF ) Else ConsoleWrite("UnChecked" & @CRLF ) Endif ; Sleep ; Manually uncheck it in the target app ; Method #2 ; _GUICtrlTreeView_SetChecked Local $hTreeView = ControlGetHandle($hMainWnd, "", $sTreeViewID) Local $pItem = _GUICtrlTreeView_FindItem($hTreeView, "0-ScoreBoard") ConsoleWrite("_GUICtrlTreeView_SetChecked: " ) if ( _GUICtrlTreeView_SetChecked($hTreeView, $pItem, True) ) Then ConsoleWrite("Checked" & @CRLF ) Else ConsoleWrite("UnChecked" & @CRLF ) Endif ; Sleep ; Manually uncheck it in the target app ; Method #3 ; _GUICtrlTreeView_SetStateImageIndex ConsoleWrite("_GUICtrlTreeView_SetStateImageIndex: " ) if ( _GUICtrlTreeView_SetStateImageIndex($hTreeView, $pItem, 2) ) Then ConsoleWrite("Checked" & @CRLF ) Else ConsoleWrite("UnChecked" & @CRLF ) Endif ; Sleep ; Manually uncheck it in the target app ; Method #4 ; _GUICtrlTreeView_SetStateImageIndex ; See: ; From: https://www.autoitscript.com/forum/topic/188897-cannot-check-systreeview32-item/?tab=comments#comment-1356905 ; and this: https://www.autoitscript.com/forum/topic/102481-controlsystreeview-treeviewitem/#comment-727417 ConsoleWrite("ControlSysTreeView: " ) ControlSysTreeView($hMainWnd, "", $sTreeViewID, "Select", "#0|#0") Local $iResult = ControlSysTreeView($hMainWnd, "", $sTreeViewID, "IsCheckbox", "#0|#0") ConsoleWrite( $iResult & " | " ) $iResult = ControlSysTreeView($hMainWnd, "", $sTreeViewID, "Check", "#0|#0") ConsoleWrite( $iResult & @CRLF ) EndFunc The output: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "TreeViewCheckboxIssue.au3" ControlTreeView: Checked _GUICtrlTreeView_SetChecked: Checked _GUICtrlTreeView_SetStateImageIndex: Checked ControlSysTreeView: False | False Interesting to note that only the ControlSysTreeView returns false for asking "IsCheckbox" and "Check" command. The target application: I would really appreciate any help to have it resolved. Thank you, Gyula 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