locked
Capturing the Screen

    Question

  • I have a requirement to develop an application that will capture the screenshots of any open window. So if that window is overlappedby some other window partially or fully, is it technically possible to take its screenshots? If yes, the how?


    Thanks in Advance

     


    Adeel
    Friday, March 19, 2010 4:53 AM

All replies

  • Get the handle to the window.

    You could use WindowFromPoint or EnumWindows for this.

     

    Then get the handle to the device context of the window.

    You could use GetDC for this.

     

    You can then save the device context for capturing it.

    Look at the following link -

    http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/dbd7dcf4-a580-4a13-80f2-638ec5edd83b


    «_Superman_»
    Microsoft MVP (Visual C++)
    Friday, March 19, 2010 10:49 AM
  • 
    maverick786us wrote:
    > I have a requirement to develop an application that will capture the screenshots of any open window. So if that window is
    > overlappedby some other window partially or fully, is it technically possible to take its screenshots?
     
    Generally, no. Parts of windows obscured by other windows are not being rendered, so there are no actual pixels to capture. The information necessary to produce an image exists only in internal data structures of the application.
     
    Now, some windows might respond to WM_PRINT or WM_PRINTCLIENT messages, and render themselves to an HDC of your choice. The problem with this is that HDC is process-specific and cannot be passed across process boundaries. So you would have to inject some code into the other application's process that would create an in-memory HDC, send WM_PRINT[CLIENT] message to the window, then somehow transfer the resulting bitmap back to your application. All doable, but a lot of work (and, again, not all windows actually respond to those messages, so this work may be in vain).
    --
    Igor Tandetnik
    Friday, March 19, 2010 12:22 PM