I have a list view control and I am trying to do the custom draw for header control. So far so good. This is the code. Sorr, it's D. But I think it's readable for you guys.
Code: Select all
case WM_NOTIFY:
auto nmcd = cast(NMCUSTOMDRAW*) lParam;
switch (nmcd.hdr.code) {
case NM_CUSTOMDRAW :
switch (nmcd.dwDrawStage) {
case CDDS_PREPAINT :
/* When drawing started, system will send a NM_CUSTOMDRAW notification to...
parent of the control. Here, parent of header control is list view. So we...
get the notification with WM_NOTIFY message. We returns the CDRF_NOTIFYITEMDRAW...
value so that system will notify us when the pre paint stage begins for each item.*/
return CDRF_NOTIFYITEMDRAW ; break;
case CDDS_ITEMPREPAINT :
/* So we get the notification at the pre paint statge. We can draw the header...
colors, text and tell the system to not to draw anything on this header. So...
system will skip the default drawing jobs. */
print("item state", nmcd.uItemState); // this will print 0
lv.headerCustomDraw(nmcd);
return CDRF_NEWFONT | CDRF_SKIPDEFAULT;
break;
default : break;
} break;
default : break;
}
break;
Code: Select all
void headerCustomDraw(NMCUSTOMDRAW* nmcd) {
auto colTxt = this.mColumns[nmcd.dwItemSpec].text; // Get the column text
SetBkMode(nmcd.hdc, TRANSPARENT);
auto rct = adjustRect(nmcd.rc,0, -1);
FillRect(nmcd.hdc, &rct, this.mHdrBkBrush ); // Paint the background
if (this.mHdrDrawFC) SetTextColor(nmcd.hdc, this.mHdrFrClrRef); // Set the text color
if (this.mHdrDrawFont) SelectObject(nmcd.hdc, this.mHdrFont.handle);
DrawText(nmcd.hdc, colTxt.toUTF16z, -1, &nmcd.rc, mTxtFlag ) ; // Drawing text again
}
Code: Select all
if ((CDIS_HOT & nmcd.uItemState) == CDIS_HOT) {/* do something */;}
Why I am trying to get the item state ?
Ans : Since I am returning CDRF_SKIPDEFAULT flag, I am responsible for the rest of the drawing job. So I want to change the back color of this header when mouse entered. In order to do that, I must get the item state. Please help. Thanks in advance.