Search in sources :

Example 1 with HDC

use of com.sun.jna.platform.win32.WinDef.HDC in project jna by java-native-access.

the class OpenGL32Test method testGetStringGLVersion.

public void testGetStringGLVersion() {
    // create a dummy window
    HWND hWnd = User32Util.createWindow("Message", null, 0, 0, 0, 0, 0, null, null, null, null);
    HDC hdc = User32.INSTANCE.GetDC(hWnd);
    // set a compatible pixel format
    PIXELFORMATDESCRIPTOR.ByReference pfd = new PIXELFORMATDESCRIPTOR.ByReference();
    pfd.nVersion = 1;
    pfd.dwFlags = WinGDI.PFD_DRAW_TO_WINDOW | WinGDI.PFD_SUPPORT_OPENGL | WinGDI.PFD_DOUBLEBUFFER;
    pfd.iPixelType = WinGDI.PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = WinGDI.PFD_MAIN_PLANE;
    GDI32.INSTANCE.SetPixelFormat(hdc, GDI32.INSTANCE.ChoosePixelFormat(hdc, pfd), pfd);
    // create the OpenGL context
    WinDef.HGLRC hGLRC = OpenGL32.INSTANCE.wglCreateContext(hdc);
    OpenGL32.INSTANCE.wglMakeCurrent(hdc, hGLRC);
    String glString = OpenGL32.INSTANCE.glGetString(GL.GL_VERSION);
    System.out.println("GL_VERSION=" + glString);
    OpenGL32.INSTANCE.wglDeleteContext(hGLRC);
    // destroy the window
    User32.INSTANCE.ReleaseDC(hWnd, hdc);
    User32Util.destroyWindow(hWnd);
    assertNotNull("Could not get GL_VERSION", glString);
}
Also used : HDC(com.sun.jna.platform.win32.WinDef.HDC) HWND(com.sun.jna.platform.win32.WinDef.HWND) PIXELFORMATDESCRIPTOR(com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR)

Example 2 with HDC

use of com.sun.jna.platform.win32.WinDef.HDC in project jna by java-native-access.

the class OpenGL32Test method testGetStringGLRenderer.

public void testGetStringGLRenderer() {
    // create a dummy window
    HWND hWnd = User32Util.createWindow("Message", null, 0, 0, 0, 0, 0, null, null, null, null);
    HDC hdc = User32.INSTANCE.GetDC(hWnd);
    // set a compatible pixel format
    PIXELFORMATDESCRIPTOR.ByReference pfd = new PIXELFORMATDESCRIPTOR.ByReference();
    pfd.nVersion = 1;
    pfd.dwFlags = WinGDI.PFD_DRAW_TO_WINDOW | WinGDI.PFD_SUPPORT_OPENGL | WinGDI.PFD_DOUBLEBUFFER;
    pfd.iPixelType = WinGDI.PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = WinGDI.PFD_MAIN_PLANE;
    GDI32.INSTANCE.SetPixelFormat(hdc, GDI32.INSTANCE.ChoosePixelFormat(hdc, pfd), pfd);
    // create the OpenGL context
    WinDef.HGLRC hGLRC = OpenGL32.INSTANCE.wglCreateContext(hdc);
    OpenGL32.INSTANCE.wglMakeCurrent(hdc, hGLRC);
    String glString = OpenGL32.INSTANCE.glGetString(GL.GL_RENDERER);
    System.out.println("GL_RENDERER=" + glString);
    OpenGL32.INSTANCE.wglDeleteContext(hGLRC);
    // destroy the window
    User32.INSTANCE.ReleaseDC(hWnd, hdc);
    User32Util.destroyWindow(hWnd);
//assertNotNull("Could not get GL_RENDERER", glString);
}
Also used : HDC(com.sun.jna.platform.win32.WinDef.HDC) HWND(com.sun.jna.platform.win32.WinDef.HWND) PIXELFORMATDESCRIPTOR(com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR)

Example 3 with HDC

use of com.sun.jna.platform.win32.WinDef.HDC in project jna by java-native-access.

the class OpenGL32Util method countGpusNV.

/**
     * Count GPUs
     * @return the number of available GPUs
     */
public static int countGpusNV() {
    // create a dummy window
    HWND hWnd = User32Util.createWindow("Message", null, 0, 0, 0, 0, 0, null, null, null, null);
    HDC hdc = User32.INSTANCE.GetDC(hWnd);
    // set a compatible pixel format
    PIXELFORMATDESCRIPTOR.ByReference pfd = new PIXELFORMATDESCRIPTOR.ByReference();
    pfd.nVersion = 1;
    pfd.dwFlags = WinGDI.PFD_DRAW_TO_WINDOW | WinGDI.PFD_SUPPORT_OPENGL | WinGDI.PFD_DOUBLEBUFFER;
    pfd.iPixelType = WinGDI.PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = WinGDI.PFD_MAIN_PLANE;
    GDI32.INSTANCE.SetPixelFormat(hdc, GDI32.INSTANCE.ChoosePixelFormat(hdc, pfd), pfd);
    // create the OpenGL context to get function address
    WinDef.HGLRC hGLRC = OpenGL32.INSTANCE.wglCreateContext(hdc);
    OpenGL32.INSTANCE.wglMakeCurrent(hdc, hGLRC);
    Pointer funcPointer = OpenGL32.INSTANCE.wglGetProcAddress("wglEnumGpusNV");
    Function fncEnumGpusNV = (funcPointer == null) ? null : Function.getFunction(funcPointer);
    OpenGL32.INSTANCE.wglDeleteContext(hGLRC);
    // destroy the window
    User32.INSTANCE.ReleaseDC(hWnd, hdc);
    User32Util.destroyWindow(hWnd);
    // abort if the nVidia extensions are not present
    if (fncEnumGpusNV == null)
        return 0;
    // enumerate nVidia adapters
    HGLRCByReference hGPU = new HGLRCByReference();
    for (int i = 0; i < 16; i++) {
        Boolean ok = (Boolean) fncEnumGpusNV.invoke(Boolean.class, new Object[] { Integer.valueOf(i), hGPU });
        if (!ok.booleanValue())
            return i;
    }
    return 0;
}
Also used : HDC(com.sun.jna.platform.win32.WinDef.HDC) HWND(com.sun.jna.platform.win32.WinDef.HWND) PIXELFORMATDESCRIPTOR(com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR) Pointer(com.sun.jna.Pointer) HGLRCByReference(com.sun.jna.platform.win32.WinDef.HGLRCByReference) Function(com.sun.jna.Function) HGLRCByReference(com.sun.jna.platform.win32.WinDef.HGLRCByReference)

Example 4 with HDC

use of com.sun.jna.platform.win32.WinDef.HDC in project jna by java-native-access.

the class MonitorInfoDemo method main.

/**
	 * @param args (ignored)
	 */
public static void main(String[] args) {
    System.out.println("Installed Physical Monitors: " + User32.INSTANCE.GetSystemMetrics(WinUser.SM_CMONITORS));
    User32.INSTANCE.EnumDisplayMonitors(null, null, new MONITORENUMPROC() {

        @Override
        public int apply(HMONITOR hMonitor, HDC hdc, RECT rect, LPARAM lparam) {
            enumerate(hMonitor);
            return 1;
        }
    }, new LPARAM(0));
}
Also used : HMONITOR(com.sun.jna.platform.win32.WinUser.HMONITOR) RECT(com.sun.jna.platform.win32.WinDef.RECT) HDC(com.sun.jna.platform.win32.WinDef.HDC) LPARAM(com.sun.jna.platform.win32.WinDef.LPARAM) MONITORENUMPROC(com.sun.jna.platform.win32.WinUser.MONITORENUMPROC)

Example 5 with HDC

use of com.sun.jna.platform.win32.WinDef.HDC in project jna by java-native-access.

the class AlphaMaskDemo method updateW32.

private void updateW32(boolean a, boolean i) {
    User32 user = User32.INSTANCE;
    GDI32 gdi = GDI32.INSTANCE;
    HWND hWnd = null;
    if (!alphaWindow.isDisplayable()) {
        alphaWindow.pack();
        hWnd = getHwnd(alphaWindow);
        int flags = user.GetWindowLong(hWnd, WinUser.GWL_EXSTYLE);
        flags |= WinUser.WS_EX_LAYERED;
        user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
        Window parent = alphaWindow.getOwner();
        Point where = parent.getLocationOnScreen();
        where.translate(parent.getWidth(), 0);
        alphaWindow.setLocation(where);
    } else {
        hWnd = getHwnd(alphaWindow);
    }
    if (i) {
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        HDC screenDC = user.GetDC(null);
        HDC memDC = gdi.CreateCompatibleDC(screenDC);
        HBITMAP hBitmap = null;
        HANDLE oldBitmap = null;
        try {
            BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
            Graphics g = buf.getGraphics();
            g.drawImage(image, 0, 0, w, h, null);
            BITMAPINFO bmi = new BITMAPINFO();
            bmi.bmiHeader.biWidth = w;
            bmi.bmiHeader.biHeight = h;
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biBitCount = 32;
            bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
            bmi.bmiHeader.biSizeImage = w * h * 4;
            PointerByReference ppbits = new PointerByReference();
            hBitmap = gdi.CreateDIBSection(memDC, bmi, WinGDI.DIB_RGB_COLORS, ppbits, null, 0);
            oldBitmap = gdi.SelectObject(memDC, hBitmap);
            Pointer pbits = ppbits.getValue();
            Raster raster = buf.getData();
            int[] pixel = new int[4];
            int[] bits = new int[w * h];
            for (int y = 0; y < h; y++) {
                for (int x = 0; x < w; x++) {
                    raster.getPixel(x, h - y - 1, pixel);
                    int alpha = (pixel[3] & 0xFF) << 24;
                    int red = (pixel[2] & 0xFF);
                    int green = (pixel[1] & 0xFF) << 8;
                    int blue = (pixel[0] & 0xFF) << 16;
                    bits[x + y * w] = alpha | red | green | blue;
                }
            }
            pbits.write(0, bits, 0, bits.length);
            SIZE size = new SIZE();
            size.cx = w;
            size.cy = h;
            POINT loc = new POINT();
            loc.x = alphaWindow.getX();
            loc.y = alphaWindow.getY();
            POINT srcLoc = new POINT();
            BLENDFUNCTION blend = new BLENDFUNCTION();
            blend.SourceConstantAlpha = (byte) (alpha * 255);
            blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
            user.UpdateLayeredWindow(hWnd, screenDC, loc, size, memDC, srcLoc, 0, blend, WinUser.ULW_ALPHA);
        } finally {
            user.ReleaseDC(null, screenDC);
            if (hBitmap != null) {
                gdi.SelectObject(memDC, oldBitmap);
                gdi.DeleteObject(hBitmap);
            }
            gdi.DeleteDC(memDC);
        }
    } else if (a) {
        BLENDFUNCTION blend = new BLENDFUNCTION();
        blend.SourceConstantAlpha = (byte) (alpha * 255);
        blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
        user.UpdateLayeredWindow(hWnd, null, null, null, null, null, 0, blend, WinUser.ULW_ALPHA);
    }
    if (!alphaWindow.isVisible()) {
        alphaWindow.setVisible(true);
    }
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) GDI32(com.sun.jna.platform.win32.GDI32) BLENDFUNCTION(com.sun.jna.platform.win32.WinUser.BLENDFUNCTION) HDC(com.sun.jna.platform.win32.WinDef.HDC) HWND(com.sun.jna.platform.win32.WinDef.HWND) Raster(java.awt.image.Raster) SIZE(com.sun.jna.platform.win32.WinUser.SIZE) Pointer(com.sun.jna.Pointer) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics(java.awt.Graphics) BITMAPINFO(com.sun.jna.platform.win32.WinGDI.BITMAPINFO) PointerByReference(com.sun.jna.ptr.PointerByReference) User32(com.sun.jna.platform.win32.User32) HBITMAP(com.sun.jna.platform.win32.WinDef.HBITMAP) POINT(com.sun.jna.platform.win32.WinDef.POINT) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Aggregations

HDC (com.sun.jna.platform.win32.WinDef.HDC)10 HWND (com.sun.jna.platform.win32.WinDef.HWND)7 PIXELFORMATDESCRIPTOR (com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR)6 HBITMAP (com.sun.jna.platform.win32.WinDef.HBITMAP)3 RECT (com.sun.jna.platform.win32.WinDef.RECT)3 BITMAPINFO (com.sun.jna.platform.win32.WinGDI.BITMAPINFO)3 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)3 BufferedImage (java.awt.image.BufferedImage)3 Memory (com.sun.jna.Memory)2 Pointer (com.sun.jna.Pointer)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 LPARAM (com.sun.jna.platform.win32.WinDef.LPARAM)1 POINT (com.sun.jna.platform.win32.WinDef.POINT)1 BLENDFUNCTION (com.sun.jna.platform.win32.WinUser.BLENDFUNCTION)1 HMONITOR (com.sun.jna.platform.win32.WinUser.HMONITOR)1 MONITORENUMPROC (com.sun.jna.platform.win32.WinUser.MONITORENUMPROC)1