Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OnDraw/OnPaint explanation...

255 views
Skip to first unread message

sftwrdvlpr

unread,
Jul 4, 2002, 2:01:40 PM7/4/02
to
Since I'm kind of a new VC++6.0/MFC programmer can someone explain to me how
OnDraw/OnPaint works in an SDI program? In what sequence are they called?
It's a little confusing as I've read documentation that says override OnDraw
and never OnPaint and others that say the opposite. When do you use
Invalidate? How do hints works? Are you supposed to do all of your drawing
in OnDraw/OnPaint? What mechanism updates the screen when it was previously
covered? I've found that one problem I have is when I use the CFileDialog
and when the user clicks OK, it's supposed to go away. But sometimes it stay
and my program draws on top of what's left, erasing parts of the dialog.

I'm sure all this sounds like very basic stuff, but I'm confused.

Thanks,
Fred

Scott McPhillips

unread,
Jul 4, 2002, 2:54:08 PM7/4/02
to

Every window receives WM_PAINT when Windows determines that it needs
repainting, such as when it is unminimized or another window uncovers
any part of it. You must (re)paint all custom graphics in your window
when this message happens, otherwise your window will not reappear
correctly. In most MFC window classes the OnPaint message handler
function is where you do the painting. Only CView-derived classes have
an OnDraw function. It is simply called by OnPaint to do the drawing.
This provides a design option to call OnDraw in other contexts as well,
such as for painting to a printer.

If the CFileDialog image does not go away it probably means you did not
(re)paint your window in response to WM_PAINT. If your window is
CView-derived do it in OnDraw.

Invalidate is used when you want to force a window to repaint, such as
when the data it renders has changed. Invalidate asks Windows to send
WM_PAINT to the specified window.

Play with the SCRIBBLE tutorial in MSDN to get more familiar with these
issues.

--
Scott McPhillips [VC++ MVP]

Thomas

unread,
Jul 5, 2002, 4:37:40 PM7/5/02
to
Fred,

When I was originally struggling with these issues I happened across
books from Wrox Press, Ltd. In particular I would recommend "Beginning
Visual C++ 6" by Ivor Horton, ISBN: 1-861000-88-X. It is a $50 book in
the stores (Barnes & Noble or Border's), probably cheaper via Amazon.
Horton will walk you through enough of the MFC issues, like OnDraw() and
OnPaint(), that will allow you to subsequently synthesize your own
programs and not be surprised by the outcome.

Thomas

0 new messages