[Subclassing ListView] How to receive WM_DRAWITEM event ?
I have a .Net (C#) project for Windows CE 5.
It's a GUI for which I overload all controls (or nearly) to do what I want and to accelerate the creation of screens in the future...
In one of the screens, I have a ListView, "CustomListView" that derives from the Windows ListView.
Here, I would like to display some information in a column such as a progress bar, a flag, etc.
So I would like to draw the lines myself!
As we are in the .Net CF, we can't override the OnPaint method, can we?
What I managed to do is to intercept WM_PAINT Windows message and in my handler, I can draw what I want in the ListView control.
The problem is that it makes me redraw every time the column headers, manage the selected line (I do but the behavior is strange), the scroll, etc...
What I would do is to subscribe to the event which is sent each time a line is drawing!
I understood that it's WM_DRAWITEM, isn't it?
But by default (it's what I understood once again), we don't receive it because it isn't sent.
We must put the property LVS_OWNERDRAWFIXED!
I also add LVS_REPORT ...
Ok, the event seems to be sent (I see header but no line) but I don't receive the WM_DRAWITEM to call my handler and display my rows
See the "Points of Interest" section about halfway down the page.
There are two principal tricks:
1) Force the LVS_OWNERDRAWFIXED style in your control's OnHandleCreated() (aka OnCreate, aka WM_CREATE).
2) In your WndProc, handle WM_DRAWITEM | WM_REFLECT (0x202B) *not* simply WM_DRAWITEM (0x002B).
The rest (drawing the items) is just as you'd expect it to be.