#include #include #include #include Opt( "MustDeclareVars", 1 ) Global $hGui,$aColors[100][10], $iRows=100 global $aItems[100][10] global $bItems[100][10] Global $idLV[28] global $hLV global $hLV_listview[28] Global $tText = DllStructCreate( "wchar[100]" ) global $msg,$button_change,$different_color=0 Example() Func Example() ; Create GUI $hGui = GUICreate( "listview changing colors", 850, 800 ) $button_change=GUICtrlCreateButton("change",20,700,120,30) ; Create ListView $idLV[1] = GUICtrlCreateListView( "", 20, 40, 400, 340,$LVS_OWNERDATA, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT ,$LVS_SHOWSELALWAYS, $LVS_REPORT)) $idLV[2] = GUICtrlCreateListView( "", 420, 40, 400, 340,$LVS_OWNERDATA, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT ,$LVS_SHOWSELALWAYS, $LVS_REPORT)) $hLV_listview[1] = GUICtrlGetHandle ( $idLV[1] ) $hLV_listview[2] = GUICtrlGetHandle ( $idLV[2] ) For $i = 0 To 1 _GUICtrlListView_AddColumn( $hLV_listview[1], "Col" & $i, 75 ) _GUICtrlListView_AddColumn( $hLV_listview[2], "Col" & $i, 75 ) Next GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState( @SW_SHOW ) FillArray() FillColors(); and put the data in the listview Sleep(10); because its to fast... FillColors2(); put the data in the second listview ; Message loop while 1 $msg = GUIGetMsg() Select Case $msg =$GUI_EVENT_CLOSE ExitLoop Case $msg = $button_change FillArray() $different_color=1 FillColors() EndSelect wend EndFunc Func FillArray() For $i = 0 To $iRows - 1 For $j = 0 To 1; aantal kolommen $aItems[$i][$j] = $i & "|" & $j Next Next For $i = 0 To $iRows - 1 For $j = 0 To 1; aantal kolommen $bItems[$i][$j] = $i & "|" & "OK" Next Next EndFunc Func FillColors() For $i_row_in_listview = 0 To $iRows - 1 For $i_column_in_listview = 0 To 1 if $i_row_in_listview =2 then if $different_color=0 Then $aColors[$i_row_in_listview ][$i_column_in_listview] = "0xFFFFFF" Else $aColors[$i_row_in_listview ][0] = "0x0000FF"; kolom =0 EndIf Else $aColors[$i_row_in_listview ][$i_column_in_listview] = "0xCCFFFF" endif Next Next $hLV=$hLV_listview[1] GUICtrlSendMsg( $idLV[1], $LVM_SETITEMCOUNT, $iRows, 0 ) EndFunc Func FillColors2() For $i_row_in_listview = 0 To $iRows - 1 For $i_column_in_listview = 0 To 1 if $i_row_in_listview =2 then if $different_color=0 Then $aColors[$i_row_in_listview ][$i_column_in_listview] = "0xFFFFFF" Else $aColors[$i_row_in_listview ][0] = "0x0000FF"; kolom =0 EndIf Else $aColors[$i_row_in_listview ][$i_column_in_listview] = "0xCCFFFF" endif Next Next $hLV=$hLV_listview[2] $aItems=$bItems GUICtrlSendMsg( $idLV[2], $LVM_SETITEMCOUNT, $iRows, 0 ) EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hLV Switch $iCode Case $LVN_GETDISPINFOW ; Fill virtual listview Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $sItem = $aItems[DllStructGetData($tNMLVDISPINFO,"Item")][DllStructGetData($tNMLVDISPINFO, "SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) DllStructSetData( $tNMLVDISPINFO, "Text", DllStructGetPtr( $tText ) ) EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before painting a subitem ;Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index ;Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", $aColors[$iItem][$iSubItem] ) ; Backcolor of item/subitem DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", $aColors[DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec")][DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem")] ) Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc