Jump to content

Getting handle to the same ListView Controls


Recommended Posts

A while ago, I posted about two buttons having the same Class Name and Instance number, thus ClassnameNN did not work see http://www.autoitscript.com/forum/index.php?showtopic=84955.

I got it to work using Text, all good.

Now I am trying to get handles to two different ListViews on two tabs (one per tab) where the ClassnameNN for both are TTntListView.UnicodeClass1 (Advanced (Class): [CLASS:TTntListView.UnicodeClass; INSTANCE:1]). There is no text and the IDs are dynamic.

I get the first ListView with the following code but now need to get the second.

Func getSearchResultsListHandle()
    Local $handle = ControlGetHandle($appHandle, "", "TTntListView.UnicodeClass1")
    If $handle == "" Then
        MsgBox(0, "Handle Error", "Search Results List handle not obtained")
    EndIf
    Return $handle
EndFunc   ;==>getSearchResultsListHandleoÝ÷ ØVÓ~¦ÚÙ^Ƨ©Ýëh¶whÁÊÞj×o%¢g­©Ýì!ÈHz0Âä±)ãlº²×¶­"ë
ÚåëAÈú,º¹

I have tried putting in Position, ControlClick Coords as well as the mouse position. I am not sure what Client Coords are, I saw them referred to in the help file under GUIGetCursorInfo so I think they are the mouse position.

The function returns three message boxes which is different from the description - "3 = All 3 ClassNameNN, Control ID, Control Handle"

1.) 329040

2.) TGridPanel2

3.) 0x00050550

Any ideas?

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

  • Moderators

Client coords are the Rect area of the client window itself (not counting Title bar/Menu/etc...), the pure surface area.

To get "Client coords" using the AutoInfo.exe, you go to Options >> Coord Mode >> Client

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

Client coords are the Rect area of the client window itself (not counting Title bar/Menu/etc...), the pure surface area.

To get "Client coords" using the AutoInfo.exe, you go to Options >> Coord Mode >> Client

Thanks for that. I have Client coords enabled and am using the mouse position.

After a lot of stuffing round I have managed to get the TTntGroupBox that the ListView sits in but can't get the ListView. Its a big ListView should be easy to get. I also notice that it sometimes picks up controls that are "underneath" that are on other tabs.

I do use a ControlFocus to display the right ListView before I call _CtrlGetByPos.

Any Ideas?

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

I got it sorted with the following code

Global $Array = _WinGetCtrlInfo($appHandle)
Local $iIndex
Local $controlName = "TTntListView.UnicodeClass"
Local $sColumn = 0
$iIndex = _ArraySearch($Array, $controlName, 0, 0, 1, 1, $sColumn)
Local $sessionListHandle = getSessionListHandle()

MsgBox(0, "Session Count", "Count is " & Int(ControlListView($sessionListHandle, "", "", "GetItemCount")))

Func getSessionListHandle()
;~  Session Results is TTntListView.UnicodeClass2 - index-1
    Local $handle = ""
    $handle = ControlGetHandle($appHandle, "", $Array[$iIndex - 1][1])
    If ($handle == $searchResultsList Or Not StringInStr(String($Array[$iIndex - 1][0]), $controlName)) Then
        MsgBox(0, "", "getSessionListHandle not obtained correctly")
    EndIf
    Return $handle
EndFunc   ;==>getSessionListHandle

As it searches through 282 controls, can anyone think of a quicker way?

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

  • Moderators

Out of curiousity. Have you tried WindowFromPoint API call? There are plenty of examples on the forum.

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

Out of curiousity. Have you tried WindowFromPoint API call? There are plenty of examples on the forum.

Thanks for the suggestion, just tried it out but it only gets the handle to the Window, thus the same as my $appHandle. If I understand correctly the WindowFromPoint function retrieves a handle to the window that contains the specified point, not a handle to a control. Is there a ControlFromPoint or something?

Either way, this is my code - thanks to http://www.autoitscript.com/forum/index.ph...st&p=444962 and http://www.autoitscript.com/forum/index.ph...mp;#entry474934.

AutoItSetOption("MouseCoordMode", 2)
MouseMove(1200, 700)
GetHoveredHwnd()

;====================================================
; Returns the Handle of GUI the mouse is over.
;http://www.autoitscript.com/forum/index.php?s=&showtopic=19370&view=findpost&p=444962
;   
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(), "long", MouseGetPos())
    If IsArray($iRet) Then
        MsgBox(0,"",$iRet[0] & "    " & $iRet[1] & "    " & $iRet[2] & "    " & HWnd($iRet[0] ))
        Return  HWnd($iRet[0])
    else
        Return SetError(1, 0, 0)
    EndIf
EndFunc

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

  • Moderators

Thanks for the suggestion, just tried it out but it only gets the handle to the Window, thus the same as my $appHandle. If I understand correctly the WindowFromPoint function retrieves a handle to the window that contains the specified point, not a handle to a control. Is there a ControlFromPoint or something?

Either way, this is my code - thanks to http://www.autoitscript.com/forum/index.ph...st&p=444962 and http://www.autoitscript.com/forum/index.ph...mp;#entry474934.

AutoItSetOption("MouseCoordMode", 2)
MouseMove(1200, 700)
GetHoveredHwnd()

;====================================================
; Returns the Handle of GUI the mouse is over.
;http://www.autoitscript.com/forum/index.php?s=&showtopic=19370&view=findpost&p=444962
;   
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(), "long", MouseGetPos())
    If IsArray($iRet) Then
        MsgBox(0,"",$iRet[0] & "    " & $iRet[1] & "    " & $iRet[2] & "    " & HWnd($iRet[0] ))
        Return  HWnd($iRet[0])
    else
        Return SetError(1, 0, 0)
    EndIf
EndFuncoÝ÷ Ûú®¢×¢µ¢Ú0º&>§·*.«Þ¶¢¶«ªê-«¨¶ëIÊÞzp¨¢·b«^²X¤{*.ÁêÞv§â)Ú¨®«¨´®¢×(÷«¶Ø^
XШ¢·l¶­ç§r+vɲ¦·z·§qçè­§º¶É«­¢+Ù±¥¹± ÅÕ½Ðí}5½ÕÍ}
½¹Ñɽ±}Ñ%¹½±¥ÅÕ½Ðì°ÄÀ¤()]¡¥±Ä(M±À Áá¤)]¹()Õ¹}5½ÕÍ}
½¹Ñɽ±}Ñ%¹½±¥ ¤(1½°ÀÌØí}¥¹¼ô}5½ÕÍ}
½¹Ñɽ±}Ñ%¹¼ ¤(%ÉɽÈQ¡¸IÑÕɸ(Q½½±Q¥À ÅÕ½Ðí!¹±ôÅÕ½ÐìµÀìÀÌØí}¥¹½lÁtµÀì
I1µÀì|(ÅÕ½Ðí
±ÍÌôÅÕ½ÐìµÀìÀÌØí}¥¹½lÅtµÀì
I1µÀì|(ÅÕ½Ðí5½ÕÍ`A½ÌôÅÕ½ÐìµÀìÀÌØí}¥¹½lÉtµÀì
I1µÀì|(ÅÕ½Ðí5½ÕÍdA½ÌôÅÕ½ÐìµÀìÀÌØí}¥¹½lÍt¤)¹Õ¹()Õ¹}5½ÕÍ}
½¹Ñɽ±}Ñ%¹¼ ¤(1½°ÀÌØí}µÁ½Ìô5½ÕÍÑA½Ì ¤(%ÉɽÈQ¡¸IÑÕɸMÑÉÉ½È Ä°À°À¤(1½°ÀÌØí}ÝÀô±±
±° ÅÕ½ÐíÕÍÈÌȹ±°ÅÕ½Ðì°ÅÕ½Ðí¡Ý¹ÅÕ½Ðì°ÅÕ½Ðí]¥¹½ÝɽµA½¥¹ÐÅÕ½Ðì°ÅÕ½Ðí±½¹ÅÕ½Ðì°ÀÌØí}µÁ½ÍlÁt°ÅÕ½Ðí±½¹ÅÕ½Ðì°ÀÌØí}µÁ½ÍlÅt¤(%ÉɽÈQ¡¸IÑÕɸMÑÉÉ½È È°À°À¤(%1½°ÀÌØíÑ}±ÍÌô±±MÑÉÕÑ
ÉÑ ÅÕ½Ðí¡ÉlÈØÁtÅÕ½Ðì¤(%±±
±° ÅÕ½ÐíUÍÈÌȹ±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½ÐíÑ
±ÍÍ9µÅÕ½Ðì°ÅÕ½Ðí¡Ý¹ÅÕ½Ðì°ÀÌØí}ÝÁlÁt°ÅÕ½ÐíÁÑÈÅÕ½Ðì°±±MÑÉÕÑÑAÑÈ ÀÌØíÑ}±Í̤°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÈØÀ¤(1½°ÀÌØí}ÉÑlÑtôlÀÌØí}ÝÁlÁt°±±MÑÉÕÑÑÑ ÀÌØíÑ}±Ḭ́Ĥ°ÀÌØí}µÁ½ÍlÁt°ÀÌØí}µÁ½ÍlÅut(IÑÕɸÀÌØí}ÉÐ)¹Õ¹
While dissecting this, note that I'm using Screen Coord Mode.

I'm including a function to translate client coordinates into screen coordinates, [0] = x and [1] = y from the return array.

Func _ClientToScreen($h_wnd, $i_x, $i_y)
    ConsoleWrite("here, " & $i_x & "," & $i_y & @CRLF)
    Local $t_point = DllStructCreate("int;int")
    
    DllStructSetData($t_point, 1, $i_x)
    DllStructSetData($t_point, 2, $i_y)
    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $h_wnd, "ptr", DllStructGetPtr($t_point))
    
    Local $a_ret[2] = [DllStructGetData($t_point, 1), DllStructGetData($t_point, 2)]
    ConsoleWrite("here, " & $a_ret[0] & "," & $a_ret[1] & @CRLF)
    Return $a_ret
EndFunc
This is in case you take my advice and use the client coords as suggested.

The first code snippet is just proof of concept for you, you obviously would tear that apart and use it as you see fit.

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

Thanks for that. Bit of a learning curve but i'll see how it goes.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

You are da man SmOke_N! Checking with the info tool, $a_info[0] has the correct handle each time.

I took your advice and made a few tweaks to incorporate your ClientToScreen function.

Thanks heaps for that, it will help me a lot. I put the code up for anyone else after the same thing.

AutoItSetOption("MouseCoordMode", 2)
AdlibEnable("_Mouse_Control_GetInfoAdlib", 10)

While 1
    Sleep(0xFFFFFFF)
WEnd
Func _Mouse_Control_GetInfoAdlib()
    Local $a_info = _Mouse_Control_GetInfo()
    If @error Then Return
    ToolTip("Handle = " & $a_info[0] & @CRLF & _
        "Class = " & $a_info[1] & @CRLF & _
        "Mouse X Pos = " & $a_info[2] & @CRLF & _
        "Mouse Y Pos = " & $a_info[3])
EndFunc

Func _Mouse_Control_GetInfo()
    local $client_mpos = MouseGetPos() ; gets client coords because of "MouseCoordMode" = 2
    Local $a_mpos = _ClientToScreen($appHandle, $client_mpos[0], $client_mpos[1]) ; $a_mpos now screen coords   
    If @error Then Return SetError(1, 0, 0)
    Local $a_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", $a_mpos[0], "long", $a_mpos[1])
    If @error Then Return SetError(2, 0, 0)
    Local $t_class = DllStructCreate("char[260]")
    DllCall("User32.dll", "int", "GetClassName", "hwnd", $a_wfp[0], "ptr", DllStructGetPtr($t_class), "int", 260)
    Local $a_ret[4] = [$a_wfp[0], DllStructGetData($t_class, 1), $a_mpos[0], $a_mpos[1]]
    Return $a_ret
EndFunc
; ===============================================================================
;~ Translates client coordinates into screen coordinates, [0] = x and [1] = y from the return array.
;~ Requires - AutoItSetOption("MouseCoordMode", 2)
;~ Params
;~      $h_wnd - Identifies the window whose client area is used for the conversion.
;~      $i_x - x pos of the client coord
;~      $i_y - Y pos of the client coord
;~ Returns - 
; ===============================================================================
Func _ClientToScreen($h_wnd, $i_x, $i_y)
    ConsoleWrite("here, " & $i_x & "," & $i_y & @CRLF)
    Local $t_point = DllStructCreate("int;int")
    
    DllStructSetData($t_point, 1, $i_x)
    DllStructSetData($t_point, 2, $i_y)
    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $h_wnd, "ptr", DllStructGetPtr($t_point))
    
    Local $a_ret[2] = [DllStructGetData($t_point, 1), DllStructGetData($t_point, 2)]
    ConsoleWrite("here, " & $a_ret[0] & "," & $a_ret[1] & @CRLF)
    Return $a_ret
EndFunc

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...