Пример #1
0
        public static Bitmap GetEntireDesktopImage()
        {
            IntPtr m_HBitmap;

            WIN32_API.SIZE size;

            IntPtr hDC    = WIN32_API.GetDC(WIN32_API.GetDesktopWindow());
            IntPtr hMemDC = WIN32_API.CreateCompatibleDC(hDC);

            size.cx = WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN);
            size.cy = WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN);

            m_HBitmap = WIN32_API.CreateCompatibleBitmap(hDC, size.cx, size.cy);

            if (m_HBitmap != IntPtr.Zero)
            {
                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(Image.FromHbitmap(m_HBitmap));
            }
            return(null);
        }
Пример #2
0
        public static Bitmap GetPartialDesktopImage(int x, int y, int w, int h)
        {
            IntPtr m_HBitmap;

            IntPtr hDC    = WIN32_API.GetDC(WIN32_API.GetDesktopWindow());
            IntPtr hMemDC = WIN32_API.CreateCompatibleDC(hDC);

            m_HBitmap = WIN32_API.CreateCompatibleBitmap(hDC, w, h);

            if (m_HBitmap != IntPtr.Zero)
            {
                IntPtr hOld = (IntPtr)WIN32_API.SelectObject(hMemDC, m_HBitmap);
                WIN32_API.BitBlt(hMemDC, 0, 0, w, h, hDC, x, y, WIN32_API.SRCCOPY);
                WIN32_API.SelectObject(hMemDC, hOld);
                WIN32_API.DeleteDC(hMemDC);
                WIN32_API.ReleaseDC(WIN32_API.GetDesktopWindow(), hDC);
                return(Image.FromHbitmap(m_HBitmap));
            }
            return(null);
        }
Пример #3
0
        public static void MoveAndClickMouse(int x, int y)
        {
            // Get screen width and height
            var w = WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN);
            var h = WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN);

            var i = new Input[3];

            i[0].Type             = InputType.INPUT_MOUSE;
            i[0].MouseInput.X     = (x * 65535) / w;
            i[0].MouseInput.Y     = (y * 65535) / h;
            i[0].MouseInput.Flags = (uint)(MouseEventFlags.Absolute | MouseEventFlags.Move);

            i[1].Type             = InputType.INPUT_MOUSE;
            i[1].MouseInput.Flags = (uint)MouseEventFlags.LeftDown;

            i[2].Type             = InputType.INPUT_MOUSE;
            i[2].MouseInput.Flags = (uint)MouseEventFlags.LeftUp;

            SendInput(3, i, Marshal.SizeOf(i[0]));
        }