howto avoid cdc drawing done not in onPaint to be erased?



hi all,
I have a static control in which i want to draw a circle.
I have subclassed the static control to a "CMyStatic" class.
added a CDC member -> CDC * pDC;
Initialize this member in OnMove function ->
void CMyStatic::OnMove(int x, int y)
{
CStatic::OnMove(x, y);

pDC = GetDC();
pDC->SelectStockObject(GRAY_BRUSH);
}
draw an ellipse on mouse click ->
void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
pDC->Ellipse(0,0,100,100) ;

CStatic::OnLButtonDown(nFlags, point);
}

and ran the application.

everything was great till I'ved minimize , or covered the dialog , the
drawing disappeard.
I know i need to do something regurding MemDC ' but i can't find any
sample.

The goal is to draw items dinamically with the mouse or any other
place rather that the OnPaint function/
Please assist.
Yariv

.


Loading