clearing a CDC
-
A graph was drawn using a CDC on a class derived from CWnd. This was done in OnPaint(). I want to clear this graph when the user presses a button. What code do I ned in the button press? thanks, sb
You don't clear the CDC, you just 'ask' for a repaint, that will erase everything. You can call Invalidate() for that.
Cédric Moonen Software developer
Charting control -
You don't clear the CDC, you just 'ask' for a repaint, that will erase everything. You can call Invalidate() for that.
Cédric Moonen Software developer
Charting controlCedric Moonen wrote: just 'ask' for a repaint, that will erase everything We all know what you meant but what you typed is a different story ;) I'm just reading it from the thread issuer's view and if they take you literally, they'll just call Invalidate() in their button pressed handler which will ultimately generate the call to the OnDraw which drew the graph in the first place effectively redrawing it once again. I'm guessing what you meant to say was in the button pressed handler, set some member variable to false like... // declaration BOOL m_bDrawGraph; // constuctor m_bDrawGraph=TRUE; // On button pressed handler m_bDrawGraph=FALSE; Invalidate(); // OnDraw if (m_bDrawGraph) { // Draw the graph, etc... } else { // OnEraseBackground already cleared the background // but you are free to draw something else here etc... } /* Don't forget that what goes up, must come down. Make sure to provide some mechanism, such as another button and another handler to set the m_bDrawGraph=TRUE when you want to see the graph again. Don't forget to Invalidate() to force a redraw. IMPORTANT: Remember that OnDraw gets called frequently, even when you did not explicitly call Invalidate(). OnDraw needs to know what to draw in your client area at any moment when someone drags another window over your window which effectively wipes out part of the graph so Windows politely Invalidates for you to "redraw" the graph. */ Anyway, I apologize for the clarification but I hope it helps a little.