我使用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#中实现了这两种方法,但同样的事情发生在那里。
有很多资源,如:
Capture screenshot of hidden desktop
take a screenshot of a desktop created using createdesktop api
C# – SCREEN CAPTURE WITH VISTA DWM (SHARED DIRECT3D SURFACE)
Window Contents Capturing using WM_PRINT Message
how to capture screen from another desktop?(CreateDesktop)
这也就像一个死的话题,没有新的文章,解释或解决方案。
我已经阅读了大部分但没有运气,这是我认为最接近的尝试。语言对我来说也无关紧要:C#,C ++,Python或.......