Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

winapi - Getting screenshot of a child window running OpenGL in it (Windows)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

Blank Screenshots In Vista and Win7 when gaming

Saving a screenshot of a window using C#, WPF, and DWM


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...