When to use OnDraw and when to use OnPaint?

Hi

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
Louis

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.

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…

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:
AfxMessageBox(“Draw”);

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

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?

Sorry, bad joke.
But seriously, OnDraw() passes the current DC, OnPaint() passes nothing. So “mayby” this would give OnPaint() a teeny performance advantage?