Showing posts with label MFC. Show all posts
Showing posts with label MFC. Show all posts

Monday, March 2, 2015

MFC OnPaint() vs OnDraw()

The two are more or less the same. OnPaint is the handler for a WM_PAINT message. OnDraw is the function that a MFC CView window calls when it receives a WM_PAINT message. 

We should use OnDraw if the window is derived from CView, otherwise OnPaint.


OnDraw()
OnPaint()
A member function of CView.

OnDraw is a virtual function. 

OnPaint handler for views call a virtual function OnDraw.

CView::OnDraw

virtual void OnDraw( 
   CDC* pDC  
) = 0

pDC
Points to the device context to be used for rendering an image of the document.


A member function of CWnd.

OnPaint is a WM_PAINT message handler.

CWnd::OnPaint

afx_msg void OnPaint( );