Beispiel #1
0
        public byte[] captureDesktopBytes()
        {
            Win32Functions.RECT windowRect = new Win32Functions.RECT();

            IntPtr hWnd = new IntPtr(Win32Functions.GetDesktopWindow());

            IntPtr hdcSrc = Win32Functions.GetWindowDC((int)hWnd);

            Win32Functions.WINDOWINFO window = new Win32Functions.WINDOWINFO();
            window.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(window);

            Win32Functions.GetWindowRect((int)hWnd, ref windowRect);

            Win32Functions.GetWindowInfo((int)hWnd, ref window);

            // create a bitmap from the visible clipping bounds of
            //the graphics object from the window

            int width = windowRect.right - windowRect.left;

            int height = windowRect.bottom - windowRect.top;

            // create a device context we can copy to
            IntPtr hdcDest = Win32Functions.CreateCompatibleDC(hdcSrc);

            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = Win32Functions.CreateCompatibleBitmap(hdcSrc, width, height);

            //// select the bitmap object
            IntPtr hOld = Win32Functions.SelectObject(hdcDest, hBitmap);

            // bitblt over
            Win32Functions.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0,
                                  Win32Defines.SRCCOPY);
            Win32Functions.CURSORINFO ci = new Win32Functions.CURSORINFO();
            ci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(ci);
            Win32Functions.GetCursorInfo(ref ci);
            Win32Functions.PICONINFO pi = new Win32Functions.PICONINFO();
            Win32Functions.GetIconInfo(ci.hCursor, ref pi);
            Win32Functions.DrawIconEx(hdcDest, ci.point.x - windowRect.left - pi.xHotSpot, ci.point.y - windowRect.top - pi.yHotSpot, (int)ci.hCursor, 0, 0, 0, 0, 3);
            Win32Functions.SelectObject(hdcDest, hOld);
            Win32Functions.ReleaseDC(hWnd, hdcDest);
            Win32Functions.DeleteDC(hdcDest);
            Win32Functions.ReleaseDC(hWnd, hdcSrc);

            byte[] b = new byte[(width * height * 4)];

            Win32Functions.GetBitmapBits(hBitmap, (width * height * 4), b);

            Win32Functions.DeleteObject(hBitmap);

            return(b);
        }
Beispiel #2
0
        public byte[] captureClientBytes(int HWND, int pwidth, int pheight)
        {
            Win32Functions.RECT windowRect = new Win32Functions.RECT();

            IntPtr hWnd = new IntPtr(HWND);

            IntPtr hdcSrc = Win32Functions.GetWindowDC((int)hWnd);

            Win32Functions.GetClientRect((int)hWnd, ref windowRect);

            Win32Functions.WINDOWINFO window = new Win32Functions.WINDOWINFO();
            window.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(window);

            Win32Functions.GetWindowInfo((int)hWnd, ref window);

            // create a device context we can copy to
            IntPtr hdcDest = Win32Functions.CreateCompatibleDC(hdcSrc);

            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = Win32Functions.CreateCompatibleBitmap(hdcSrc, pwidth, pheight);

            //// select the bitmap object
            IntPtr hOld = Win32Functions.SelectObject(hdcDest, hBitmap);

            // bitblt over
            Win32Functions.BitBlt(hdcDest, 0,
                                  0, pwidth, pheight, hdcSrc, window.rcClient.left - window.rcWindow.left,
                                  window.rcClient.top - window.rcWindow.top,
                                  (uint)(Win32Defines.SRCCOPY));

            Win32Functions.CURSORINFO ci = new Win32Functions.CURSORINFO();
            ci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(ci);
            Win32Functions.GetCursorInfo(ref ci);
            Win32Functions.PICONINFO pi = new Win32Functions.PICONINFO();
            Win32Functions.GetIconInfo(ci.hCursor, ref pi);
            Win32Functions.DrawIconEx(hdcDest, ci.point.x - window.rcClient.left - pi.xHotSpot,
                                      ci.point.y - window.rcClient.top - pi.yHotSpot, (int)ci.hCursor, 0, 0, 0, 0, 3);
            Win32Functions.SelectObject(hdcDest, hOld);
            Win32Functions.ReleaseDC(hWnd, hdcDest);
            Win32Functions.DeleteDC(hdcDest);
            Win32Functions.ReleaseDC(hWnd, hdcSrc);

            byte[] b = new byte[(pwidth * pheight * 4)];

            Win32Functions.GetBitmapBits(hBitmap, (pwidth * pheight * 4), b);

            Win32Functions.DeleteObject(hBitmap);

            return(b);
        }
Beispiel #3
0
        public byte[] captureWindowBytes(int HWND, int pwidth, int pheight)
        {
            Win32Functions.RECT windowRect = new Win32Functions.RECT();

            IntPtr hWnd = new IntPtr(HWND);

            IntPtr hdcSrc = Win32Functions.GetWindowDC((int)hWnd);

            Win32Functions.GetWindowRect((int)hWnd, ref windowRect);

            // create a device context we can copy to
            IntPtr hdcDest = Win32Functions.CreateCompatibleDC(hdcSrc);

            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = Win32Functions.CreateCompatibleBitmap(hdcSrc, pwidth, pheight);

            //// select the bitmap object
            IntPtr hOld = Win32Functions.SelectObject(hdcDest, hBitmap);

            // bitblt over
            Win32Functions.BitBlt(hdcDest, 0, 0, pwidth, pheight, hdcSrc, 0, 0,
             (uint)(Win32Defines.SRCCOPY ));
            Win32Functions.CURSORINFO ci = new Win32Functions.CURSORINFO();
            ci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(ci);
            Win32Functions.GetCursorInfo(ref ci);
            Win32Functions.PICONINFO pi = new Win32Functions.PICONINFO();
            Win32Functions.GetIconInfo(ci.hCursor, ref pi);
            Win32Functions.DrawIconEx(hdcDest, ci.point.x - windowRect.left - pi.xHotSpot, ci.point.y - windowRect.top - pi.yHotSpot, (int)ci.hCursor, 0, 0, 0, 0, 3);
            Win32Functions.SelectObject(hdcDest, hOld);
            Win32Functions.ReleaseDC(hWnd, hdcDest);
            Win32Functions.DeleteDC(hdcDest);
            Win32Functions.ReleaseDC(hWnd, hdcSrc);

            byte[] b = new byte[(pwidth * pheight * 4)];

            Win32Functions.GetBitmapBits(hBitmap, (pwidth * pheight * 4), b);

            Win32Functions.DeleteObject(hBitmap);

            return b;


        }
Beispiel #4
0
        public byte[] captureDesktopBytes()
        {
            Win32Functions.RECT windowRect = new Win32Functions.RECT();

            IntPtr hWnd = new IntPtr(Win32Functions.GetDesktopWindow());

            IntPtr hdcSrc = Win32Functions.GetWindowDC((int)hWnd);

            Win32Functions.WINDOWINFO window = new Win32Functions.WINDOWINFO();
            window.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(window);

            Win32Functions.GetWindowRect((int)hWnd, ref windowRect);

            Win32Functions.GetWindowInfo((int)hWnd, ref window);

            // create a bitmap from the visible clipping bounds of 
            //the graphics object from the window

            int width = windowRect.right - windowRect.left;

            int height = windowRect.bottom - windowRect.top;

            // create a device context we can copy to
            IntPtr hdcDest = Win32Functions.CreateCompatibleDC(hdcSrc);

            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = Win32Functions.CreateCompatibleBitmap(hdcSrc, width, height);

            //// select the bitmap object
            IntPtr hOld = Win32Functions.SelectObject(hdcDest, hBitmap);

            // bitblt over
            Win32Functions.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0,
            Win32Defines.SRCCOPY);
            Win32Functions.CURSORINFO ci = new Win32Functions.CURSORINFO();
            ci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(ci);
            Win32Functions.GetCursorInfo(ref ci);
            Win32Functions.PICONINFO pi = new Win32Functions.PICONINFO();
            Win32Functions.GetIconInfo(ci.hCursor, ref pi);
            Win32Functions.DrawIconEx(hdcDest, ci.point.x - windowRect.left - pi.xHotSpot, ci.point.y - windowRect.top - pi.yHotSpot, (int)ci.hCursor, 0, 0, 0, 0, 3);
            Win32Functions.SelectObject(hdcDest, hOld);
            Win32Functions.ReleaseDC(hWnd, hdcDest);
            Win32Functions.DeleteDC(hdcDest);
            Win32Functions.ReleaseDC(hWnd, hdcSrc);

            byte[] b = new byte[(width * height * 4)];

            Win32Functions.GetBitmapBits(hBitmap, (width * height * 4), b);

            Win32Functions.DeleteObject(hBitmap);

            return b;
        }