We help IT Professionals succeed at work.

avoid Erase on Custom Draw

ronibr
ronibr asked
on
Hi Everybody !

I have a tree control and I catch Custom Draw messages.

LRESULT  CTreeListBox::OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{    

   switch (pCustomDraw->nmcd.dwDrawStage)
  {
      case CDDS_PREPAINT:
    CDC dc;
   dc.Attach(pCustomDraw->nmcd.hdc);
    dc.FillRect(&rcClient,&backcolor_brush);
     return CDRF_NOTIFYITEMDRAW;
   
     case CDDS_ITEMPREPAINT:
     return CDRF_SKIPDEFAULT;
   }
         
  return 0;
}

I'm doing FillRect and paiting the whole client area when I get the Prepaint notification.
But I have a problem.
It seems like the Client area is erased on each cycle of Custom Draw messages.
(and then painted again with the FillRect call).

My questions is:
 How can I get the CDDS_PREERASE  notification ?
and more important
How can I avoid the erase cycle every times I refresh the Tree Control ,
so that i wouldnt have to fillrect again and again ?
I want to avoid the erasing of the backcolor of my control.

Thanks for any help.
Ron

Comment
Watch Question

Commented:
Did you try to use function Invalidate() instead OnCustomDraw()?
BRONZE EXPERT
Author of the Year 2009

Commented:
One reference said that CDDS_PREERASE was used only by the toolbar control.

But I don't understand something... why are you erasing the entire client area?

>>I want to avoid the erasing of the backcolor of my control

perhaps what you really want is to keep the background color from flashing to white before you overwrite it with your custom color.

If so, you should try to handle the WM_CTLCOLOR message or use CDC::SetBkColor in an early draw stage.

-- Dan

Commented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "kamarey, DanROllins" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Force-accepted by
Netminder
CS Moderator

DanRollins: points for you at http://experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20280730

Explore More ContentExplore courses, solutions, and other research materials related to this topic.