Add a variable, such as a BOOL, to your CStaticGraph class to act as a flag to tell OnPaint() what to do. Initialize the variable in the constructor and change it when the button is clicked. For example:
In the header file for CStaticGraph add:
BOOL m_fButtonPressed;
In the CStaticGraph constructor add:
m_fButtonPressed = FALSE;
In your button click handler do something like:
void CStaticGraph::OnButtonClick()
{
m_fButtonPressed = TRUE;
Invalidate();
}
Then in your OnPaint only draw the graph when flag is set:
void CStaticGraph::OnPaint()
(
CPaintDC dc(this);
if ( m_fButtonPressed )
{
// Clear the window
return;
}
// Draw the graph
. . .
}