获取startmenu的屏幕截图 [英] Get screenshot of startmenu

查看:100
本文介绍了获取startmenu的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用bitblt捕获窗口.如果启用了航空主题,则捕获图像的背景为黑色.如果我禁用DWM并捕获窗口,则捕获的图像非常好.

I am using bitblt to to capture a window. If the aero theme is enabled, The background of the captured image is black. If I disable the DWM and capture the window then the captured image is very good.

这是我的代码的一部分.

Here is part of my code.

HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(desktopDC);
HDC windowDC = User32.INSTANCE.GetDC(window);

HWND window= User32Extra.INSTANCE.FindWindow(null, "Start menu");

GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, desktopDC, 0, 0, WinGDIExtra.SRCCOPY );
GDI32Extra.INSTANCE.BitBlt(hdcMemDC,windowBounds.left, windowBounds.top, windowWidth, windowHeight, windowDC, windowBounds.left+windowBounds1.right-windowBounds.right+(windowExtraGap/2), windowBounds.top+windowBounds1.bottom-windowBounds.bottom+(windowExtraGap/2), WinGDIExtra.SRCCOPY);

如何在适当的背景下捕获开始菜单?

How to capture the start Menu with proper background?

还有其他方法可以获取正确的航空窗图像吗?

Are there any other methods to get the proper image of aero window?

推荐答案

使用桌面DC并剪切到窗口

use desktop DC and cut to window

RECT rc, rc2;
GetClientRect(hWnd, &rc);
GetWindowRect(hWnd, &rc2);
int width = rc2.right - rc2.left;
int height = rc2.bottom - rc2.top;
HDC hdcScreen = GetDC(NULL); //!!!! Get desktop DC

HDC     hBmpFileDC = CreateCompatibleDC(hdcScreen);
HBITMAP hBmpFileBitmap = CreateCompatibleBitmap(hdcScreen, width, height);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBmpFileDC, hBmpFileBitmap);
BitBlt(hBmpFileDC, 0, 0, width, height, hdcScreen, rc2.left, rc2.top, SRCCOPY | CAPTUREBLT);
HGDIOBJ prev = SelectObject(hBmpFileDC, hOldBitmap);

SaveBitmap(szLogFilename, hBmpFileBitmap);

DeleteDC(hBmpFileDC);
DeleteObject(hBmpFileBitmap);

另一种变体

RECT rc;
GetClientRect(hWnd, &rc);

int width = rc.right - rc.left;
int height = rc.bottom - rc.top;

HDC hdcScreen = GetDC(hWnd);
////////////////////////////
PrintWindow(hWnd, hdcScreen, 0);
PrintWindow(hWnd, hdcScreen, PW_CLIENTONLY);
////////////////////////////    
HDC     hBmpFileDC = CreateCompatibleDC(hdcScreen);
HBITMAP hBmpFileBitmap = CreateCompatibleBitmap(hdcScreen, width, height);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBmpFileDC, hBmpFileBitmap);
BitBlt(hBmpFileDC, 0, 0, width, height, hdcScreen, 0, 0, SRCCOPY | CAPTUREBLT);
HGDIOBJ prev = SelectObject(hBmpFileDC, hOldBitmap);

SaveBitmap(szLogFilename, hBmpFileBitmap);

DeleteDC(hBmpFileDC);
DeleteObject(hBmpFileBitmap);

在调用任何捕获方法之前,我先调用PrintWindow.它充当重新绘制自身的窗口.结果,屏幕截图将具有正确的图像.两次调用PrintWindow可以得到最稳定的结果.

before call any capture method I call PrintWindow. It acts window to redraw itself. And as a result screen capture will have correct picture. The most stable result I got with double call of PrintWindow.

这篇关于获取startmenu的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆