Jump to content
Sign in to follow this  
Achilles

GUiCtrlListView and the $GUI_BKCOLOR_LV_ALTERNATE

Recommended Posts

Achilles

I've been trying to apply $GUI_BKCOLOR_LV_ALTERNATE to a listview. I've tried it as a normal style, as an extended style and with GuiCtrlSetState... However it doesn't seem to be working. The helpfile says this:

The special flag $GUI_BKCOLOR_LV_ALTERNATE can be used with Listview control to give alternate background of the ListviewItems lines.

But I'm not sure how to actually apply the "special flag"... Any help would be great...

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

Global $hListView, $hLIstView2
Global $gui, $btn

$gui = GUICreate("ListView Sort", 600, 300)
$hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180)
    GUICtrlSetState(-1, $GUI_BKCOLOR_LV_ALTERNATE)

_AddRow($hListView, "ABC|000666|10.05.2004")
_AddRow($hListView, "DEF|444|11.05.2005")
_AddRow($hListView, "CDE|555|12.05.2004")

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

GUIDelete()

Func _AddRow($hWnd, $sItem)
    Local $aItem = StringSplit($sItem, "|")
    Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], -1, _GUICtrlListView_GetItemCount($hWnd) + 9999)

    For $x = 2 To $aItem[0]
        _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1)
    Next
EndFunc  ;==>_AddRow

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
picaxe

I use a version of this by Siao. I couldn't get $GUI_BKCOLOR_LV_ALTERNATE to work.

Share this post


Link to post
Share on other sites
wraithdu

Basic idea:

#include <GuiConstantsEx.au3>

$GUI = GUICreate("dummy", 100, 400)
$LV = GUICtrlCreateListView("Items", 0, 0, 100, 400)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
For $i = 1 To 10
    GUICtrlCreateListViewItem("Item" & $i, $LV)
    GUICtrlSetBkColor(-1, 0xE6E6E6)
Next
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Edited by wraithdu

Share this post


Link to post
Share on other sites
Achilles

Basic idea:

#include <GuiConstantsEx.au3>

$GUI = GUICreate("dummy", 100, 400)
$LV = GUICtrlCreateListView("Items", 0, 0, 100, 400)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
For $i = 1 To 10
    GUICtrlCreateListViewItem("Item" & $i, $LV)
    GUICtrlSetBkColor(-1, 0xE6E6E6)
Next
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Could you do that with the _GUICtrlListView_AddItem? Or do you have to use GUICtrlCreateListViewitem?

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
rasim

Achilles

Could you do that with the _GUICtrlListView_AddItem?

No. For items created with GuiListView.au3 UDF functions use this code:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>

Global Const $CDDS_SUBITEMPREPAINT = BitOR($CDDS_ITEM, $CDDS_SUBITEM, $CDDS_PREPAINT)

Global $Font1 = _WinAPI_CreateFont(14, 0, 0, 0, $FW_BOLD)
Global $Font2 = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, _
                                   $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "MS Sans Serif")

$hGUI = GUICreate("Test", 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems|", 10, 10, 280, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 2)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($Font1)
_WinAPI_DeleteObject($Font2)

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    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, $hDC
                    
                    Switch $iItem
                        Case 5
                            $hDC = DllStructGetData($tCustDraw, "hdc")
                            
                            If $iSubItem = 0 Then
                                $iColor = RGB2BGR(0xFF0000)
                                _WinAPI_SelectObject($hDC, $Font1)
                                DllStructSetData($tCustDraw, "clrText", $iColor)
                            ElseIf $iSubItem = 1 Then
                                $iColor = RGB2BGR(0x000000)
                                _WinAPI_SelectObject($hDC, $Font2)
                                DllStructSetData($tCustDraw, "clrText", $iColor)
                                DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFF80))
                            ElseIf $iSubItem = 2 Then
                                $iColor = RGB2BGR(0x008080)
                                _WinAPI_SelectObject($hDC, $Font1)
                                DllStructSetData($tCustDraw, "clrText", $iColor)
                                DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFFFF))
                            EndIf
                            Return $CDRF_NEWFONT
                    EndSwitch
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc   ;==>RGB2BGR()

Share this post


Link to post
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
Sign in to follow this  

×