3
votes

I am trying to learn MFC doc-view application. I've started with creating a simple image viewer application. For this I've derived my view class from CScrollView class and overridden the draw() function.

I wanted to know when to use OnPaint() function and how it is related with draw() function.

1

1 Answers

4
votes

You shouldn't need both an OnPaint and OnDraw function in the same view. According to Microsoft's documentation:

When a view becomes invalid, Windows sends it a WM_PAINT message. The view's OnPaint handler function responds to the message by creating a device-context object of class CPaintDC and calls your view's OnDraw member function. You do not normally have to write an overriding OnPaint handler function.

By splitting the drawing code into its own function, the framework allows you to reuse it for both painting the screen and printing.