添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to capture screen of a child window and render it on parent surface in Windows 7.

HTHUMBNAIL thumbnail = NULL;
HRESULT hr = S_OK;
hr = DwmRegisterThumbnail( hWnd, visualHwnd, &thumbnail );
if( SUCCEEDED( hr ) )

This fails all the time. visualHwnd is the child window and hWnd is the parent. I also tried it without the parent-child relationship and it just doesn't draw anything, well expected because if statement fails.

What could be the reason?

Here is how I create the parent:

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

And the child:

CreateProcessA( NULL, "PVFOX.exe \"view3.pv\" ", NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &piVisual);
WaitForInputIdle( piVisual.hProcess, INFINITE );
Sleep( 3000 );
EnumWindows(EnumWindowsProc, 0);
SetParent(visualHwnd, hWnd);
  • hwndDestination

    The handle to the window that will use the DWM thumbnail. Setting the destination window handles to anything other than a top level window type will result in an E_INVALIDARG.

  • hwndSource

    The handle to the window to as the thumbnail source. Setting the source window handles to anything other than a top level window type will result in an E_INVALIDARG.

  • This is expected to fail if you pass a child window.

    Man this Win API just keeps getting more inconvenient. Do you know of a way to capture a part of the child window that is running OpenGL in it - with the OpenGL? (It comes out blank normally) I also asked the question here: stackoverflow.com/questions/2143854/… – Dogan Demir Jan 27, 2010 at 18:44 No, I don't. Doesn't windowed OpenGL disable the DWM anyway (back to Windows Basic Theme)? In which case DwmRegisterThumbnail will fail anyway. If OpenGL does disable DWM, this implies that it is bypassing the traditional GDI stack and rendering directly to screen, which means Wndows is not aware of the contents of the window and therefore cannot capture it. – Michael Jan 27, 2010 at 18:48 This window draws opengl only on part of its window, kind of like a 3D modelling software, with the GUI. So no, it doesn't disable DWM. – Dogan Demir Jan 27, 2010 at 18:53

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.