Jump to content
Sign in to follow this  
Shravani

Unable to check the item in tree view - (Moved)

Recommended Posts

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***********************************

 

image.png.12b300e14232c6ce672aa3a9770e0d8a.png

image.thumb.png.e1e30d21792cd4cf421c44a300fe04fc.png

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

  1. ControlTreeView
  2. _GUICtrlTreeView_SetChecked
  3. _GUICtrlTreeView_SetStateImageIndex
  4. ControlSysTreeView
  5. Bonus (no luck with them)
    1. Tried with ControlSend - Hit Space key on the selected item
    2. 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:

#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:

image.png.d689e4d95272e3a86453c4acadd80a80.png

2019-08-25_102942.png.192823b396b44439ab45b841d33c9a38.png

I would really appreciate any help to have it resolved.

Thank you,

Gyula

image.png

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...