Part of my evil plans involve custom-drawing the holy living crap out of a ListView control.
The ListView on the left works fine; the blue lines come from that pcdListViewDraw->clrTextBk = RGB( 0xE5, 0xF5, 0xFF );
line of code.
But the ListView on the right goes into if ( pcdListViewDraw->nmcd.dwDrawStage == CDDS_PREPAINT ) {
, which always returns CDRF_NOTIFYITEMDRAW
, but then nothing more.
It never goes into if ( pcdListViewDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT ) {
I’m not sure what else to say about them since there aren’t really any differences. They are both children of main windows, not dialog boxes, so there is no difference in how their return codes are handled. Both have LVS_OWNERDATA and respond to LVN_GETDISPINFOW to draw their texts. I can’t see any reason they would be drawn differently.
The code is simple:
case NM_CUSTOMDRAW : {
LPNMCUSTOMDRAW pcdCustomDraw = reinterpret_cast<LPNMCUSTOMDRAW>(_lParam);
CWidget * pmwSrc = LSW_WIN2CLASS( pcdCustomDraw->hdr.hwndFrom );
if ( pmwSrc ) {
if ( pmwSrc->IsListView() ) {
LPNMLVCUSTOMDRAW pcdListViewDraw = reinterpret_cast<LPNMLVCUSTOMDRAW>(_lParam);
HWND hFrom = pcdCustomDraw->hdr.hwndFrom;
if ( pcdListViewDraw->nmcd.dwDrawStage == CDDS_PREPAINT ) {
return CDRF_NOTIFYITEMDRAW;
}
if ( pcdListViewDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT ) {
if ( pcdListViewDraw->nmcd.dwItemSpec % 2 == 0 ) {
pcdListViewDraw->clrText = ::GetSysColor( COLOR_WINDOWTEXT );
pcdListViewDraw->clrTextBk = RGB( 0xE5, 0xF5, 0xFF );
return CDRF_NEWFONT;
}
}
}
}
return 1;
}
What could cause an evil ListView to go into dwDrawStage == CDDS_PREPAINT
, which always returns CDRF_NOTIFYITEMDRAW
, and then to not go into dwDrawStage == CDDS_ITEMPREPAINT
?
L. Spiro