Screenshotbitmap

Screenshotbitmap

Post by Peter Kadle » Wed, 16 Apr 2003 17:21:51



How to get a screenshot from the active window using
Visual Basic and then saving this bitmap to a BMP file ?

Thx in advance for any hint on that topic,

peter

 
 
 

Screenshotbitmap

Post by Mike D Sutto » Wed, 16 Apr 2003 19:37:44


Quote:> How to get a screenshot from the active window using
> Visual Basic and then saving this bitmap to a BMP file ?

Grab the handle to the active window with the GetActiveWindow() API call,
then either find it's area on the desktop with GetWindowRect() and blit it
from the desktop window's DC, or try and get the window's DC and blit
directly from there.  You can get the DC associated with a window by calling
GetDC() (Or GetWindowDC() to work with the client area), but remember to
pair it up with a subsequent ReleaseDC() call when you've finished using the
window.
In some cases you can also request the window to draw itself to your
back-buffer by sending it WM_PRINT and WM_PAINT messages, but not all
windows support this.

Here's an example including bitmap saving:
http://groups.google.com/groups?selm=cVxO7.10561%24Sk6.67494%40NewsRe...

Here's one going via an EMF for easy scaling:
http://groups.google.co.uk/groups?selm=uzKAleMyCHA.2536%40TK2MSFTNGP09

Here's an example of the WM_PRINT method:
http://groups.google.co.uk/groups?selm=a6aol7%246u0%241%40newsg4.svr....

Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://www20.brinkster.com/EDais/