UDF > GUI > GuiListView >


_GUICtrlListView_SubItemHitTest

Détermine quel élément ou sous-élément d'une ListView est à une position donnée

#include <GuiListView.au3>
_GUICtrlListView_SubItemHitTest ( $hWnd [, $iX = -1 [, $iY = -1]] )

Paramètres

$hWnd ID/handle du contrôle
$iX [optionnel] Position X à tester ou -1 pour utiliser la position actuelle de la souris
$iY [optionnel] Position Y à tester ou -1 pour utiliser la position actuelle de la souris

Valeur de retour

Retourne un tableau avec le format suivant:
    [ 0] - Index de l'élément, de base 0, à la position spécifiée, ou -1
    [ 1] - Index du sous-élément, de base 0, à la position spécifiée, ou -1
    [ 2] - Si True, la position est dans la fenêtre client du contrôle, mais pas sur un élément
    [ 3] - Si True, la position est sur l'icône de l'élément
    [ 4] - Si True, la position est sur le texte de l'élément
    [ 5] - Si True, la position est sur l'image d'état de l'élément
    [ 6] - Si True, la position est quelque part sur l'élément
    [ 7] - Si True, la position est au-dessus de la zone client du contrôle
    [ 8] - Si True, la position est au-dessous de la zone cliente du contrôle
    [ 9] - Si True, la position est à gauche de la zone cliente
    [10] - Si True, la position est à droite de la zone cliente

En relation

_GUICtrlListView_HitTest

Exemple

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

Global $g_idListView, $g_hStatusBar, $g_iIndex = -1, $g_iSubIndex = -1

Example()

Func Example()
    Local $hImage, $hGUI

    ; Crée une GUI
    $hGUI = GUICreate("ListView SubItem Hit Test", 400, 300)
    $g_idListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    $g_idListView = GUICtrlGetHandle($g_idListView) ; get the handle for use in the notify events
    $g_hStatusBar = _GUICtrlStatusBar_Create($hGUI, -1, "")

    ; Installe des styles étendus
    _GUICtrlListView_SetExtendedListViewStyle($g_idListView, $LVS_EX_SUBITEMIMAGES)
    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Charge les images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_idListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_idListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_idListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($g_idListView, $hImage, 1)

    ; Ajoute des colonnes
    _GUICtrlListView_AddColumn($g_idListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($g_idListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($g_idListView, "Column 3", 100)

    ; Ajoute des éléments
    _GUICtrlListView_AddItem($g_idListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($g_idListView, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($g_idListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($g_idListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($g_idListView, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_AddItem($g_idListView, "Row 3: Col 1", 2)

    ; Boucle jusqu'à ce que l'utilisateur quitte.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    GUIDelete()
EndFunc   ;==>Example

Func ListView_Click()
    Local $aHit

    $aHit = _GUICtrlListView_SubItemHitTest($g_idListView)
    If ($aHit[0] <> -1) And (($aHit[0] <> $g_iIndex) Or ($aHit[1] <> $g_iSubIndex)) Then
        _GUICtrlStatusBar_SetText($g_hStatusBar, @TAB & StringFormat("HitTest Item: %d, SubItem: %d", $aHit[0], $aHit[1]))
        $g_iIndex = $aHit[0]
        $g_iSubIndex = $aHit[1]
    EndIf
EndFunc   ;==>ListView_Click

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK 
                    ; Une colonne a été cliquée
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    _DebugPrint("$LVN_COLUMNCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
                    ; Aucune valeur retournée

                Case $LVN_KEYDOWN 
                    ; Une touche a été pressée
                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)
                    _DebugPrint("$LVN_KEYDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->VKey:" & @TAB & DllStructGetData($tInfo, "VKey") & @CRLF & _
                            "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags"))
                    ; Aucune valeur retournée

                Case $NM_CLICK 
                    ; Envoyé par un contrôle ListView quand l'utilisateur clique sur un élément avec le bouton gauche de la souris
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ListView_Click()
                    ; Aucune valeur retournée

                Case $NM_DBLCLK 
                    ; Envoyé par un contrôle ListView quand l'utilisateur double-clique sur un élément avec le bouton gauche de la souris
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; Aucune valeur retournée

                Case $NM_KILLFOCUS 
                    ; Le contrôle a perdu le focus d'entrée
                    _DebugPrint("$NM_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Aucune valeur retournée

                Case $NM_RCLICK 
                    ; Envoyé par un contrôle ListView quand l'utilisateur clique sur un élément avec le bouton droit de la souris
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_RCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; Return 1 ; Interdit le traitement par défaut
                    Return 0 ; Autorise le traitement par défaut

                Case $NM_RDBLCLK 
                    ; Envoyé par un contrôle ListView quand l'utilisateur double-clique sur un élément avec le bouton droit de la souris
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_RDBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; Aucune valeur retournée

                Case $NM_RETURN 
                    ; Le contrôle a le focus d'entrée et l'utilisaeur a pressé la touche ENTER
                    _DebugPrint("$NM_RETURN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Aucune valeur retournée

                Case $NM_SETFOCUS 
                    ; Le contrôle a reçu le focus d'entrée
                    _DebugPrint("$NM_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Aucune valeur retournée
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint