Jump to content

Column Header Color


huntpeck
 Share

Recommended Posts

Hi, I feel like this should be easy, and probably is but I'm not able to find it.  I just want to color the column headers of a listview.  They can be the same color just want to make it easier to differentiate from the data.  I've tried a couple of things but hoping someone has a simple answer.  I've included test code I've been using.  Thanks!

#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>
#include "GUIListViewEx.au3"
#include <MsgBoxConstants.au3>

GUICreate("listview items", 220, 250, 100, 200, -1)
Global $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150)
GUICtrlCreateListViewItem("item1|item12|item13", $idListview)
GUICtrlCreateListViewItem("item2|item22|item23", $idListview)
GUICtrlCreateListViewItem("item3|item32|item33", $idListview)
GUICtrlCreateListViewItem("item4|item42|item43", $idListview)
GUICtrlCreateListViewItem("item5|item52|item53", $idListview)
GUICtrlCreateListViewItem("item6|item62|item63", $idListview)


$Test = IsHWnd(_GUICtrlListView_GetHeader($idListview))
;$Test = _GUICtrlListView_GetHeader($idListview)
_GUICtrlListView_SetBkColor($Test, $COLOR_RED)

GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

 

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

huntpeck,

My GUIListViewEx UDF (see link in my sig) allows you to have coloured headers - but it might be a bit OTT to use it just for that.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here a streamlined version :

#include <GuiConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>
#include <Constants.au3>
#include <WinAPISysWin.au3>
#include <WinAPITheme.au3>

Opt('MustDeclareVars', True)

Global $hHeader

Example()

Func Example()
  Local $hGUI = GUICreate("Listview Color Header", 500, 300)
  Local $idListView = GUICtrlCreateListView("Items List|SubList 1|SubList 2", 10, 10, 480, 280)
  _GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
  $hHeader = GUICtrlSendMsg($idListView, $LVM_GETHEADER, 0, 0)

  _WinAPI_SetWindowTheme($hHeader, "", "") ;Turn off theme for header

  Local $iStyle = _WinAPI_GetWindowLong($hHeader, $GWL_STYLE)
  _WinAPI_SetWindowLong($hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT)) ; remove header 3D button effect

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

  _GUICtrlListView_SetColumnWidth($idListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
  _GUICtrlListView_SetColumnWidth($idListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
  _GUICtrlListView_SetColumnWidth($idListView, 2, $LVSCW_AUTOSIZE_USEHEADER)

  GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)
  GUISetState()

  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
  If $tNMHDR.hWndFrom = $hHeader And $tNMHDR.Code = $NM_CUSTOMDRAW Then
    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
    Switch $tCustDraw.dwDrawStage
      Case $CDDS_PREPAINT
        Return $CDRF_NOTIFYITEMDRAW
      Case $CDDS_ITEMPREPAINT
        _WinAPI_SetTextColor($tCustDraw.hDC, 0)
        _WinAPI_SetBkColor($tCustDraw.hDC, 0x00FFFF)
        Return $CDRF_NEWFONT
    EndSwitch
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

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...