Note that there are some explanatory texts on larger screens.

plurals
  1. POCapture screenshot of OpenGL/Direct3D 3rd party application
    primarykey
    data
    text
    <p>I want to capture the contents (client area) of a window, in my VS2008, MFC, C++ project. I have tried using the PrintWindow technique described here: <a href="https://stackoverflow.com/questions/7292757/how-to-get-screenshot-of-a-window-as-bitmap-object-in-c">How to get screenshot of a window as bitmap object in C++?</a></p> <p>I have also tried blitting the contents of the window using the following code:</p> <pre><code>void captureWindow(int winId) { HDC handle(::GetDC(HWND(winId))); CDC sourceContext; CBitmap bm; CDC destContext; if( !sourceContext.Attach(handle) ) { printf("Failed to attach to window\n"); goto cleanup; } RECT winRect; sourceContext.GetWindow()-&gt;GetWindowRect(&amp;winRect); int width = winRect.right-winRect.left; int height = winRect.bottom-winRect.top; destContext.CreateCompatibleDC( &amp;sourceContext ); if(!bm.CreateCompatibleBitmap(&amp;sourceContext, width, height)) { printf("Failed to create bm\n"); goto cleanup; } { //show a message in the window to enable us to visually confirm we got the right window CRect rcText( 0, 0, 0 ,0 ); CPen pen(PS_SOLID, 5, 0x00ffff); sourceContext.SelectObject(&amp;pen); const char *msg = "Window Captured!"; sourceContext.DrawText( msg, &amp;rcText, DT_CALCRECT ); sourceContext.DrawText( msg, &amp;rcText, DT_CENTER ); HGDIOBJ hOldDest = destContext.SelectObject(bm); if( hOldDest==NULL ) { printf("SelectObject failed with error %d\n", GetLastError()); goto cleanup; } if ( !destContext.BitBlt( 0, 0, width, height, &amp;sourceContext, 0, 0, SRCCOPY ) ){ printf("Failed to blit\n"); goto cleanup; } //assume this function saves the bitmap to a file saveImage(bm, "capture.bmp"); destContext.SelectObject(hOldDest); } cleanup: destContext.DeleteDC(); sourceContext.Detach(); ::ReleaseDC(0, handle); } </code></pre> <p>The code works fine for most applications. The specific application where I need to capture the screenshot however, has a window that I think is rendered using OpenGl or Direct3D. Both methods will capture most of the app just fine, but the "3d" area will be left black or garbled.</p> <p>I do not have access to the application code, so I cannot change it in any way. </p> <p>Is there any way to capture all the contents, including the "3d" window?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload