本文介绍了排查 PrintWindow 为空白的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PrintWindow 捕获非活动窗口的屏幕截图.它适用于计算器和捕获谷歌浏览器,但对于其他一些应用程序,如游戏,它会节省白色区域.

I am trying to capture screenshot of inactive window with PrintWindow. It works correctly for calculator and for capturing Google Chrome, but for some other applications, like games, it saves white area.

PrintWindow 失败的原因可能是什么以及如何验证它们?

What could be the reasons for PrintWindow to fail and how to validate them?

我想要工具报告为什么无法捕获窗口

I want tool to report why window can not be captured

推荐答案

每个窗口都有 WM_PRINT 的默认实现,如果您调用 PrintWindow() 并且不使用 PW_CLIENTONLY 标志,您将使用它.由默认窗口过程 DefWindowProc() 提供.它非常简单,它创建了一个内存 DC 并发送 WM_PAINT.所以你在位图中得到的和你在屏幕上得到的一样.祝大家开心.

Every window has a default implementation for WM_PRINT, you will use it if you call PrintWindow() and don't use the PW_CLIENTONLY flag. Provided by the default window procedure, DefWindowProc(). It is pretty straight-forward, it creates a memory DC and sends WM_PAINT. So what you get in the bitmap is the same you get on the screen. Everybody happy.

但这仅适用于实际使用 WM_PAINT 呈现其内容的窗口.当它没有时芯片会关闭,大多数游戏实际上使用 DirectX 渲染并且以高速率渲染,而不依赖于 WM_PAINT 消息.使用具有 alpha 透明度的分层窗口的程序也不会,您通常可以通过花哨的混合边框识别它们.

But that only works for windows that actually use WM_PAINT to render their content. The chips are down when it doesn't, most any game actually renders with DirectX and does so at a high rate, not relying on WM_PAINT messages. A program that uses a layered window with alpha transparency doesn't either, you can typically recognize them from a fancy blended border.

这样的程序应该做的是为 WM_PRINT/CLIENT 编写自己的消息处理程序,并将它们的表面渲染到设备上下文中.必需,因为默认实现不知道有关 DirectX 表面的 bean.

What such a program should do is write their own message handler for WM_PRINT/CLIENT and render their surface into the device context. Necessary because the default implementation doesn't know beans about DirectX surfaces.

游戏不会这样做,这是他们必须编写的额外代码,几乎没有人实际使用过.您将不可避免地得到一个空位图.当然,您对此无能为力.

Games just don't do this, that's extra code they have to write that just about nobody ever actually uses. You'll inevitably end up with an empty bitmap. Nothing you can do about it of course.

这篇关于排查 PrintWindow 为空白的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 16:42