Screen Capture Specific Window

前端 未结 2 1600
不知归路
不知归路 2020-12-06 11:14

Is it possible to screen capture a specific window (also possibly of another process)?

Currently I am capturing the entire desktop of a specific monitor, however wh

相关标签:
2条回答
  • 2020-12-06 11:19

    Yes it is. All what you need is get handle to window which you want to capture and use WinAPI function PrintWindow for example:

    // Get the window handle of calculator application.
    HWND hWnd = ::FindWindow( 0, _T( "Calculator" ));
    
    // Take screenshot.
    PrintWindow( hWnd, getDC(hWnd), 0 );
    

    Here you have PrintWindow documentation.

    0 讨论(0)
  • 2020-12-06 11:34

    Yes, Just as easy as capturing the full screen. You just use GetWindowDC() on the required window rather than GetDesktopWindow(), then BitBlt() from that to your target DC. You can also get the correct size by using GetWindowRect().

    Note that this method also allows you to capture from hidden/covered windows where a full screenshot with a bounding rectangle doesn't.

    See this question for some more details.

    0 讨论(0)
提交回复
热议问题