我使用创建了第二个桌面CreateDesktop
我不会切换到它。我还在其中创建了一些进程,例如 Explorer.exe 和 Winrar.exe。接下来我有一个代码,它将当前桌面的屏幕截图保存到剪贴板。 CreateDesktop 和 Screenshot 都有效,但是新桌面或窗口的屏幕截图返回黑色位图:
这是桌面中返回当前桌面的窗口的屏幕截图:
// hwnd is handle to winrar or ... created in a new desktop retrieved by EnumDesktopWindow
RECT rc;
GetClientRect(hwnd, &rc);
const HDC hScreenDC = GetDC(nullptr);
const HDC hMemoryDC = CreateCompatibleDC(hScreenDC);
const int width = GetDeviceCaps(hScreenDC, HORZRES);
const int height = GetDeviceCaps(hScreenDC, VERTRES);
const HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, width, height);
HBITMAP(SelectObject(hMemoryDC, hBitmap));
BitBlt(hMemoryDC, 0, 0, width, height, hScreenDC, 0, 0, SRCCOPY);
OpenClipboard(nullptr);
EmptyClipboard();
SetClipboardData(CF_BITMAP, hBitmap);
CloseClipboard();
DeleteDC(hMemoryDC);
DeleteDC(hScreenDC);
我已经在 C# 中实现了这两种方法,但那里发生了同样的事情。
有很多很棒的资源,例如:
捕获隐藏桌面的屏幕截图 https://stackoverflow.com/questions/10375509/capture-screenshot-of-hidden-desktop
使用 createdesktop api 创建桌面的屏幕截图 https://stackoverflow.com/questions/4580520/take-a-screenshot-of-a-desktop-created-using-createdesktop-api
C# – 使用 VISTA DWM 进行屏幕捕获(共享 DIRECT3D 表面) http://spazzarama.com/2009/02/12/screen-capture-with-vista-dwm/
使用 WM_PRINT 消息捕获窗口内容 http://www.fengyuan.com/article/wmprint.html
如何从另一个桌面捕获屏幕?(CreateDesktop) https://stackoverflow.com/questions/5643637/how-to-capture-screen-from-another-desktopcreatedesktop
这也就像一个死主题,没有新文章、解释或解决方案。
我读过其中的大部分,但没有运气,我认为这是我最接近的尝试。另外,语言对我来说并不重要:C#、C++、Python 或...。