How do I apply a background color AND bitmap to the ListView Column Header using only the WinAPI

I have code for a listview that places a sort direction bitmap (asc or desc) based on the last column click. Someone told me that if I wanted to supply my own color to the listview header buttons I would have to subclass the control and use FillRect with the color and Drawtext to set the column header text. When I do this the sort icons go away. When I remove the subclassing the sort icons re appear.

Any ideas. This is the code I use to apply the sort icons.
SUB SetHeaderIcons(hDlg AS DWORD, lCtrlID AS DWORD, lSortCol AS LONG)

  LOCAL hCtrl     AS DWORD
  LOCAL hColCtrl  AS DWORD
  LOCAL lIndex    AS LONG
  LOCAL tHDItem   AS HD_ITEM
  DIM X$(100)

  ' get handle of list view so we can then get handle of header
  CONTROL HANDLE hDlg, lCtrlID TO hCtrl
  hCtrl = ListView_GetHeader(hCtrl)
  ' set the format and image for each header
  FOR lIndex = 0 TO Header_GetItemCount(hCtrl) - 1
    tHDItem.mask = %HDI_FORMAT OR %HDI_IMAGE
    IF lIndex = ABS(lSortCol&) - 1 THEN
        ' this is the column being sorted on so set it to use an image
      'IF lIndex = 4 OR lIndex = 5 OR lIndex = 10 THEN
      IF VAL(PARSE$(X$(lIndex + 1),"|",4)) = 1 THEN
        tHDItem.fmt = %HDF_STRING OR %HDF_IMAGE OR %HDF_BITMAP_ON_RIGHT OR %LVCFMT_RIGHT
      ELSE
        tHDItem.fmt = %HDF_STRING OR %HDF_IMAGE OR %HDF_BITMAP_ON_RIGHT
      END IF
    ELSE
        ' this isn't the column being sorted on so set it to text only
      'IF lIndex = 4 OR lIndex = 5 OR lIndex = 10 THEN
      IF VAL(PARSE$(X$(lIndex + 1),"|",4)) = 1 THEN
        tHDItem.fmt = %HDF_STRING OR %LVCFMT_RIGHT
      ELSE
        tHDItem.fmt = %HDF_STRING
      END IF
    END IF
    ' set the image index from the imagelist attached to the header
    tHDItem.iImage = IIF&(lSortCol& < 0, 1, 0)
    ' apply changes
    Header_SetItem hCtrl, lIndex, tHDItem
  NEXT lIndex
END SUB

Open in new window

LVL 1
bob_mechlerProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

puranik_pCommented:
You have to set your control as Owner Draw and then handle the event NM_CUSTOMDRAW  to get the control of various stages of draw operations of the whole list.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bob_mechlerProgrammerAuthor Commented:
No WINAPI examples given. I had to subclass the control to gain access to the header control's drawing features.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.