views:

264

answers:

2

I have a main window with children. I need to take screenshots programmatically to crop and draw them back on my main window. The way I do this is:

HDC hDC = GetWindowDC(hWnd);
HDC memDC = CreateCompatibleDC(hDC);
HBITMAP memBM = CreateCompatibleBitmap(hDC, Width, Height);
HBITMAP OldBM = (HBITMAP)::SelectObject(memDC, memBM );
BitBlt(memDC, 0, 0, Width, Height , hDC, BEGINX, BEGINY, SRCCOPY);
int Bpp = GetDeviceCaps(hDC,BITSPIXEL);
int size = Bpp/8 * ( Width * Height );
BYTE *lpBits = new BYTE[size];
GetBitmapBits(memBM, size, lpBits);

But this doesn't capture the OpenGL section of the child windows, instead it just draws blank white in the area where OGL render is supposed to be.

Any ideas are appreciated.

A: 

I remember having similar problems a few years back when I was attempting to screen grab a video and just getting a black region where the video had been. Got around it at the time by reducing the hardware accelaration setting on the video driver (on XP: right click desktop > properties > settings > advanced > troubleshoot).

As for a code-based solution, you might want to refer to the following previous posts:

http://stackoverflow.com/questions/1439246/blank-screenshots-in-vista-and-win7-when-gaming

http://stackoverflow.com/questions/1858122/saving-a-screenshot-of-a-window-using-c-wpf-and-dwm

Conan
Apparently you can't do that with DWM thumbnails if the source window is child. I am frustrated.
Dogan Demir
A: 

Possibly NQR, but you could render your scene to a bitmap and BLT it into the blank space.

Marcelo Cantos
I don't know but I can't control the child application anyway so I can't try it. You should be able to render to a bitmap I don't see any problems with that. But as I said the OGL window is just some application.
Dogan Demir