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;
}
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;
}
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;
}
Aggregations