GetDC() 和 BeginPaint() 之间的区别

发布于 2024-11-04 09:15:00 字数 75 浏览 2 评论 0原文

我正在研究 Win32 UI。我想知道 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

紫轩蝶泪 2024-11-11 09:15:00

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

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

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

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.

许仙没带伞 2024-11-11 09:15:00

GetDC()不能替代Begin+EndPaint()。如果您尝试,您会发现您的 UI 线程开始消耗 100% 的 cpu 核心,并且您的 WM_PAINT 处理程序被一遍又一遍地调用。

最重要的是BeginPaint(),它清除窗口的更新区域。 PAINTSTRUCT.rcPaint 的值。只要窗口有脏矩形,WM_PAINT 就会生成,该脏矩形是由窗口管理器或程序显式调用它的 InvalidateRect() 调用创建的。 BeginPaint() 清除它。

GetDC() is not a substitute for Begin+EndPaint(). If you try, you'll find that your UI thread starts to burn 100% cpu core and your WM_PAINT handler getting called over and over again.

The big one is BeginPaint(), it clears the update region of the window. The value of PAINTSTRUCT.rcPaint. WM_PAINT is generated as long as the window has a dirty rectangle, created by an InvalidateRect() call by either the window manager or your program explicitly calling it. BeginPaint() clears it.

喜你已久 2024-11-11 09:15:00

BeginPaint 旨在仅在响应 WM_PAINT 消息时调用。它获得的设备上下文指向窗口的无效(要重绘)区域。然后应该使用 EndPaint 释放它。

GetDC 可以随时调用。它获得的设备上下文指向窗口的整个客户区。要释放它,您应该调用ReleaseDC

BeginPaint is intended to be called only in response to WM_PAINT message. The device context obtained by it points to the invalidated (to-be-redrawn) area of the window. It should be then released using EndPaint.

GetDC can be called at any time. The device context obtained by it points to the whole client area of the window. To release it, you should call ReleaseDC.

洛阳烟雨空心柳 2024-11-11 09:15:00

如果我们在wm_paint之外使用hdc,我们使用get_dc/relese_dc,如果我们在wm_paint内部使用hdc,我们使用begin_paint/end_paint。

If we use hdc outside of wm_paint, we use get_dc/relese_dc, and if we use hdc inside of wm_paint, we use begin_paint/end_paint.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文