Search in sources :

Example 11 with GDI32

use of com.sun.jna.platform.win32.GDI32 in project HearthStats.net-Uploader by HearthStats.

the class ProgramHelperWindows method _getScreenCaptureWindows.

private BufferedImage _getScreenCaptureWindows(HWND hWnd) {
    HDC hdcWindow = User32.INSTANCE.GetDC(hWnd);
    HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(hdcWindow);
    RECT bounds = new RECT();
    User32Extra.INSTANCE.GetClientRect(hWnd, bounds);
    // check to make sure the window's not minimized
    if (bounds.toRectangle().width >= 1024) {
        if (isMinimised) {
            _notifyObserversOfChangeTo("Hearthstone window restored");
            isMinimised = false;
        }
        if (isFullScreen(bounds.toRectangle())) {
            if (!isFullscreenFlag) {
                _notifyObserversOfChangeTo("Hearthstone running in fullscreen");
                isFullscreenFlag = true;
            }
            return null;
        } else {
            int width = bounds.right - bounds.left;
            int height = bounds.bottom - bounds.top;
            HBITMAP hBitmap = GDI32.INSTANCE.CreateCompatibleBitmap(hdcWindow, width, height);
            HANDLE hOld = GDI32.INSTANCE.SelectObject(hdcMemDC, hBitmap);
            GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, WinGDIExtra.SRCCOPY);
            GDI32.INSTANCE.SelectObject(hdcMemDC, hOld);
            GDI32.INSTANCE.DeleteDC(hdcMemDC);
            BITMAPINFO bmi = new BITMAPINFO();
            bmi.bmiHeader.biWidth = width;
            bmi.bmiHeader.biHeight = -height;
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biBitCount = 32;
            bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
            Memory buffer = new Memory(width * height * 4);
            GDI32.INSTANCE.GetDIBits(hdcWindow, hBitmap, 0, height, buffer, bmi, WinGDI.DIB_RGB_COLORS);
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            image.setRGB(0, 0, width, height, buffer.getIntArray(0, width * height), 0, width);
            GDI32.INSTANCE.DeleteObject(hBitmap);
            User32.INSTANCE.ReleaseDC(hWnd, hdcWindow);
            return image;
        }
    }
    if (!isMinimised) {
        // that the window has been minimised.
        if (minimisedCount < ITERATIONS_FOR_MINIMISE) {
            minimisedCount++;
        } else {
            _notifyObserversOfChangeTo("Warning! Hearthstone minimized. No detection possible.");
            isMinimised = true;
            minimisedCount = 0;
        }
    }
    return null;
}
Also used : RECT(com.sun.jna.platform.win32.WinDef.RECT) HDC(com.sun.jna.platform.win32.WinDef.HDC) Memory(com.sun.jna.Memory) BITMAPINFO(com.sun.jna.platform.win32.WinGDI.BITMAPINFO) HBITMAP(com.sun.jna.platform.win32.WinDef.HBITMAP) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) BufferedImage(java.awt.image.BufferedImage)

Aggregations

HDC (com.sun.jna.platform.win32.WinDef.HDC)9 HWND (com.sun.jna.platform.win32.WinDef.HWND)7 PIXELFORMATDESCRIPTOR (com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR)6 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)5 HBITMAP (com.sun.jna.platform.win32.WinDef.HBITMAP)3 BITMAPINFO (com.sun.jna.platform.win32.WinGDI.BITMAPINFO)3 BufferedImage (java.awt.image.BufferedImage)3 Memory (com.sun.jna.Memory)2 Pointer (com.sun.jna.Pointer)2 HICON (com.sun.jna.platform.win32.WinDef.HICON)2 RECT (com.sun.jna.platform.win32.WinDef.RECT)2 ICONINFO (com.sun.jna.platform.win32.WinGDI.ICONINFO)2 File (java.io.File)2 Function (com.sun.jna.Function)1 GDI32 (com.sun.jna.platform.win32.GDI32)1 User32 (com.sun.jna.platform.win32.User32)1 Win32Exception (com.sun.jna.platform.win32.Win32Exception)1 HGLRCByReference (com.sun.jna.platform.win32.WinDef.HGLRCByReference)1 POINT (com.sun.jna.platform.win32.WinDef.POINT)1 BITMAP (com.sun.jna.platform.win32.WinGDI.BITMAP)1