Пример #1
0
        public void ScreenShot(IntPtr hwnd)
        {
            IntPtr hdcSrc  = User32.GetWindowDC(hwnd);
            IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);

            Rectangle rect = new Rectangle(0, 0, 10, 20);

            User32.GetWindowRect(hwnd, ref rect);

            int width  = rect.Width - rect.X;
            int height = rect.Height - rect.Y;

            IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);

            GDI32.SelectObject(hdcDest, hBitmap);

            if (User32.SupportPrintWindow())
            {
                User32.PrintWindow(hwnd, hdcDest, 0);
            }
            else
            {
                GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, 0x00CC0020);
            }

            bmp = new Bitmap(Image.FromHbitmap(hBitmap),
                             Image.FromHbitmap(hBitmap).Width,
                             Image.FromHbitmap(hBitmap).Height);

            LoadImage("");
            saveImage();
            Cleanup(hwnd, hBitmap, hdcSrc, hdcDest);
        }
Пример #2
0
        // sama kuin ScreenShot, mutta kuvakaappuksessa ei mukana mitään reunuksia
        public void ScreenShotWithoutBorders(IntPtr hwnd)
        {
            IntPtr hdcSrc  = User32.GetWindowDC(hwnd);
            IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);

            Rectangle rect = new Rectangle();

            User32.GetWindowRect(hwnd, ref rect);

            int width  = rect.Width - rect.X - 2 * System.Windows.Forms.SystemInformation.FrameBorderSize.Width;
            int height = rect.Height - rect.Y - (System.Windows.Forms.SystemInformation.CaptionHeight + 2 * System.Windows.Forms.SystemInformation.FrameBorderSize.Width);

            // Debug.WriteLine("ScreenShotWithoutBorders! width: " + width + " height: " + height);

            IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);

            GDI32.SelectObject(hdcDest, hBitmap);

            int starFromX = System.Windows.Forms.SystemInformation.FrameBorderSize.Width;
            int starFromY = System.Windows.Forms.SystemInformation.CaptionHeight + System.Windows.Forms.SystemInformation.FrameBorderSize.Width;

            GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, starFromX, starFromY, 0x00CC0020);

            bmp = new Bitmap(Image.FromHbitmap(hBitmap),
                             Image.FromHbitmap(hBitmap).Width,
                             Image.FromHbitmap(hBitmap).Height);

            LoadImage("");
            saveImage();
            Cleanup(hwnd, hBitmap, hdcSrc, hdcDest);
        }