Difference between GetDC() and BeginPaint()(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() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GetDC() 和 BeginPaint() 的区别
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
