When I send LVM_SORTITEMS message to a list view control, I can sort
the items of the list view control.
  And, I can send HDM_SETITEM message to the head control to add/remove
a bitmap triangle indicator. It works OK.

But, I want to "Draw" a triangle indicator:

01: I send HDM_SETITEM message to the head control, change the HDITEM.fmt with HDF_OWNERDRAW
02: In my main window WM_DRAWITEM message, I can not receive the head control's WM_DRAWITEM message.
03: I read the MSDN, the head control only send WM_DRAWITEM to it's parent window.
In a list view control, the head control is the child window of the list view control.
should I subclass the list view control ?

So, how to "Draw" a triangle indicator?

Is there anybody has any idea?

Posted on 2007-12-06 18:55:04 by seasea

I assume your talking about the sort arrows in the header control of the listview. I am not sure if I have ever seen it 'drawn' before as there is no message callback for the header (TIKO), which you need to process WM_PAINT where the drawing would have to take place. You could try to subclass the header but that would be problematic and quite a bit of work when the bitmap method works fine and is more than flexible enough. I suppose you could create a bitmap, draw a triangle on it then assign it to the header button but it hardly seems worth the effort.

To subclass the header and process WM_PAINT you would follow these general steps...

    [*]Obtain the handle of the listview
    [*]Enumerate the listviews child windows
    [*]Obtain the handle to the header control
    [*]Subclass the header control saving the address of it's WndProc
    [*]Process WM_PAINT, sending all other messages to the original WndProc

When processing WM_PAINT you will have to completely draw the header, since it has buttons this may not be that easy as buttons are notoriously difficult to draw. Not really a project that I would attempt as there is a much more efficient and easy way to do it already.

Posted on 2007-12-06 22:46:02 by donkey
 hello, donkey, thank you for your response.

 Your methord may be OK.

 "Draw" a triangle indicator, that is using GDI function to draw the indicator, such as MoveToEx,LineTo....

 I had just complete the "Drawing" a triangle indicator, It works OK.

  • Subclass the list view control

  • In the new list-view-control's proc, I just get WM_DRAWITEM message, and send the WM_DRAWITEM message to the parent window(the main window)

  • In the main window proc, when WM_DRAWITEM message, and the DRAWITEMSTRUCT.hwndItem == head-control, I can use DRAWITEMSTRUCT to draw the item

 It works OK, and I think it works easy than subclassing the head control.

 BTW: hWndHeadControl = GetWindow(hWndListview, GWL_CHILD) , becase the list view control only has one child control.

 ha, donkey, you're warmhearted. thank you.
Posted on 2007-12-07 00:30:51 by seasea
Actually I removed the post by accident, I was meaning to press modify :) At any rate it doesn't work when you add buttons to the header so it's pretty useless. Good idea with your method though...

I would never trust that listviews would only have one child control, I constantly add controls like comboboxes to them.
Posted on 2007-12-07 00:39:15 by donkey
:D I had read the post you just posted and then removed.
ha :lol:

Posted on 2007-12-07 00:42:28 by seasea

I would never trust that listviews would only have one child control, I constantly add controls like comboboxes to them.

Yes, you're right. :thumbsup:
Posted on 2007-12-07 00:50:41 by seasea