jos*_*736 5 c++ windows winapi screenshot
我正在尝试截取Chrome窗口的屏幕截图.它看起来像这样:

当我PrintWindow用来获取屏幕截图时,我可以在窗口标题栏/ Chrome标签区域看到闪烁.捕获的屏幕截图包含Windows Basic样式的标题栏的奇怪呈现(即使我的机器运行Aero主题):

我注意到其他一些应用程序也表现出类似的行为,它们在屏幕上闪烁,但标题栏工件在捕获的屏幕截图中不可见.执行此操作的应用程序包括Office 2010,IE 10和Trillian选项卡式聊天窗口 - 换句话说,扩展非客户区域的窗口似乎存在此问题.
重现这一点的代码很简单:
void Screenshot(HWND hWnd) {
RECT rc;
GetClientRect(hWnd, &rc);
HDC hdcScreen = GetDC(NULL);
HDC hdc = CreateCompatibleDC(hdcScreen);
HBITMAP hbmp = CreateCompatibleBitmap(hdcScreen,
rc.right - rc.left, rc.bottom - rc.top);
SelectObject(hdc, hbmp);
//Print to memory hdc
PrintWindow(hWnd, hdc, PW_CLIENTONLY);
}
Run Code Online (Sandbox Code Playgroud)
为什么我会看到闪烁和奇怪的视觉文物?我能做些什么来阻止它?
小智 1
如果启用了 Aero,请改用 BitBlt。
chromium 桌面捕获源代码中的这条评论特别有帮助:
// When desktop composition (Aero) is enabled each window is rendered to a
// private buffer allowing BitBlt() to get the window content even if the
// window is occluded. PrintWindow() is slower but lets rendering the window
// contents to an off-screen device context when Aero is not available.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
863 次 |
| 最近记录: |