Ejemplo n.º 1
0
        /// <summary>
        /// Takes the snapshot of the window owned by a process
        /// </summary>
        /// <param name="name">The process name</param>
        /// <returns>Bitmap object</returns>
        public static Bitmap ProcessSnapshot(string name)
        {
            IntPtr hwnd = IntPtr.Zero;

            foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName(name))
            {
                if (p.MainWindowHandle != IntPtr.Zero)
                {
                    hwnd = p.MainWindowHandle;
                    break;
                }
            }

            if (hwnd == IntPtr.Zero)
            {
                return(null);
            }
            else
            {
                USER32.RECT rc;
                USER32.GetWindowRect(hwnd, out rc);
                Rectangle r      = ApiConverter.ToRectangle(rc);
                Bitmap    bitmap = new Bitmap(r.Width, r.Height, PixelFormat.Format24bppRgb);
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    IntPtr hdcBitmap = g.GetHdc();
                    USER32.PrintWindow(hwnd, hdcBitmap, 0);
                }
                return(bitmap);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Takes a snaphot of a window
 /// </summary>
 /// <param name="hwnd">Handle to the window</param>
 /// <returns>Bitmap object</returns>
 public static Bitmap WindowSnapshot(IntPtr hwnd)
 {
     if (hwnd == IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         USER32.RECT rc;
         USER32.GetWindowRect(hwnd, out rc);
         Rectangle r      = ApiConverter.ToRectangle(rc);
         Bitmap    bitmap = new Bitmap(r.Width, r.Height, PixelFormat.Format24bppRgb);
         using (Graphics g = Graphics.FromImage(bitmap))
         {
             IntPtr hdcBitmap = g.GetHdc();
             USER32.PrintWindow(hwnd, hdcBitmap, 0);
         }
         return(bitmap);
     }
 }