I understand that the onDraw()
function is virtual void which is called automatically via OnPaint()
, which is itself triggered by the WM_PAINT message.
My declaration goes something like this:
myDialog.cpp
void myDialog::OnDraw(CDC* dc)
{
CCustomMemDC pDC(dc);
CExampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
myDialog.h
afx_msg void OnDraw(CDC* dc);
and in my OnPaint()
CDialog::OnPaint();
However I could not get OnDraw to be triggered at all... Could anyone enlighten if this method is correct?
Thanks!
It is not correct. As others have pointed out, OnDraw() is a virtual method of CView and not CDialog. Therefore, your OnDraw() method will never be called.
I don't know why your dialog would have a flicker problem that you would need to mitigate it. If you have a custom control on the dialog that is causing flicker, then you probably need to fix the drawing code in it and possibly add WS_CLIPCHILDREN as a Window Style to your dialog. That will make sure that the background of the custom control is not erased when the dialog executes its WM_ERASEBKGND message.
It makes no sense to override the WM_PAINT of the dialog unless you are really planning to do custom drawing on it. Unless you have a very good reason, don't do it.
If you choose to ignore the advice then add an ON_WM_PAINT() to your message handler to the dialog, and then draw the dialog yourself:
If you really want to use your OnDraw() method, then you could also write OnPaint() like this:
But, the first thing I would do in your situation is try adding the style
WS_CLIPCHILDREN
to your dialog style.