Search code examples
clistviewwinapiownerdrawn

Does owner draw only work in report mode for ListView?


I want to draw a rectangle around a ListView item when the ListView is in Icon mode, so I started reading about owner draw which I thought that it will solve my problem.

However, I have also read that owner draw only works in Report mode! Is this still the case under newer versions of Windows (Windows XP and later)?

And if this is still the case, then is there another way to draw a rectangle around a ListView item?


Solution

  • Yes, LVS_OWNERDRAWFIXED style is only meaningful for LVS_REPORT case. But there's another way - you can process NM_CUSTOMDRAW notifications that listview sends you. Those are sent for all control modes, and depending on what you want to do you can handle CDDS_ITEMPOSTPAINT notification, use dwItemSpec field as item index, send LVM_GETITEMRECT from within your WM_NOTIFY handler, and do whatever you want with it.