Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
Global $g_hListView, $countcheck = 0
Local $hGUI, $hImage
$hGUI = GUICreate("(UDF Created) ListView Create", 400, 300)
Global $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268,$LVS_REPORT)
_GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR( $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUISetState(@SW_SHOW)
; Charge des images
$hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x0000FF, 16, 16))
_GUICtrlListView_SetImageList($g_hListView, $hImage, 1)
; Ajoute des colonnes
_GUICtrlListView_InsertColumn($g_hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($g_hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($g_hListView, 2, "Column 3", 100)
_GUICtrlListView_InsertColumn($g_hListView, 3, "Column 4", 100)
; Ajoute des éléments
_GUICtrlListView_AddItem($g_hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($g_hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($g_hListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($g_hListView, "Row 3: Col 1", 2)
Global $g_hStatus = _GUICtrlStatusBar_Create($hGUI)
$countcheck = _GUICtrlListView_GetItemCount($g_hListView)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Boucle jusqu'à ce que l'utilisateur quitte.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
; Local $tBuffer
$hWndListView = $g_hListView
If Not IsHWnd($g_hListView) Then $hWndListView = GUICtrlGetHandle($g_hListView)
$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_ITEMCHANGED
Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
Local $iItem = DllStructGetData($tInfo, "Item")
Local $Changed = DllStructGetData($tInfo, "NewState")
Local $Changed1 = DllStructGetData($tInfo, "OldState")
Local $yCount = 0
For $i = 0 To $countcheck - 1
If _GUICtrlListView_GetItemChecked ( $hWndFrom, $i) Then
$yCount += 1
EndIf
Next
_DebugPrint("OldState " & $Changed1 &">NewState "& $Changed &">item "& $iItem & " coché "& _GUICtrlListView_GetItemChecked($g_hListView, $iItem)&">>nombre " & $yCount & @CR)
UpdateStatusBar($yCount)
Return False
Case $NM_CLICK
; Envoyé par un contrôle ListView quand l'utillisateur clique sur un élément avec le bouton gauche de la souris
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
$rep = Not _GUICtrlListView_GetItemChecked ( $hWndFrom, DllStructGetData($tInfo, "Index") )
_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 )
_GUICtrlStatusBar_SetText($g_hStatus, _GUICtrlStatusBar_GetText ( $g_hStatus, 0 ) & @TAB & @TAB & _GUICtrlListView_GetItemText( $hWndFrom, DllStructGetData($tInfo, "Index") ))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"+======================================================" & @CRLF & _
"++>Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
Func UpdateStatusBar($iChecked)
Local $iSelected = 0
Local $iItemCount = $countcheck
Local $sText = ''
; Lignes sélectionnées
$iSelected = _GUICtrlListView_GetSelectedCount($g_hListView)
$sText = $iSelected & " ligne sélectionnée"
If $iSelected > 1 Then $sText &= "s"
If @UserName Then _GUICtrlStatusBar_SetText($g_hStatus, $sText)
$sText1 = $iChecked & " case cochée"
If $iChecked > 1 Then $sText &= "s"
If @UserName Then _GUICtrlStatusBar_SetText($g_hStatus, $sText1 & " " & $sText)
EndFunc ;==>UpdateStatusBar
à priori, je dirais que c'est moins énergivore mais ça reste à prouver...