View Full Version : When to use OnDraw and when to use OnPaint?

07-11-2000, 12:04 PM

I see in some MFC OpenGl examples that the OnDraw member function is used while others use OnPaint. Are there any obvious reasons?

I experience that when using mouse interaction together with OnDraw implementation there is a lag in response, while when I implement OnPaint the response is smooth???

Thanks in advance

07-11-2000, 08:09 PM
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. So OnPaint is a tiny bit faster, but unless you're trying to get hundreds of frames per second, you should not notice any real difference between the two. Basically, you should use OnDraw if your window is derived from CView, otherwise use OnPaint.

07-11-2000, 09:31 PM
i think if you wanna do speedy OpenGL programs, do it with the Windows API, because there's very much going on behind the MFC-scene. ( message map, command handler, and in W.API you just have a simple switch-statement...). however, it could be cool for making a modelling program becuase of the tool-,dialog,stylebars...

07-12-2000, 03:40 PM
Louis, try this.
Start a new project using the MFC App Wizard.
Just leave everything as the default and let the wizard build the source.

In you're CView's OnDraw() put this:

Now create a message handler for the a WM_PAINT in the CView. The default OnPaint() will be created. Now put this in OnPaint():

Now execute the app, size the window, open a new window (MDI), tile the windows, etc.
How many Draws did you see? Now how many Paints did you see?

07-12-2000, 04:05 PM
Sorry, bad joke. http://www.opengl.org/discussion_boards/ubb/smile.gif
But seriously, OnDraw() passes the current DC, OnPaint() passes nothing. So "mayby" this would give OnPaint() a teeny performance advantage?