Screen shots

  • Thread starter Thread starter Wayne
  • Start date Start date
W

Wayne

In a Delphi application I would use GetDC passing the handle of the window I
wanted to capture, then with the handle and a caption I would be able to
convert the image to a bitmap. I would like to be able to do this in
C#/.net, but I don't know where to start.

Can someone point me in the right direction?

Thanks
Wayne
 
Wayne,

How you would do it in .NET isn't much different. You would have to
call the same API functions through the P/Invoke layer in order to do this,
as there is no way to get this out of the box.

Hope this helps.
 
try this originally written by me, but modified by Jose Ines

[DllImport("user32.dll")]
extern static IntPtr GetDesktopWindow();

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hwnd);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern UInt64 BitBlt
(IntPtr hDestDC,
int x,
int y,
int nWidth,
int nHeight,
IntPtr hSrcDC,
int xSrc,
int ySrc,
System.Int32 dwRop);

with the code of to do it here...

private Image Capture(){
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
Graphics gr1 = Graphics.FromImage(myImage);
IntPtr dc1 = gr1.GetHdc();
IntPtr dc2 = GetWindowDC(GetDesktopWindow());
BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376);
gr1.ReleaseHdc(dc1);

return myImage;

}
 
Back
Top