Code : Tout sélectionner
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
Global $click_item = -1, $click_subitem
Dim $array[3][3]
$array[0][1] = @Autoitexe
$array[0][2] = FileGetVersion(@Autoitexe)
$array[1][1] = "ligne 2, colonne 1"
$array[1][2] = "ligne 2, colonne 2"
$array[2][1] = "ligne 3, colonne 1"
$array[2][2] = "ligne 3, colonne 2"
$gui = GUICreate("listview items", 420, 180, 500, 20, -1)
$listview = GUICtrlCreateListView("icone|colonne 1|colonne 2 ", 10, 10, 400, 130, -1, $LVS_EX_SUBITEMIMAGES+$LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 60)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 1, 200)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 2, 130)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @Autoitexe, 0)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 132)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 138)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
_GUICtrlListView_SetImageList($listview, $hImage, 1)
Dim $ligne[3]
$ligne[0] = GUICtrlCreateListViewItem("|" &$array[0][1] & "| ", $listview)
$ligne[1] = GUICtrlCreateListViewItem("|" &$array[1][1] & "|" , $listview)
$ligne[2] = GUICtrlCreateListViewItem("|" &$array[2][1] & "|" , $listview)
_GUICtrlListView_AddSubItem($listview, 0, "(1)", 0, 0)
_GUICtrlListView_AddSubItem($listview, 1, "(2)", 0, 1)
_GUICtrlListView_AddSubItem($listview, 2, "(3)", 0, 2)
_GUICtrlListView_AddSubItem($listview, 0, $array[0][2], 2, 3)
_GUICtrlListView_AddSubItem($listview, 1, $array[1][2], 2, 4)
_GUICtrlListView_AddSubItem($listview, 2, $array[2][2], 2, 5)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
$hListView = GuiCtrlGetHandle($listView)
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_CLICK ; DBLCLK
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
$click_item = DllStructGetData($tInfo, "Index")
$click_subItem = DllStructGetData($tInfo, "SubItem")
If $click_item<>-1 Then _GUICtrlListView_SetTextColor($hListView, 0)
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iColor
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then
ControlListView($gui, "", $listview, "DeSelect", $iItem)
_GUICtrlListView_SetItemFocused($hListView, $iItem, false)
Return $CDRF_NOTIFYSUBITEMDRAW
EndIf
If $iItem = $click_item and $iSubItem = $click_subitem Then
If $click_subitem = 1 Then
$iColor = RGB2BGR(0x00ff00)
ElseIf $click_subitem = 2 Then
$iColor = RGB2BGR(0xff0000)
EndIf
Else
$iColor = 0
EndIf
DllStructSetData($tCustDraw, "clrText", $iColor)
Return $CDRF_NEWFONT
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR()