BeginPaint/EndPaint(CPaintDC)与GetDC(CClientDC)的区别

在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. 

转载于:https://www.cnblogs.com/shanql/p/6574388.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值