tags:

views:

40

answers:

3

I created a list view class that uses Custom Draw for its rendering. It all works well except that it doesn't render anything. I subclassed its parent window to catch the NM_CUSTOMDRAW notification as a WM_NOTIFY message. However, it appears that WM_NOTIFY is only triggered a few times during creation of the control and never again after that. So the NM_CUSTOMDRAW code is never executed.

I checked with Winspector Spy so see if the control is laid out correctly in the parent window and that seems to be fine.

Does anyone have a clue about what I may be doing wrong?

The code can be found online:

+2  A: 

Why are you drawing text in CDDS_ITEMPOSTPAINT? You should probably draw your text in CDDS_ITEMPREPAINT and return CDRF_SKIPDEFAULT. Also, you should not use the rect in NMCUSTOMDRAW, call ListView_GetItemRect to get the rect you are really after (LVIR_LABEL for text etc)

Anders
Thanks, I'll fix that. But the problem is that I don't receive the NM_CUSTOMDRAW notification at all.
StackedCrooked
A: 

It doesn't look like you're using the LVS_OWNERDRAWFIXED style, which could explain why you don't get owner-draw messages.

Ben Voigt
I believe owner draw is a separate concept from custom draw. Anyway I tried setting the flag and I still don't get the NM_CUSTOMDRAW notification.
StackedCrooked
A: 

I needed to call ShowWindow(mHandle, SW_SHOW); after creating the list view.

Doh!

StackedCrooked
That'll do it. Or use `WS_VISIBLE`.
Ben Voigt