本文介绍了GetDC() 和 BeginPaint() 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Win32 用户界面.我想知道 GetDC 和 BeginPaint 之间的区别.何时使用哪个 API,何时不使用哪个 API.

I am working on Win32 UI. I want to know the difference Between GetDC and BeginPaint. When to Use which API and when not to use which API.

推荐答案

GetDC 只是将句柄返回到设备上下文,可以随时随地使用它来进行自己的绘图.另一方面,BeginPaint 为绘制窗口做准备,并提供关于应该绘制什么的信息(例如背景是否需要重新绘制以及需要绘制的矩形).

GetDC simply returns the handle to the device context, which can be used any time anywhere to do your own drawing. BeginPaint on the other hand prepares the window for painting, and also provides information on what should be painted (such as whether the background needs repainting and the rect that needs to be painted).

何时使用每个示例?BeginPaint 最常见于 WM_PAINT 处理程序中(MSDN:应用程序不应调用 BeginPaint,除非响应 WM_PAINT 消息.对 BeginPaint 的每个调用都必须对 EndPaint 函数有相应的调用.).GetDC 可以在任何地方使用,所以如果你想在外部窗口上绘图.基本上任何时候不在 WM_PAINT 处理程序中.BeginPaint 和 EndPaint 对插入符号也有一些影响.阅读 msdn 了解更多详情.

Examples of when to use each? BeginPaint is most commonly seen inside WM_PAINT handlers (MSDN: An application should not call BeginPaint except in response to a WM_PAINT message. Each call to BeginPaint must have a corresponding call to the EndPaint function.). GetDC can be used anywhere, so if you want to draw on an external window. Basically anytime thats not in a WM_PAINT handler. BeginPaint and EndPaint also have some affect on the caret. Read msdn for more details.

这篇关于GetDC() 和 BeginPaint() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 00:10