7

I am taking screenshots of Windows desktop with code such as

HDC     hScreen = GetDC(NULL);
HDC     hDC     = CreateCompatibleDC(hScreen);
HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, w, h);
HGDIOBJ old_obj = SelectObject(hDC, hBitmap);
BOOL    bRet    = BitBlt(hDC, 0, 0, w, h, hScreen, x1, y1, SRCCOPY);

However Windows 10 has multiple desktops. Not only multiple screens like older Windows but desktop switching feature with CTRL+WIN+LEFT/RIGHT I would like to take screenshot of desktop 2 from application running in desktop 1, for instance. My guess is that I should give some parameter in

HDC     hScreen = GetDC(NULL);

I googled but didn't find much examples. Any multiple desktop developers around?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • Isn't the same DC shared between all the virtual desktops so only current gets rendered? I mean that switching between desktops doesn't really switch anything, it just composition manager renders some windows and skips rendering other on the same (non virtual) desktop. Probably to take screenshot of currently not visible virtual desktop you need to switch to this virtual desktop first. – user7860670 Jul 17 '17 at 12:42
  • 3
    @VTT is correct. A window that is not part of the current virtual desktop simply is not drawn anywhere. No amount of BitBlt can capture something that isn't being drawn. – Raymond Chen Jul 17 '17 at 13:06
  • Thanks ! I did some tests that confirm this: inactive desktops are not being drawn – Doof Warrior Jul 19 '17 at 08:08
  • @DoofWarrior does it mean it's not possible ? – user310291 Aug 28 '17 at 06:22
  • @user310291 yes it looks impossible to take a screenshot of a desktop not being shown – Doof Warrior Aug 29 '17 at 09:24
  • Although you can get the content of a window in another virtual desktop using the DWM Thumbnail API. The content is redirected to a destination window that you have to create in the current visible desktop. Once that the destination window starts receiving the frames of the "hidden" window you can take a screenshot. This is like mirroring the window content to another window. – Bemipefe Oct 29 '19 at 17:19

0 Answers0