Paint problems during scrolling
-
I have a CTreeCtrl derived class which does heavy custom drawing for various styles. One of the style is "Right justified" item, that is a tree item should be drawn at the right most corner of the window. Its an hyperlink as well. I have handled NM_CUSTOMDRAW, and I do painting in PrePaint and say a Skip Default to prevent the custom drawn items to be painted again. The code looks like this (Excerpt only)
GetItemRect(hItem, textRect, TRUE); //this gets the rect for text only GetItemRect(hItem, itemRect, FALSE); //get the text for full item area if ( itemStyle is Right Justified ) { // subtract offset for right justified itemRect.right -= _offsetRTJustifed; itemRect.left = itemRect.right - textRect.Width(); pDC->DrawText(sItemText, &itemRect, DT_LEFT); }
This right justified item is added under a root item and appears when user expands that root item. When the user plays around with the tree items, expanding and collapsing often, the vertical scroll bar appears and disappears as per the number of tree items. Due to this scroll bar appearing/disappearing, the painting of this right justified item gets garbled. (It seems as if the paint messages are lost in between very frequent scroll bar displays/removals).. Its difficult to suggest, but would appreciate if somebody has a clue about it.. ThanksEvil triumphs when good people sit quiet...