Example #1
1
 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);
  }
Example #3
0
 /** 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;
 }
Example #4
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);
    }
  }
Example #6
0
 public static Window[] getTopLevelWindows(String titleRegex) {
   WindowList result = new WindowList();
   result.titlePattern = Pattern.compile(titleRegex);
   User32.INSTANCE.EnumWindows(result, null);
   return result.toArray();
 }
Example #7
0
 public int getProcessID() {
   IntByReference processID = new IntByReference();
   User32.INSTANCE.GetWindowThreadProcessId(hWnd, processID);
   return processID.getValue();
 }
Example #8
0
 /** 3=SW_MAXIMIZE, etc */
 private void showWindow(int nCmdShow) {
   User32.INSTANCE.ShowWindow(hWnd, nCmdShow);
 }
Example #9
0
 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);
 }
Example #10
0
 /**
  * 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);
 }
Example #11
0
 public static Window getForegroundWindow() {
   return new Window(User32.INSTANCE.GetForegroundWindow());
 }
Example #12
0
 public void setForeground() {
   User32.INSTANCE.SetForegroundWindow(hWnd);
   minimize();
   restore();
 }
Example #13
0
 public String getTitle() {
   char[] buffer = new char[2048];
   User32.INSTANCE.GetWindowText(hWnd, buffer, 1024);
   return Native.toString(buffer);
 }
Example #14
0
 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;
 }
Example #15
0
 /**
  * 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
 }
Example #16
0
 public static Window[] getTopLevelWindows() {
   WindowList result = new WindowList();
   User32.INSTANCE.EnumWindows(result, null);
   return result.toArray();
 }
Example #17
0
 /**
  * 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
 }
Example #18
0
 /**
  * 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));
 }
Example #19
0
 /**
  * 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
 }
Example #20
0
 public Window[] getChildren() {
   WindowList result = new WindowList();
   User32.INSTANCE.EnumChildWindows(hWnd, result, null);
   return result.toArray();
 }
Example #21
0
 public void setRectangle(Rectangle rect) {
   User32.INSTANCE.MoveWindow(hWnd, rect.x, rect.y, rect.width, rect.height, true);
 }