获取startmenu的屏幕截图

编程入门 行业动态 更新时间:2024-10-15 16:23:25
本文介绍了获取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的屏幕截图

本文发布于:2023-11-30 03:35:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648587.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:截图   屏幕   startmenu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!