Search in sources :

Example 6 with HWND

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

the class User32Test method testFindWindowEx.

@Test
public void testFindWindowEx() {
    HWND result = User32.INSTANCE.FindWindowEx(null, null, null, null);
    assertNotNull("FindWindowEx result should not be null", result);
    assertEquals("GetLastError should be ERROR_SUCCESS.", WinError.ERROR_SUCCESS, Native.getLastError());
}
Also used : HWND(com.sun.jna.platform.win32.WinDef.HWND) Test(org.junit.Test)

Example 7 with HWND

use of com.sun.jna.platform.win32.WinDef.HWND 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 8 with HWND

use of com.sun.jna.platform.win32.WinDef.HWND 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 9 with HWND

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

the class GDI32UtilTest method testGetScreenshot.

@Test
public void testGetScreenshot() {
    HWND desktopWindow = User32.INSTANCE.GetDesktopWindow();
    assertNotNull("Failed to obtain desktop window handle", desktopWindow);
    BufferedImage image = GDI32Util.getScreenshot(desktopWindow);
    // Since this test involves taking a whole-desktop screenshot
    // we can't be sure what the image will be exactly.
    // We'll validate that the image is "good" 
    // by checking for 20 distinct colors.
    // BufferedImages normally start life as one uniform color 
    // so if that's not the case then some data was indeed copied over as a result of the getScreenshot() function.
    List<Integer> distinctPixels = new ArrayList<Integer>();
    for (int x = 0; x < image.getWidth(); x++) {
        for (int y = 0; y < image.getHeight(); y++) {
            int pixel = image.getRGB(x, y);
            if (!distinctPixels.contains(pixel)) {
                distinctPixels.add(pixel);
            }
            if (distinctPixels.size() > 20) {
                break;
            }
        }
    }
    assertTrue("Number of distinct pixels was not above 20.", distinctPixels.size() > 20);
}
Also used : HWND(com.sun.jna.platform.win32.WinDef.HWND) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 10 with HWND

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

the class Shell32Util method getFolderPath.

/**
	 * Get a special folder path.
	 * @param hwnd
	 *  Parent window.
	 * @param nFolder
	 *  Folder CSLID.
	 * @param dwFlags
	 *  Flags.
	 * @return
	 *  Special folder.
	 */
public static String getFolderPath(HWND hwnd, int nFolder, DWORD dwFlags) {
    char[] pszPath = new char[WinDef.MAX_PATH];
    HRESULT hr = Shell32.INSTANCE.SHGetFolderPath(hwnd, nFolder, null, dwFlags, pszPath);
    if (!hr.equals(W32Errors.S_OK)) {
        throw new Win32Exception(hr);
    }
    return Native.toString(pszPath);
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT)

Aggregations

HWND (com.sun.jna.platform.win32.WinDef.HWND)26 HDC (com.sun.jna.platform.win32.WinDef.HDC)9 Pointer (com.sun.jna.Pointer)7 Test (org.junit.Test)7 PIXELFORMATDESCRIPTOR (com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR)6 BufferedImage (java.awt.image.BufferedImage)6 JFrame (javax.swing.JFrame)6 LPARAM (com.sun.jna.platform.win32.WinDef.LPARAM)4 LRESULT (com.sun.jna.platform.win32.WinDef.LRESULT)4 WPARAM (com.sun.jna.platform.win32.WinDef.WPARAM)4 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)4 Memory (com.sun.jna.Memory)3 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 Rectangle (java.awt.Rectangle)3 COPYDATASTRUCT (com.sun.jna.platform.win32.WinUser.COPYDATASTRUCT)2 PointerByReference (com.sun.jna.ptr.PointerByReference)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2