BeginPaint/EndPaint(CPaintDC)与GetDC(CClientDC)的区别
2017-04-04 21:03
465 查看
在OnPaint函数中,用CClientDC dc(this)代替CPaintDC(this)后,界面不断闪烁。
说明:CClientDC是对GetDC的使用封装, CPaintDC是对BeginPaint/EndPaint的使用封装
原因:BeginPaint/EndPaint会将无效区域设置为NULL, 从而通知系统已经绘制了,不用再发WM_PAINT消息,
而GetDC不会这样做,若在OnPaint函数中直接调用GetDC来获得设备进行绘制,不做其它操作,系统会不断的
发送WM_PAINT消息,从而导致不断重绘而闪烁。
以下摘自MSDN,
BeginPaint sets the update region of a window to NULL. This clears the region, preventing it from generating subsequent WM_PAINT messages. If an application processes a WM_PAINT message but does not call BeginPaint or otherwise clear the update region, the application continues to receive WM_PAINT messages as long as the region is not empty. In all cases, an application must clear the update region before returning from the WM_PAINT message.
After the application finishes drawing, it should call EndPaint. For most windows, EndPaint releases the display device context, making it available to other windows. EndPaint also shows the caret, if it was previously hidden by BeginPaint. BeginPaint hides the caret to prevent drawing operations from corrupting it.
说明:CClientDC是对GetDC的使用封装, CPaintDC是对BeginPaint/EndPaint的使用封装
原因:BeginPaint/EndPaint会将无效区域设置为NULL, 从而通知系统已经绘制了,不用再发WM_PAINT消息,
而GetDC不会这样做,若在OnPaint函数中直接调用GetDC来获得设备进行绘制,不做其它操作,系统会不断的
发送WM_PAINT消息,从而导致不断重绘而闪烁。
以下摘自MSDN,
BeginPaint sets the update region of a window to NULL. This clears the region, preventing it from generating subsequent WM_PAINT messages. If an application processes a WM_PAINT message but does not call BeginPaint or otherwise clear the update region, the application continues to receive WM_PAINT messages as long as the region is not empty. In all cases, an application must clear the update region before returning from the WM_PAINT message.
After the application finishes drawing, it should call EndPaint. For most windows, EndPaint releases the display device context, making it available to other windows. EndPaint also shows the caret, if it was previously hidden by BeginPaint. BeginPaint hides the caret to prevent drawing operations from corrupting it.
相关文章推荐
- BeginPaint/EndPaint(CPaintDC)与GetDC(CClientDC)的区别
- BeginPaint EndPaint 与GetDC ReleaseDC的区别
- BeginPaint EndPaint 与GetDC ReleaseDC的区别
- BeginPaint&&GetDc区别
- 双缓存之BeginPaint&GetDC
- HDC,CDC,CClientDC,CPaintDC,CWindowDC的区别
- HDC,CDC,CPaintDC,CClientDC,CWindowDC区别
- STL front() ,back()和begin(),end()区别
- BeginPaint&&GetDc
- CPaintDC和CClientDC的区别
- CPaintDC\CClientDC\CWindowDC区别
- CDC,CPaintDC,CClientDC,CWindowDC区别
- CDC,CClientDC,CPaintDC,CWindowDC 比较区别
- CDC,CPaintDC,CClientDC,CWindowDC的区别
- MFC中的CDC,CClientDC,CPaintDC,CWindowDC的区别
- CPaintDC和CClientDC又有什么区别?
- 关于CClientDC与CPAINTDC,以及GetDC与GetWindowDC的用法。
- CDC,CPaintDC,CClientDC,CWindowDC的区别
- 关于CClientDC与CPAINTDC,以及GetDC与GetWindowDC的用法。
- CDC,CClientDC,CPaintDC,CWindowDC 比较区别