public boolean isVisible() { return User32.INSTANCE.IsWindowVisible(hWnd); }
/** * Uses JNA to retrieve the module file name of a program and parses it as a string which is then * passed to the InterruptionLogic class. */ private void getProgramIdentifier() { PSAPI psapi = (PSAPI) Native.loadLibrary("psapi", PSAPI.class); HWND focusedWindow = User32.INSTANCE.GetForegroundWindow(); byte[] name = new byte[1024]; IntByReference pid = new IntByReference(); User32.INSTANCE.GetWindowThreadProcessId(focusedWindow, pid); System.out.println("pid = " + pid.getValue()); HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010, false, pid.getValue()); // Initally I was using the 'GetWindowModuleFileName' which provided // erronous behaviour. 'technomage' on Stackoverflow pointed out that // the method that should be used is 'GetModuleFileNameEx' - // http://stackoverflow.com/questions/15693210/getmodulefilename-for-window-in-focus-jna-windows-os psapi.GetModuleFileNameExA(process, null, name, 1024); String nameString = Native.toString(name); System.out.println(nameString); interruptDec.interruptNow(nameString); }
/** Return true if the window message queue is idle, false if timeout */ public boolean waitForInputIdle(int timeout_ms) { IntByReference lpdwProcessId = new IntByReference(); User32.INSTANCE.GetWindowThreadProcessId(hWnd, lpdwProcessId); return User32.INSTANCE .WaitForInputIdle(new HANDLE(lpdwProcessId.getPointer()), new DWORD(timeout_ms)) .intValue() == 0; }
/** Flash the window three times */ public void flash() { WinUser.FLASHWINFO pfwi = new WinUser.FLASHWINFO(); pfwi.cbSize = 20; pfwi.hWnd = hWnd; pfwi.dwFlags = 3; // 3 = FLASHW_ALL pfwi.uCount = 3; pfwi.dwTimeout = 250; User32.INSTANCE.FlashWindowEx(pfwi); sleep(1000); }
static void setOverlayIcon(IdeFrame frame, Object icon, boolean dispose) { if (!isEnabled()) { return; } if (icon == null) { icon = Pointer.NULL; } mySetOverlayIcon.invokeInt( new Object[] {myInterfacePointer, getHandle(frame), icon, Pointer.NULL}); if (dispose) { User32.INSTANCE.DestroyIcon((WinDef.HICON) icon); } }
public static Window[] getTopLevelWindows(String titleRegex) { WindowList result = new WindowList(); result.titlePattern = Pattern.compile(titleRegex); User32.INSTANCE.EnumWindows(result, null); return result.toArray(); }
public int getProcessID() { IntByReference processID = new IntByReference(); User32.INSTANCE.GetWindowThreadProcessId(hWnd, processID); return processID.getValue(); }
/** 3=SW_MAXIMIZE, etc */ private void showWindow(int nCmdShow) { User32.INSTANCE.ShowWindow(hWnd, nCmdShow); }
public Rectangle getRectangle() { RECT rect = new RECT(); User32.INSTANCE.GetWindowRect(hWnd, rect); return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); }
/** * Returns the class of the window, such as "SWT_Window0" for any SWT application. See AutoIt * Window Info Tool */ public String getClassName() { char[] buffer = new char[2048]; User32.INSTANCE.GetClassName(hWnd, buffer, 1024); return Native.toString(buffer); }
public static Window getForegroundWindow() { return new Window(User32.INSTANCE.GetForegroundWindow()); }
public void setForeground() { User32.INSTANCE.SetForegroundWindow(hWnd); minimize(); restore(); }
public String getTitle() { char[] buffer = new char[2048]; User32.INSTANCE.GetWindowText(hWnd, buffer, 1024); return Native.toString(buffer); }
public static Window getProcessWindow(int processID) { WindowList result = new WindowList(); result.processID = processID; User32.INSTANCE.EnumWindows(result, null); return result.list.size() > 0 ? result.list.get(0) : null; }
/** * In windows the user can customize the border and title bar size. * * @return titlebar height */ public static int getTitleHeight() { int f = User32.INSTANCE.GetSystemMetrics(33); // 33 = SM_CYSIZEFRAME return User32.INSTANCE.GetSystemMetrics(4) + f; // 4 = SM_CYCAPTION }
public static Window[] getTopLevelWindows() { WindowList result = new WindowList(); User32.INSTANCE.EnumWindows(result, null); return result.toArray(); }
/** * Get the next top-level window in Z-order, (from foreground to background). * * <p>To iterate all windows, use * * <p>for (Window w = getForegroundWindow(); !w.isNull(); w = w.next()) ... * * @return */ public Window next() { return new Window(User32.INSTANCE.GetWindow(hWnd, new DWORD(2))); // 2 = // GW_HWNDNEXT }
/** * Find the FIRST top level window with specified class and title. * * @param className such as "SWT_Window0" or null * @param title such as "QREADS" or null * @return first window found, or null if not found. */ public static Window findWindow(String className, String title) { return new Window(User32.INSTANCE.FindWindow(className, title)); }
/** * In windows the user can customize the border and title bar size. * * @return border thickness in pixels */ public static int getBorderSize() { int f = User32.INSTANCE.GetSystemMetrics(32); // 32 = SM_CXSIZEFRAME return User32.INSTANCE.GetSystemMetrics(5) + f; // 5 = SM_CXBORDER }
public Window[] getChildren() { WindowList result = new WindowList(); User32.INSTANCE.EnumChildWindows(hWnd, result, null); return result.toArray(); }
public void setRectangle(Rectangle rect) { User32.INSTANCE.MoveWindow(hWnd, rect.x, rect.y, rect.width, rect.height, true); }