Jump to content

Color a single item in a Listview?


nyke0
 Share

Recommended Posts

Helping with Mikell's code >here :

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

$Form1 = GUICreate("Form1", 350, 250, -1, -1)
$ListView1 = GUICtrlCreateListView("Header|Header|Header", 0, 0, 350, 250)

GuiCtrlCreateListViewItem('Black|Black|Black',$ListView1)
GuiCtrlCreateListViewItem('Black|GREEN?|Black',$ListView1)
GuiCtrlCreateListViewItem('Black|Black|Black',$ListView1)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


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($ListView1)

    Switch $hWndFrom
         Case $hListView
             Switch $iCode
               Case $NM_CUSTOMDRAW
                     Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                     Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
                     If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
                     If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
                     Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
                     Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                     Local $iColor, $iColor2 = RGB2BGR(0xFFFFFF)

                     If $iItem = 1 and $iSubItem = 1 Then
                        $iColor = RGB2BGR(0x00cc00)
                        $iColor2 = RGB2BGR(0xcc00cc)
                    EndIf
                     DllStructSetData($tCustDraw, "clrText", $iColor)    ; text color
                     DllStructSetData($tCustDraw, "clrTextBk", $iColor2) ; background color
                     Return $CDRF_NEWFONT
             EndSwitch
     EndSwitch
    Return $GUI_RUNDEFMSG
 EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
     Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc   ;==>RGB2BGR()
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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