Esempio n. 1
1
 public boolean isVisible() {
   return User32.INSTANCE.IsWindowVisible(hWnd);
 }
Esempio n. 2
0
  /**
   * 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);
  }
Esempio n. 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;
 }
Esempio n. 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);
    }
  }
Esempio n. 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();
 }
Esempio n. 7
0
 public int getProcessID() {
   IntByReference processID = new IntByReference();
   User32.INSTANCE.GetWindowThreadProcessId(hWnd, processID);
   return processID.getValue();
 }
Esempio n. 8
0
 /** 3=SW_MAXIMIZE, etc */
 private void showWindow(int nCmdShow) {
   User32.INSTANCE.ShowWindow(hWnd, nCmdShow);
 }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 11
0
 public static Window getForegroundWindow() {
   return new Window(User32.INSTANCE.GetForegroundWindow());
 }
Esempio n. 12
0
 public void setForeground() {
   User32.INSTANCE.SetForegroundWindow(hWnd);
   minimize();
   restore();
 }
Esempio n. 13
0
 public String getTitle() {
   char[] buffer = new char[2048];
   User32.INSTANCE.GetWindowText(hWnd, buffer, 1024);
   return Native.toString(buffer);
 }
Esempio n. 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;
 }
Esempio n. 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
 }
Esempio n. 16
0
 public static Window[] getTopLevelWindows() {
   WindowList result = new WindowList();
   User32.INSTANCE.EnumWindows(result, null);
   return result.toArray();
 }
Esempio n. 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
 }
Esempio n. 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));
 }
Esempio n. 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
 }
Esempio n. 20
0
 public Window[] getChildren() {
   WindowList result = new WindowList();
   User32.INSTANCE.EnumChildWindows(hWnd, result, null);
   return result.toArray();
 }
Esempio n. 21
0
 public void setRectangle(Rectangle rect) {
   User32.INSTANCE.MoveWindow(hWnd, rect.x, rect.y, rect.width, rect.height, true);
 }