How do I perform BitBlt() to copy a screen region that contains Windows Media Player in win32 C++ programming?

3.2k Views Asked by At

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?

1

There are 1 best solutions below

4
On

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.