I am wondering about the difference between OnDraw()
and OnPaint()
in MFC.
After searching the Internet for a while, I found a useful article. In summary,
WM_PAINT
will triggerOnPaint()
, which callsOnDraw()
and passes aCDC*
:void CView::OnPaint() { // standard paint routine CPaintDC dc(this); OnPrepareDC(&dc); OnDraw(&dc); }
Another article mentions that when printing a document,
OnPrint()
also callsOnDraw()
by passing a printer DC. Therefore, by overridingOnDraw()
, you get screen painting and printing both in one function, which is convenient.
I tried to put my statements for drawing in either OnDraw()
and OnPaint()
. Either can work well. OnDraw()
is a little easier because it has already gotten a pointer pDC
.