+#if defined(_WIN32_IE) && _WIN32_IE >= 0x300
+
+WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam)
+{
+ LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
+ NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
+ switch ( nmcd.dwDrawStage )
+ {
+ case CDDS_PREPAINT:
+ // if we've got any items with non standard attributes,
+ // notify us before painting each item
+ //
+ // for virtual controls, always suppose that we have attributes as
+ // there is no way to check for this
+ return IsVirtual() || m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
+ : CDRF_DODEFAULT;
+
+ case CDDS_ITEMPREPAINT:
+ {
+ size_t item = (size_t)nmcd.dwItemSpec;
+ if ( item >= (size_t)GetItemCount() )
+ {
+ // we get this message with item == 0 for an empty control,
+ // we must ignore it as calling OnGetItemAttr() would be
+ // wrong
+ return CDRF_DODEFAULT;
+ }
+
+ wxListItemAttr *attr =
+ IsVirtual() ? OnGetItemAttr(item)
+ : (wxListItemAttr *)m_attrs.Get(item);
+
+ if ( !attr )
+ {
+ // nothing to do for this item
+ return CDRF_DODEFAULT;
+ }
+
+ HFONT hFont;
+ wxColour colText, colBack;
+ if ( attr->HasFont() )
+ {
+ wxFont font = attr->GetFont();
+ hFont = (HFONT)font.GetResourceHandle();
+ }
+ else
+ {
+ hFont = 0;
+ }
+
+ if ( attr->HasTextColour() )
+ {
+ colText = attr->GetTextColour();
+ }
+ else
+ {
+ colText = GetTextColour();
+ }
+
+ if ( attr->HasBackgroundColour() )
+ {
+ colBack = attr->GetBackgroundColour();
+ }
+ else
+ {
+ colBack = GetBackgroundColour();
+ }
+
+ lplvcd->clrText = wxColourToRGB(colText);
+ lplvcd->clrTextBk = wxColourToRGB(colBack);
+
+ // note that if we wanted to set colours for
+ // individual columns (subitems), we would have
+ // returned CDRF_NOTIFYSUBITEMREDRAW from here
+ if ( hFont )
+ {
+ ::SelectObject(nmcd.hdc, hFont);
+
+ return CDRF_NEWFONT;
+ }
+ }
+ // fall through to return CDRF_DODEFAULT
+
+ default:
+ return CDRF_DODEFAULT;
+ }
+}
+
+#endif // NM_CUSTOMDRAW supported
+