2
votes

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);
}
2
Are you sure you want to use MFC?amaurea
i don't want to but i have to for collage. if it would be up to me i would use c#. i actually know how to do thatShawn
You can use CClientDC to do the paining outside OnPaint. It won't persist but will help you draw on every click and will get erased when the background is invalidated.mots_g

2 Answers

6
votes

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

  1. CPaintDC shall be used only inside WM_PAINT handler as it performs BeginPaint()/EndPaint() calls.
  2. All drawing usually shall be performed in overrided CWnd::OnPaint()/CView::OnDraw() method.
  3. 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.
0
votes

if you want repaint using OnRedraw() method is good... in that BeginPaint() and endPaint(); using CPAINTDC create the struct of paint handler