Jump to content

Recommended Posts

Posted

I have a script that I'd like to use to click on a subitem in a ListView.  So far I have this:

_GUICtrlListView_ClickItem($chnd,0,"left",False,1)

...which happily clicks on the entire Item, highlighting the row, which has 3 subitems:

image.png.c180e43c984c172d0870d8a3b24592a3.png

In this case I would like to click on the middle one of the three.

I can use _GUICtrlListView_SetItem as such:

_GUICtrlListView_SetItem($chnd, 500,0,1)

...which sends 500 to the top row, subitem 1, which is the middle box.  But ClickItem doesn't appear to allow me to select a subitem.  Is there a way around this?

This is an engine control application, not a game, btw.

Thank you as always for any help that you might have.

 

Posted

I have a script that I'd like to use to click on a subitem in a ListView.  So far I have this:

_GUICtrlListView_ClickItem($chnd,0,"left",False,1)

...which happily clicks on the entire Item, highlighting the row, which has 3 subitems:

image.png.c180e43c984c172d0870d8a3b24592a3.png

In this case I would like to click on the middle one of the three.

I can use _GUICtrlListView_SetItem as such:

_GUICtrlListView_SetItem($chnd, 500,0,1)

...which sends 500 to the top row, subitem 1, which is the middle box.  But ClickItem doesn't appear to allow me to select a subitem.  Is there a way around this?

This is an engine control application, not a game, btw.

Thank you as always for any help that you might have.

 

Posted (edited)

In AutoIt is implemented only click on (whole) Item not subitem as you can see in sources of related UDFs:

; GUIListView.au3

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

    _GUICtrlListView_EnsureVisible($hWnd, $iIndex, False)
    Local $tRECT = _GUICtrlListView_GetItemRectEx($hWnd, $iIndex, $LVIR_LABEL)
    Local $tPoint = _WinAPI_PointFromRect($tRECT, True)
    $tPoint = _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)
EndFunc   ;==>_GUICtrlListView_ClickItem

Func _GUICtrlListView_GetItemRect($hWnd, $iIndex, $iPart = 3)
    Local $tRECT = _GUICtrlListView_GetItemRectEx($hWnd, $iIndex, $iPart)
    Local $aRect[4]
    $aRect[0] = DllStructGetData($tRECT, "Left")
    $aRect[1] = DllStructGetData($tRECT, "Top")
    $aRect[2] = DllStructGetData($tRECT, "Right")
    $aRect[3] = DllStructGetData($tRECT, "Bottom")
    Return $aRect
EndFunc   ;==>_GUICtrlListView_GetItemRect

Func _GUICtrlListView_GetItemRectEx($hWnd, $iIndex, $iPart = 3)
    Local $tRECT = DllStructCreate($tagRECT)
    DllStructSetData($tRECT, "Left", $iPart)
    If IsHWnd($hWnd) Then
        If _WinAPI_InProcess($hWnd, $__g_hLVLastWnd) Then
            _SendMessage($hWnd, $LVM_GETITEMRECT, $iIndex, $tRECT, 0, "wparam", "struct*")
        Else
            Local $iRect = DllStructGetSize($tRECT)
            Local $tMemMap
            Local $pMemory = _MemInit($hWnd, $iRect, $tMemMap)
            _MemWrite($tMemMap, $tRECT, $pMemory, $iRect)
            _SendMessage($hWnd, $LVM_GETITEMRECT, $iIndex, $pMemory, 0, "wparam", "ptr")
            _MemRead($tMemMap, $pMemory, $tRECT, $iRect)
            _MemFree($tMemMap)
        EndIf
    Else
        GUICtrlSendMsg($hWnd, $LVM_GETITEMRECT, $iIndex, DllStructGetPtr($tRECT))
    EndIf
    Return $tRECT
EndFunc   ;==>_GUICtrlListView_GetItemRectEx

LVM_GETITEMRECT

https://msdn.microsoft.com/en-us/windows/desktop/bb761049

 

But in Win32 API for ListView control there is also possibility to get subitem's rectangle so you can quite simply accomodate current UDFs to achieve subitem clicking

so you have to create new function _GUICtrlListView_ClickSubItem() as accomodated copy of _GUICtrlListView_ClickItem() using existing UDF _GUICtrlListView_GetSubItemRect() ...

LVM_GETSUBITEMRECT

https://msdn.microsoft.com/en-us/windows/desktop/bb761075

 

; GUIListView.au3

Func _GUICtrlListView_GetSubItemRect($hWnd, $iIndex, $iSubItem, $iPart = 0)
    Local $aPart[2] = [$LVIR_BOUNDS, $LVIR_ICON]

    Local $tRECT = DllStructCreate($tagRECT)
    DllStructSetData($tRECT, "Top", $iSubItem)
    DllStructSetData($tRECT, "Left", $aPart[$iPart])
    If IsHWnd($hWnd) Then
        If _WinAPI_InProcess($hWnd, $__g_hLVLastWnd) Then
            _SendMessage($hWnd, $LVM_GETSUBITEMRECT, $iIndex, $tRECT, 0, "wparam", "struct*")
        Else
            Local $iRect = DllStructGetSize($tRECT)
            Local $tMemMap
            Local $pMemory = _MemInit($hWnd, $iRect, $tMemMap)
            _MemWrite($tMemMap, $tRECT, $pMemory, $iRect)
            _SendMessage($hWnd, $LVM_GETSUBITEMRECT, $iIndex, $pMemory, 0, "wparam", "ptr")
            _MemRead($tMemMap, $pMemory, $tRECT, $iRect)
            _MemFree($tMemMap)
        EndIf
    Else
        GUICtrlSendMsg($hWnd, $LVM_GETSUBITEMRECT, $iIndex, DllStructGetPtr($tRECT))
    EndIf
    Local $aRect[4]
    $aRect[0] = DllStructGetData($tRECT, "Left")
    $aRect[1] = DllStructGetData($tRECT, "Top")
    $aRect[2] = DllStructGetData($tRECT, "Right")
    $aRect[3] = DllStructGetData($tRECT, "Bottom")
    Return $aRect
EndFunc   ;==>_GUICtrlListView_GetSubItemRect

 

EDIT:

You also have to handle possible horizontal scrolling to get desired column visible if it's not visible due to other columns before that one.

Edited by Zedna

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
  • Recently Browsing   0 members

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