1

This is a weird problem.

I'm using BitBlt to copy from the device context associated with my (WinForms) window handle to a bitmap, and it works (or so I thought).

But there's one machine where the WPF elements inside ElementHost just don't show up on the bitmap: there isn't a hole, it's just as if they were transparent and whatever is behind appears instead.

I've been playing around with one VM, one working and the other not. They both have the same OS version, I've whittled down the installed Programs and Features to be the same on both, and yet there is still one which works and the other not.

Has anyone come across this problem, and does anyone have any ideas where to start searching?

UPDATE: thanks to jsanalytics tip in the comment, I've worked out that it's Aero which stops the screenshot working properly. Now to work out why and what to do about it...

Benjol
  • 63,995
  • 54
  • 186
  • 268

1 Answers1

1

This isn't the answer, but it's working for me for the moment:

If

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern int DwmIsCompositionEnabled(out bool enabled);

Returns true, then instead of BitBlting the Device context of the window, I BitBlt the whole desktop, but crop to the size of the window (using GetWindowRect and adapting the created Bitmap to the size, then passing left and top into BitBlt).

Benjol
  • 63,995
  • 54
  • 186
  • 268