Framework uses OnDraw() code for WM_PAINT processing and for printing document as well. So you provide universal code for both tasks.
In addition to that, there are other differences:
WM_PAINT is a Windows message which is sent to every window in order to have it repainted. With MFC, OnPaint() is just a handler for that message. In response to a WM_PAINT message, your code must call BeginPaint() to obtain a DC, do the drawing, and call EndPaint(). MFC apps can instantiate a CPaintDC in OnPaint(), it wraps the calls to BeginPaint() and EndPaint().
OTOH, OnDraw() is part of the doc/view architecture. It only exists for CView and derived classes. Basically, CView's OnPaint handler instantiates the CPaintDC for you and calls OnDraw() passing in the DC as the pDC param, so you just have to add the drawing code. Furthermore, as Igor already said, it is also called in response to WM_PRINT messages, so you can use the same drawing code for screen and printer output.
In addition to that, there are other differences:
WM_PAINT is a Windows message which is sent to every window in order to have it repainted. With MFC, OnPaint() is just a handler for that message. In response to a WM_PAINT message, your code must call BeginPaint() to obtain a DC, do the drawing, and call EndPaint(). MFC apps can instantiate a CPaintDC in OnPaint(), it wraps the calls to BeginPaint() and EndPaint().
OTOH, OnDraw() is part of the doc/view architecture. It only exists for CView and derived classes. Basically, CView's OnPaint handler instantiates the CPaintDC for you and calls OnDraw() passing in the DC as the pDC param, so you just have to add the drawing code. Furthermore, as Igor already said, it is also called in response to WM_PRINT messages, so you can use the same drawing code for screen and printer output.
本文探讨了WM_PAINT消息处理与OnDraw方法在MFC应用程序中的使用区别。WM_PAINT是Windows消息,用于刷新窗口;而OnDraw是文档/视图架构的一部分,专为CView类及其派生类设计。文章还详细解释了如何实现这两种方法以完成绘图任务,并指出OnDraw也可响应WM_PRINT消息,从而实现屏幕和打印输出的统一绘图代码。
3640

被折叠的 条评论
为什么被折叠?



