2

I've a program that captures a screen region via BitBlt. I was testing it today and discovered that when the screen region contains parts of Windows Media Player then those parts are gray. The rest of the region gets successfully copied to a bitmap.

Here's the code fragment that I use to capture a section of the screen:

    HDC hdc = ::GetDC(NULL); // get the desktop device context
    HDC hDest = CreateCompatibleDC(hdc); // create a device context to use

    // set the height and width of the region
    int height = 800;
    int width = 600;

    // create a bitmap
    HBITMAP hbDesktop = CreateCompatibleBitmap(hdc, width, height);

    // use the previously created device context with the bitmap
    SelectObject(hDest, hbDesktop);

    // copy from the desktop device context (x=100,y=100) to the bitmap device context
    BitBlt(hDest, 0, 0, width, height, hdc, 100, 100, SRCCOPY);

This code fragment captures the screen region of dimensions 800x600 starting at screen point (100, 100).

I put media player with playing movie somewhere in this region and when I get in the output bitmap is a gray region instead of movie player's content.

I wonder if it's possible to BitBlt a screen region at all if it contains a movie player? Is it because Media Player displays content to screen differently than other windows applications?

bodacydo
  • 75,521
  • 93
  • 229
  • 319

1 Answers1

1

It's not possible. Media players (and Windows Media Player in particular) use the video card to draw the video (and often decode the video stream) independently of the CPU. The images aren't even in main memory. DRM also applies here as well.

You can try

BitBlt(hDest, 0, 0, width, height , hdc, 100, 100, SRCCOPY | CAPTUREBLT);

to capture any layered windows, but this isn't guaranteed to work.

Eric Brown
  • 13,774
  • 7
  • 30
  • 71
  • Just curious, I could capture (Alt-PrtScrn) a windowed Media Player playing a sample movie, so if you an Alt-PrtScrn it, you would also be able to `BitBlt` the screen region? Or is Alt-PrtScrn doing something special? – Edward Clements Aug 11 '13 at 07:39
  • Wow that is interesting. I thought the operating system had a buffer that contained the screen as it is. – bodacydo Aug 11 '13 at 17:04
  • Sometimes it does. For video players, though, many times the media player data only exists in the graphics card (and the OS tells the graphics card where to do the overlay); the OS buffer only has the (color-keyed) overlay region. – Eric Brown Aug 11 '13 at 17:33
  • @EdwardClements - Many times the overlay choice depends on the video format & filter layout. If the graphics card doesn't support the video format (or the media player chooses not to offload video decoding to the graphics card), then the video is in CPU accessible memory. BitBlt with the CAPTUREBLT flag might help, but there are still going to be quite a few circumstances where the data simply isn't there to be copied. – Eric Brown Aug 11 '13 at 17:38