Exemple #1
0
        public static void DoFlashScreen()
        {
            // Ref:
            // http://stackoverflow.com/questions/14385838/draw-on-screen-without-form
            // http://stackoverflow.com/questions/2527679/how-to-clean-up-after-myself-when-drawing-directly-to-the-screen
            WIN32_API.SIZE size;
            size.cx = WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN);
            size.cy = WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN);
            IntPtr     hDC = WIN32_API.GetDC(WIN32_API.GetDesktopWindow());
            Graphics   g   = Graphics.FromHdc(hDC);
            SolidBrush b   = new SolidBrush(Color.White);

            g.FillRectangle(b, new Rectangle(0, 0, size.cx, size.cy));
            g.Dispose();
            WIN32_API.ReleaseDC(WIN32_API.GetDesktopWindow(), hDC);
            WIN32_API.InvalidateRect(IntPtr.Zero, IntPtr.Zero, true);
        }
Exemple #2
0
        public static Bitmap DoScreenShot()
        {
            // Ref: http://stackoverflow.com/questions/158151/how-can-i-save-a-screenshot-directly-to-a-file-in-windows
            WIN32_API.SIZE size;
            size.cx = WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN);
            size.cy = WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN);
            IntPtr hDC       = WIN32_API.GetDC(WIN32_API.GetDesktopWindow());
            IntPtr hMemDC    = WIN32_API.CreateCompatibleDC(hDC);
            IntPtr m_HBitmap = WIN32_API.CreateCompatibleBitmap(hDC, size.cx, size.cy);

            if (m_HBitmap == IntPtr.Zero)
            {
                return(null);
            }
            IntPtr hOld = (IntPtr)WIN32_API.SelectObject(hMemDC, m_HBitmap);

            WIN32_API.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, WIN32_API.SRCCOPY);
            WIN32_API.SelectObject(hMemDC, hOld);
            WIN32_API.DeleteDC(hMemDC);
            WIN32_API.ReleaseDC(WIN32_API.GetDesktopWindow(), hDC);
            return(System.Drawing.Image.FromHbitmap(m_HBitmap));
        }