home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Drawing;
- using System.Runtime.InteropServices;
-
- ///12/12/2003
- ///Ing. Antonio Pelleriti
- ///compilare con csc catturaschermo.csc
- ///eseguire ad esempio catturaschermo c:\temp\cattura.bmp
- class CatturaSchermo
- {
-
- [DllImport("gdi32.dll")]
- public static extern bool BitBlt(IntPtr hdcDst, int xDst, int yDst, int cx, int cy,
- IntPtr hdcSrc, int xSrc, int ySrc, uint ulRop);
-
- public static void Main(string[] args)
- {
- string filename=@"C:\cattura.bmp";
- if(args.Length>0)
- filename=args[0];
-
- Graphics gfxScreen = Graphics.FromHwnd(IntPtr.Zero);
-
- Bitmap bmp = new Bitmap((int) gfxScreen.VisibleClipBounds.Width,
- (int) gfxScreen.VisibleClipBounds.Height, gfxScreen);
-
- Graphics gfxBitmap = Graphics.FromImage(bmp);
-
- IntPtr hdcScreen = gfxScreen.GetHdc();
- IntPtr hdcBitmap = gfxBitmap.GetHdc();
-
- BitBlt(hdcBitmap,
- 0, 0,
- bmp.Width, bmp.Height,
- hdcScreen,
- 0, 0,
- 0x00CC0020);//costante SRCCOPY
-
- gfxBitmap.ReleaseHdc(hdcBitmap);
- gfxScreen.ReleaseHdc(hdcScreen);
-
- gfxBitmap.Dispose();
- gfxScreen.Dispose();
-
- bmp.Save(filename);
- }
- }
-
-