Search in sources :

Example 1 with HICON

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

the class GDI32Test method testGetObject.

public void testGetObject() throws Exception {
    final ICONINFO iconInfo = new ICONINFO();
    final HANDLE hImage = User32.INSTANCE.LoadImage(null, new File(getClass().getResource("/res/test_icon.ico").toURI()).getAbsolutePath(), WinUser.IMAGE_ICON, 0, 0, WinUser.LR_LOADFROMFILE);
    try {
        // obtain test icon from classpath
        if (!User32.INSTANCE.GetIconInfo(new HICON(hImage), iconInfo))
            throw new Exception("Invocation of User32.GetIconInfo() failed: " + Kernel32Util.getLastErrorMessage());
        iconInfo.read();
        // test GetObject method
        BITMAP bmp = new BITMAP();
        int nWrittenBytes = GDI32.INSTANCE.GetObject(iconInfo.hbmColor, bmp.size(), bmp.getPointer());
        bmp.read();
        if (nWrittenBytes <= 0)
            throw new Exception("Detection of bitmap information failed: " + Kernel32Util.getLastErrorMessage());
        // verify that bitmap information was successfully detected
        assertEquals(32, bmp.bmHeight.intValue());
        assertEquals(32, bmp.bmWidth.intValue());
    } finally {
        if (iconInfo.hbmColor != null && iconInfo.hbmColor.getPointer() != Pointer.NULL)
            GDI32.INSTANCE.DeleteObject(iconInfo.hbmColor);
        if (iconInfo.hbmMask != null && iconInfo.hbmMask.getPointer() != Pointer.NULL)
            GDI32.INSTANCE.DeleteObject(iconInfo.hbmMask);
    }
}
Also used : ICONINFO(com.sun.jna.platform.win32.WinGDI.ICONINFO) BITMAP(com.sun.jna.platform.win32.WinGDI.BITMAP) HICON(com.sun.jna.platform.win32.WinDef.HICON) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) File(java.io.File)

Example 2 with HICON

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

the class WindowUtilsTest method testGetIconSize.

public void testGetIconSize() throws Exception {
    final JFrame w = new JFrame();
    try {
        final BufferedImage expectedIcon = ImageIO.read(new FileInputStream(new File(getClass().getResource("/res/test_icon.png").getPath())));
        w.setIconImage(expectedIcon);
        w.setVisible(true);
        Pointer p = Native.getComponentPointer(w);
        assertNotNull("Could not obtain native HANDLE for JFrame", p);
        HWND hwnd = new HWND(p);
        final DWORDByReference hIconNumber = new DWORDByReference();
        LRESULT result = User32.INSTANCE.SendMessageTimeout(hwnd, WinUser.WM_GETICON, new WPARAM(WinUser.ICON_BIG), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber);
        assertNotEquals(0, result.intValue());
        final HICON hIcon = new HICON(new Pointer(hIconNumber.getValue().longValue()));
        assertTrue(WindowUtils.getIconSize(hIcon).width >= 32);
        assertTrue(WindowUtils.getIconSize(hIcon).height >= 32);
        assertEquals(WindowUtils.getIconSize(hIcon).width, WindowUtils.getIconSize(hIcon).height);
    } finally {
        w.dispose();
    }
}
Also used : LRESULT(com.sun.jna.platform.win32.WinDef.LRESULT) JFrame(javax.swing.JFrame) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) HWND(com.sun.jna.platform.win32.WinDef.HWND) LPARAM(com.sun.jna.platform.win32.WinDef.LPARAM) HICON(com.sun.jna.platform.win32.WinDef.HICON) Pointer(com.sun.jna.Pointer) File(java.io.File) WPARAM(com.sun.jna.platform.win32.WinDef.WPARAM) BufferedImage(java.awt.image.BufferedImage) FileInputStream(java.io.FileInputStream)

Example 3 with HICON

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

the class User32Test method testCopyIcon.

@Test
public void testCopyIcon() {
    HICON result = User32.INSTANCE.CopyIcon(null);
    assertNull("CopyIcon result should be false", result);
    assertEquals("GetLastError should be ERROR_INVALID_CURSOR_HANDLE.", WinError.ERROR_INVALID_CURSOR_HANDLE, Native.getLastError());
}
Also used : HICON(com.sun.jna.platform.win32.WinDef.HICON) Test(org.junit.Test)

Example 4 with HICON

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

the class User32Test method testGetIconInfo.

@Test
public void testGetIconInfo() throws Exception {
    final ICONINFO iconInfo = new ICONINFO();
    final HANDLE hImage = User32.INSTANCE.LoadImage(null, new File(getClass().getResource("/res/test_icon.ico").toURI()).getAbsolutePath(), WinUser.IMAGE_ICON, 0, 0, WinUser.LR_LOADFROMFILE);
    try {
        // obtain test icon from classpath
        if (!User32.INSTANCE.GetIconInfo(new HICON(hImage), iconInfo))
            throw new Exception("Invocation of User32.GetIconInfo() failed: " + Kernel32Util.getLastErrorMessage());
        iconInfo.read();
    } finally {
        if (iconInfo.hbmColor != null && iconInfo.hbmColor.getPointer() != Pointer.NULL)
            GDI32.INSTANCE.DeleteObject(iconInfo.hbmColor);
        if (iconInfo.hbmMask != null && iconInfo.hbmMask.getPointer() != Pointer.NULL)
            GDI32.INSTANCE.DeleteObject(iconInfo.hbmMask);
    }
}
Also used : ICONINFO(com.sun.jna.platform.win32.WinGDI.ICONINFO) HICON(com.sun.jna.platform.win32.WinDef.HICON) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) File(java.io.File) AWTException(java.awt.AWTException) Test(org.junit.Test)

Aggregations

HICON (com.sun.jna.platform.win32.WinDef.HICON)4 File (java.io.File)3 ICONINFO (com.sun.jna.platform.win32.WinGDI.ICONINFO)2 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)2 Test (org.junit.Test)2 Pointer (com.sun.jna.Pointer)1 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)1 HWND (com.sun.jna.platform.win32.WinDef.HWND)1 LPARAM (com.sun.jna.platform.win32.WinDef.LPARAM)1 LRESULT (com.sun.jna.platform.win32.WinDef.LRESULT)1 WPARAM (com.sun.jna.platform.win32.WinDef.WPARAM)1 BITMAP (com.sun.jna.platform.win32.WinGDI.BITMAP)1 AWTException (java.awt.AWTException)1 BufferedImage (java.awt.image.BufferedImage)1 FileInputStream (java.io.FileInputStream)1 JFrame (javax.swing.JFrame)1