Jump to content
Sign in to follow this  
FordsFinest

_GUICtrlTreeView_ClickItem issues

Recommended Posts

I have a macro that works well on 95% of computers. However, I am running into an issue on a couple computers where the _GUICtrlTreeView_ClickItem clicks the wrong item (an item or two below the correct one). Both the ExpandItem and SelectItem command work fine, just the click item is off on these computers (and only their user names). I'm not sure if some temp file somewhere is causing an issue or what. Note, using ONLY selectitem results in inconsistent focusing (item appears focused but the next command won't always work correctly). Hence my need to use the clickitem command.

Any help would be appreciated.

_GUICtrlTreeView_Expand($hWnd, $Array2[$i]) ;Expand $model
    Sleep(250)
    _GUICtrlTreeView_SelectItem($hWnd, $Array2[$i]) ;Select $model
    Sleep(150)
    _GUICtrlTreeView_ClickItem($hWnd, $Array2[$i]) ;Click $model
    Sleep(150)
    EndIf

 

Edited by FordsFinest

Share this post


Link to post
Share on other sites

Are you serious ?  May be giving us a runable script that express the problem would be appropriate.  Not 3 lines of codes with an EndIf taken from nowhere !

Share this post


Link to post
Share on other sites

FordFinest, We have some issues with a few of the commands in the GuiTreeView UDF under Windows 10 64 bit. I had temporarily forgotten that in your previous post about the same subject a month ago. Sorry.

The problem is obvious if you try the example of _GUICtrlTreeView_ClickItem in the help file under Windows 10 64 bit. The _GUICtrlTreeView_ClickItem command (here a double click) simply does not work.

Make a copy of the example. Add the two functions here to the code and replace _GUICtrlTreeView_ClickItem with _GUICtrlTreeView_ClickItem64.

Func _GUICtrlTreeView_ClickItem64($hWnd, $hItem, $sButton = "left", $bMove = False, $iClicks = 1, $iSpeed = 0)
  If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

  Local $tRECT = _GUICtrlTreeView_DisplayRectEx64($hWnd, $hItem, True)
  If @error Then Return SetError(@error, @error, 0)
  ; Always click on the left-most portion of the control, not the center.  A
  ; very wide control may be off-screen which means clicking on it's center
  ; will click outside the window.
  Local $tPoint = _WinAPI_PointFromRect($tRECT, False)
  _WinAPI_ClientToScreen($hWnd, $tPoint)
  Local $iX, $iY
  _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
  Local $iMode = Opt("MouseCoordMode", 1)
  If Not $bMove Then
    Local $aPos = MouseGetPos()
    _WinAPI_ShowCursor(False)
    MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
    MouseMove($aPos[0], $aPos[1], 0)
    _WinAPI_ShowCursor(True)
  Else
    MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
  EndIf
  Opt("MouseCoordMode", $iMode)
  Return 1
EndFunc   ;==>_GUICtrlTreeView_ClickItem

Func _GUICtrlTreeView_DisplayRectEx64($hWnd, $hItem, $bTextOnly = False)
  Local $tRECT = DllStructCreate($tagRECT)
  Local $iRet
  If IsHWnd($hWnd) Then
    ; RECT is expected to point to the item in its first member.
    ;DllStructSetData($tRECT, "Left", $hItem)
    $iRet = @AutoItX64 ? DllStructSetData( DllStructCreate( "ptr", DllStructGetPtr( $tRect ) ), 1, $hItem ) _
                       : DllStructSetData( $tRect, "Left", $hItem )
    If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
      $iRet = _SendMessage($hWnd, $TVM_GETITEMRECT, $bTextOnly, $tRECT, 0, "wparam", "struct*")
    Else
      Local $iRect = DllStructGetSize($tRECT)
      Local $tMemMap
      Local $pMemory = _MemInit($hWnd, $iRect, $tMemMap)
      _MemWrite($tMemMap, $tRECT)
      $iRet = _SendMessage($hWnd, $TVM_GETITEMRECT, $bTextOnly, $pMemory, 0, "wparam", "ptr")
      _MemRead($tMemMap, $pMemory, $tRECT, $iRect)
      _MemFree($tMemMap)
    EndIf
  Else
    If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
    ; RECT is expected to point to the item in its first member.
    DllStructSetData($tRECT, "Left", $hItem)
    $iRet = GUICtrlSendMsg($hWnd, $TVM_GETITEMRECT, $bTextOnly, DllStructGetPtr($tRECT))
  EndIf

  ; On failure ensure Left is set to 0 and not the item handle.
  If Not $iRet Then DllStructSetData($tRECT, "Left", 0)
  Return SetError($iRet = 0, $iRet, $tRECT)
EndFunc   ;==>_GUICtrlTreeView_DisplayRectEx

You haven't shown much code, but I think the two functions will solve your problem. If the code doesn't help then add a new post. The problem can certainly be solved.

For one reason or another, Microsoft has stopped supporting the focused state of a treeview item. However, the dotted focus rectangle is still displayed. This is not an AutoIt problem.

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.

  • Similar Content

    • By FUD
      hello 
      please i need help 
      i need to open link in default browser only one windows without duplicate if i try to open the same link 
       
      thanks 
    • By YogendraAtluri
      Hi, 
      I am new to AutoIT scripting and I am still learning. I am trying to communicate with a Labview application that acts like a server. it basically takes commands from the client. But for some commands, it also send back some data. 
      When i am sending commands from my script, i can see that the labview is getting them. But i am not able to get anything back. I tried different code pieces that are available online in the forum.
      This is the working piece of code which i been using to send data.
      #cs This module is used to establish tcp connection with lab view #ce #include <File.au3> Func SendCmd($cmd) TCPStartup() Local $IpAddress="192.168.10.101" Local $Port="5353" $Labview = TCPConnect($IpAddress,$Port) If @error Then ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ).' & @CRLF) TCPCloseSocket($Labview) TCPShutdown() Exit EndIf TCPSend($Labview, $cmd & @CRLF) TCPCloseSocket($Labview) TCPShutdown() EndFunc SendCmd("wt42d")  
      This is slightly modified code to send and receive data, which is not working. I am not getting any response back
      SendCmd("galil") Func SendCmd($cmd) TCPStartup() Local $IpAddress="192.168.10.101" Local $Port="5353" $Labview = TCPConnect($IpAddress,$Port) If @error Then ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ).' & @CRLF) TCPCloseSocket($Labview) TCPShutdown() Exit EndIf TCPSend($Labview, $cmd & @CRLF) $ip = @IPAddress1 ;create listening socket $Listensocket = TCPListen($ip, $Port) ConsoleWrite("Listening to Socket - " & $Listensocket & @CRLF) If $Listensocket = -1 Then ConsoleWrite("Exiting..." & @CRLF) Exit EndIf ;Accept incoming clients and recieve info While 1 $connectedsocket = TCPAccept($Listensocket) ConsoleWrite("Connecting to Socket - " & $connectedsocket & "Error -" & @error & @CRLF) If $ConnectedSocket >= 0 Then $ip2 = TCPRecv($connectedsocket,1000000) EndIf WEnd TCPCloseSocket($connectedsocket) TCPCloseSocket($Labview) TCPShutdown() EndFunc I am not getting anything back. I am getting the following output in the console
      +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. Listening to Socket - 544 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 its going through that loop forever. i need to force stop it.
      But when i open putty and send the same command, i am getting response right away. 
      Can someone please help me with that.
      Thanks in advance
      Regards
      Yogendra
    • By Bhooshan
      I need to mute an ongoing call on Microsoft teams without activating the window. Teams allows us to mute using shortcut key Ctrl+Shift+m but only when the window is active.
      # Used set option as ongoing call can be with any person which leads to change in Title Name.
      AutoItSetOption ( "WinTitleMatchMode", 2 ) 
      # I am not clear with the control ID which will be good to use here and also the key combination of ^M       
      ControlSend ( "Microsoft Teams", "", "[CLASS:Intermediate D3D Window; INSTANCE:1]", "{ctrl down}")
       
      Can anyone help...!!! 
       

    • By Sayed
      Hi there, 
      I'm new in AutoIt forms and using AutoIt to automate desktop application (able to automate the application normally but facing issue when I've to re-run the application twice within the same script...so need help in this please)
      here is the steps then followed by the issue in a brief : 
      1- run application . 
      2- do some actions (click menus,activate windows,set texts..)
      3- close the application. 
      4- run the application again & access the same controls.
      5- open the same windows again (like step 2)
      6- perform some validations (by getting texts from some text boxes)
      7- close the application again (and repeat 1-7 for 15 times in average )
      The issue 
      * all controls are accessible in the first run and actions done successfully on controls (for steps 1-3) BUT from the second run of the application from step-4 it's able to set focus only the main application window.
      Note: only unique properties used to while mapping the controls. 
      Error that appear in the console :
      UIAWrappers.au3" (1673) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $x = Int($t[1] + ($t[3] / 2)) $x = Int($t[1] + (^ ERROR  
      Simple spy code  of one of the controls that has this strange issue(menubar&view menu Item): 
      ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=XXX;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app") ;main app form xxx _UIA_setVar("oP2","Title:=menuStrip1;controltype:=UIA_MenuBarControlTypeId;class:=WindowsForms10.Window.8.app") ;menuStrip1 ;~ $oUIElement=_UIA_getObjectByFindAll("View.mainwindow", "title:=View;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement","Title:=View;controltype:=UIA_MenuItemControlTypeId;class:=") ;ControlType:=UIA_MenuItemControlTypeId;classname:=") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") _UIA_action("oUIElement","highlight") ;~_UIA_action("oUIElement","click")  
       
    • By HenryJiu
      Hello!
      I have a question , about Mac and Autoit3.
      I want to convert my script to Mac App,but Aut2Exe just convert to EXE!
      So I asked if there was a way to convert scripts to MAC App
      My English isn't very good,so don't laugh please😃
×
×
  • Create New...