home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 77 / IOPROG_77.ISO / tips / C++ / catturaschermo.cs
Encoding:
Text File  |  2003-12-19  |  1.2 KB  |  49 lines

  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4.  
  5. ///12/12/2003
  6. ///Ing. Antonio Pelleriti
  7. ///compilare con csc catturaschermo.csc
  8. ///eseguire ad esempio catturaschermo c:\temp\cattura.bmp
  9. class CatturaSchermo
  10. {
  11.  
  12.      [DllImport("gdi32.dll")]
  13.      public static extern bool BitBlt(IntPtr hdcDst, int xDst, int yDst, int cx, int cy,
  14.                                       IntPtr hdcSrc, int xSrc, int ySrc, uint ulRop);
  15.  
  16.      public static void Main(string[] args)
  17.      {
  18.          string filename=@"C:\cattura.bmp";
  19.          if(args.Length>0)
  20.             filename=args[0];
  21.  
  22.          Graphics gfxScreen = Graphics.FromHwnd(IntPtr.Zero);
  23.  
  24.          Bitmap bmp = new Bitmap((int) gfxScreen.VisibleClipBounds.Width,
  25.                           (int) gfxScreen.VisibleClipBounds.Height, gfxScreen);
  26.  
  27.          Graphics gfxBitmap = Graphics.FromImage(bmp);
  28.  
  29.          IntPtr hdcScreen = gfxScreen.GetHdc();
  30.          IntPtr hdcBitmap = gfxBitmap.GetHdc();
  31.  
  32.          BitBlt(hdcBitmap,
  33.                 0, 0,
  34.                 bmp.Width, bmp.Height,
  35.                 hdcScreen,
  36.                 0, 0,
  37.                 0x00CC0020);//costante SRCCOPY
  38.  
  39.          gfxBitmap.ReleaseHdc(hdcBitmap);
  40.          gfxScreen.ReleaseHdc(hdcScreen);
  41.  
  42.          gfxBitmap.Dispose();
  43.          gfxScreen.Dispose();
  44.  
  45.          bmp.Save(filename);
  46.      }
  47. }
  48.  
  49.