I have trouble with getting my custom drawing within a SDK treeview to work.
The data that is represented in my treeview has icons and colors. Certain items are represented by an icon, others only by their color. In order to get the color to show I "overdraw" each icon where the item should have a color by using FillRect. The size is calculated by the bounding rectangle of the item's text.
This works perfectly until I move the scrollbar quickly up and down. In the end the colored rectangles are not painted anymore and the whole HDC seems to be messed up (such as context menus of other programs display black parts instead of menu entries).
What I do (deleted some code lines for simplicity):
Code:
llplvcd = (LPNMLVCUSTOMDRAW)lParam;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
return CDRF_NOTIFYPOSTPAINT;
break;
case CDDS_ITEMPOSTPAINT:
TreeView_GetItemRect(ctrl->hCtrl, (HTREEITEM) lplvcd->nmcd.dwItemSpec, &rect, 1);
SetBkColor(lplvcd->nmcd.hdc, RGB(0x00, 0x88, 0xFF));
FillRect(lplvcd->nmcd.hdc, &item_rect, CreateSolidBrush(RGB(r, g, b))); //r, g, b calculated from RGB above
return 1; // or CDDS_SKIPDEFAULT / _DODEFAULT?
}
What I don't know is, what should ITEMPOSTPAINT return? All my google searches returned tons of information on all the other drawstages but none on the ITEMPOSTPAINT. Am I doing something wrong in general? One thing I was suspecting is that the treeview generates so many messages that the messageloop can't keep up.
The whole program works, if I comment the CDDS_ITEMPOSTPAINT part. So the error has to be there.
Thanks allot in advance for any help.
Manuel