You can try getting the desktop window (GetDesktopWindow
) and then getting a device context for it (GetWindowDC
), then create a compatible in-memory device context (CreateCompatibleDC
), create a compatible bitmap from the desktop dc (CreateCompatibleBitmap
), select it in the in-memory dc (SelectObject
) and then do bit-blitting fo the region you are interested from the desktop dc into the in-memory dc(BitBlt
). Don't forget to cleanup after all this.
Oh, and if you are doing this in managed code, you can find all these APIs on PInvoke.net. You'll also need to use Imaging.CreateBitmapSourceFromHBitmap
to copy the bitmap from the native bitmap into the managed bitmap.
I am writing all this from memory; it used to work on XP, but I have not tried it on Vista or Win7.
EDIT: A quick search on the web for ".Net screen capture" returns couple of hits, including this one with sample code in C# and VB.Net.