MFC draw Circle

c++, mfc

Solution

No, Windows painting works different way. It's quite asynchronous.

- `CPaintDC` shall be used only inside `WM_PAINT` handler as it performs `BeginPaint()`/`EndPaint()` calls.

- All drawing usually shall be performed in overrided `CWnd::OnPaint()`/`CView::OnDraw()` method.

- On user input (e.g. right mouse button down) your handler shall change state of your class, e.g. set some bool flag `isRightButtonDown` and call `Invalidate()` to initiate asynchronous repainting of window. To enforce synch repainting you could use `UpdateWindow()` or `RedrawWindow()` right after invalidating.

Problem

I just started to learn MFC. I need to draw a circle. If I use OnPaint() it works. What should i do that it will draw on background ? Is this the proper function or should I change it? ``` void Cvaja5Dlg::OnRButtonDown(UINT nFlags, CPoint point) { CPaintDC dc(this); dc.Ellipse(0,0,500,500); CDialogEx::OnRButtonDown(nFlags, point); } ```

Original source