Example #1
0
        private static Bitmap GetWindowImage(IntPtr hWnd, Size size)
        {
            Bitmap result;

            try
            {
                if (size.IsEmpty || size.Height < 0 || size.Width < 0)
                {
                    result = null;
                }
                else
                {
                    Bitmap   bitmap   = new Bitmap(size.Width, size.Height);
                    Graphics graphics = Graphics.FromImage(bitmap);
                    IntPtr   hdc      = graphics.GetHdc();
                    WindowSnap.PrintWindow(hWnd, hdc, 0u);
                    graphics.ReleaseHdc();
                    graphics.Dispose();
                    result = bitmap;
                }
            }
            catch
            {
                result = null;
            }
            return(result);
        }
Example #2
0
        private static Bitmap GetWindowImage(IntPtr hWnd, System.Drawing.Size size)
        {
            Bitmap bitmap;

            try
            {
                if (size.IsEmpty || size.Height < 0 || size.Width < 0)
                {
                    bitmap = null;
                }
                else
                {
                    Bitmap   bitmap1 = new Bitmap(size.Width, size.Height);
                    Graphics graphic = Graphics.FromImage(bitmap1);
                    WindowSnap.PrintWindow(hWnd, graphic.GetHdc(), 0);
                    graphic.ReleaseHdc();
                    graphic.Dispose();
                    bitmap = bitmap1;
                }
            }
            catch
            {
                bitmap = null;
            }
            return(bitmap);
        }