Search in sources :

Example 46 with User32

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

the class JnaUtil method getWindowRect.

public static Rectangle getWindowRect(Pointer hWnd) throws JnaUtilException {
    if (hWnd == null) {
        throw new JnaUtilException("Failed to getWindowRect since Pointer hWnd is null");
    }
    Rectangle result = null;
    RECT rect = new RECT();
    boolean rectOK = user32.GetWindowRect(hWnd, rect);
    if (rectOK) {
        int x = rect.left;
        int y = rect.top;
        int width = rect.right - rect.left;
        int height = rect.bottom - rect.top;
        result = new Rectangle(x, y, width, height);
    }
    return result;
}
Also used : RECT(com.sun.jna.platform.win32.WinDef.RECT) Rectangle(java.awt.Rectangle)

Example 47 with User32

use of com.sun.jna.platform.win32.User32 in project cerberus-source by cerberustesting.

the class WebDriverService method focusBrowserWindow.

/**
 * Tries to focus the browser window thanks to the title given by the
 * webdriver in order to put it in foreground for Robot to work (Only works
 * on Windows so far, another way is to find for Xorg)
 *
 * @param session Webdriver session instance
 * @return True if the window is found, False otherwise
 */
public boolean focusBrowserWindow(Session session) {
    WebDriver driver = session.getDriver();
    String title = driver.getTitle();
    User32 user32 = User32.instance;
    // Arbitrary
    String[] browsers = new String[] { "", "Google Chrome", "Mozilla Firefox", "Opera", "Safari", "Internet Explorer", "Microsoft Edge" };
    for (String browser : browsers) {
        HWND window;
        if (browser.isEmpty()) {
            window = user32.FindWindow(null, title);
        } else {
            window = user32.FindWindow(null, title + " - " + browser);
        }
        if (user32.ShowWindow(window, User32.SW_SHOW)) {
            return user32.SetForegroundWindow(window);
        }
    }
    return false;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HWND(com.sun.jna.platform.win32.WinDef.HWND)

Example 48 with User32

use of com.sun.jna.platform.win32.User32 in project hook-any-text by MX-Futhark.

the class WindowsUtils method findByTitle.

/**
 * Finds windows by their title.
 *
 * @param title A string contained in the title of the windows.
 * @param windows A list of windows in which the search is performed.
 * @return The windows having the given title.
 */
public static List<HWND> findByTitle(String title, List<HWND> windows) {
    final List<HWND> filteredWindows = new LinkedList<>();
    for (HWND window : windows) {
        char[] windowText = new char[512];
        user32.GetWindowText(window, windowText, 512);
        String currentTitle = Native.toString(windowText).trim();
        if (!currentTitle.isEmpty() && currentTitle.contains(title)) {
            filteredWindows.add(window);
        }
    }
    return filteredWindows;
}
Also used : HWND(com.sun.jna.platform.win32.WinDef.HWND) LinkedList(java.util.LinkedList)

Aggregations

HWND (com.sun.jna.platform.win32.WinDef.HWND)23 Test (org.junit.Test)21 HDC (com.sun.jna.platform.win32.WinDef.HDC)10 LPARAM (com.sun.jna.platform.win32.WinDef.LPARAM)8 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)8 Pointer (com.sun.jna.Pointer)7 LRESULT (com.sun.jna.platform.win32.WinDef.LRESULT)7 WPARAM (com.sun.jna.platform.win32.WinDef.WPARAM)7 RECT (com.sun.jna.platform.win32.WinDef.RECT)6 PIXELFORMATDESCRIPTOR (com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR)6 BufferedImage (java.awt.image.BufferedImage)5 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)4 HICON (com.sun.jna.platform.win32.WinDef.HICON)4 POINT (com.sun.jna.platform.win32.WinDef.POINT)4 PointerByReference (com.sun.jna.ptr.PointerByReference)4 File (java.io.File)4 Memory (com.sun.jna.Memory)3 DesktopWindow (com.sun.jna.platform.DesktopWindow)3 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)3 HBITMAP (com.sun.jna.platform.win32.WinDef.HBITMAP)3