示例#1
0
        public IntPtr? CursorHandleGet(int x, int y)
        {
            var pt = new User32.POINT { x = x, y = y };

            User32.ClientToScreen(hwnd, ref pt);
            User32.SetCursorPos(pt.x, pt.y);
            Thread.Sleep(20);
            var info = new User32.CursorInfo();
            info.Size = Marshal.SizeOf(info.GetType());

            if (User32.GetCursorInfo(out info))
                return info.Handle;

            return null;
        }
示例#2
0
        /// <summary>
        /// Creates an Image object containing a screen shot of a specific window
        /// </summary>
        /// <param name="handle">The handle to the window. (In windows forms, this is obtained by the Handle property)</param>
        /// <returns></returns>
        public Bitmap CaptureWindow(IntPtr handle)
        {
            // get te hDC of the target window
            IntPtr hdcSrc = User32.GetWindowDC(handle);

            // get the size
            User32.RECT windowRect = new User32.RECT();
            User32.GetWindowRect(handle, ref windowRect);

            User32.RECT clientRect = new User32.RECT();
            User32.GetClientRect(handle, out clientRect);


            User32.POINT point = new User32.POINT {
                x = 0, y = 0
            };
            User32.ClientToScreen(handle, ref point);

            int x      = point.x - windowRect.left;
            int y      = point.y - windowRect.top;
            int width  = (clientRect.right - clientRect.left);
            int height = (clientRect.bottom - clientRect.top);


            // create a device context we can copy to
            IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
            // select the bitmap object
            IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);

            // bitblt over
            GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, x, y, GDI32.SRCCOPY);
            // restore selection
            GDI32.SelectObject(hdcDest, hOld);
            // clean up
            GDI32.DeleteDC(hdcDest);
            User32.ReleaseDC(handle, hdcSrc);
            // get a .NET image object for it
            Bitmap img = Image.FromHbitmap(hBitmap);

            // free up the Bitmap object
            GDI32.DeleteObject(hBitmap);
            return(img);
        }
示例#3
0
        public IntPtr?CursorHandleGet(int x, int y)
        {
            var pt = new User32.POINT {
                x = x, y = y
            };

            User32.ClientToScreen(hwnd, ref pt);
            User32.SetCursorPos(pt.x, pt.y);
            Thread.Sleep(20);
            var info = new User32.CursorInfo();

            info.Size = Marshal.SizeOf(info.GetType());

            if (User32.GetCursorInfo(out info))
            {
                return(info.Handle);
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// Creates an Image object containing a screen shot of a specific window
        /// </summary>
        /// <param name="handle">The handle to the window. (In windows forms, this is obtained by the Handle property)</param>
        /// <returns></returns>
        public Bitmap CaptureWindow(IntPtr handle)
        {
            // get te hDC of the target window
            IntPtr hdcSrc = User32.GetWindowDC(handle);
            // get the size
            User32.RECT windowRect = new User32.RECT();
            User32.GetWindowRect(handle, ref windowRect);

            User32.RECT clientRect = new User32.RECT();
            User32.GetClientRect(handle, out clientRect);

            User32.POINT point = new User32.POINT { x = 0, y = 0 };
            User32.ClientToScreen(handle, ref point);

            int x = point.x - windowRect.left;
            int y = point.y - windowRect.top;
            int width = (clientRect.right - clientRect.left);
            int height = (clientRect.bottom - clientRect.top);

            // create a device context we can copy to
            IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
            // select the bitmap object
            IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
            // bitblt over
            GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, x, y, GDI32.SRCCOPY);
            // restore selection
            GDI32.SelectObject(hdcDest, hOld);
            // clean up
            GDI32.DeleteDC(hdcDest);
            User32.ReleaseDC(handle, hdcSrc);
            // get a .NET image object for it
            Bitmap img = Image.FromHbitmap(hBitmap);
            // free up the Bitmap object
            GDI32.DeleteObject(hBitmap);
            return img;
        }