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() 的区别
基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01