Java 类com.sun.jna.platform.WindowUtils 实例源码

项目:rensa    文件:WindowTitleFetcher.java   
/**
 * @param processName .exe name
 * @return window title, if found - else null
 */
public static String getProcessWindowTitle(String processName) {
    final String[] res = {null};
    List<DesktopWindow> windows = WindowUtils.getAllWindows(true);
    for (DesktopWindow dw : windows) {
        if (dw.getFilePath().endsWith(processName)) {
            String result = dw.getTitle();
            if (!result.isEmpty()) {
                if (!result.contains("MSCTFIME") && !result.contains("Default IME")) {
                    if (res[0] == null || res[0].length() < result.length()) {
                        if(res[0] != null) {
                            log.db("Changing window name from " + res[0]);
                        }
                        res[0] = result;
                        String msg = "Set to " + result;
                        if (!msg.equals(lastMessage)) {
                            log.db(msg);
                            lastMessage = msg;
                        }
                    }
                }
            }
        }
    }
    return res[0];
}
项目:intellij-ce-playground    文件:WindowManagerImpl.java   
private static void setAlphaMode(Window window, float ratio) {
  try {
    if (SystemInfo.isMacOSLeopard) {
      if (window instanceof JWindow) {
        ((JWindow)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      } else if (window instanceof JDialog) {
        ((JDialog)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      } else if (window instanceof JFrame) {
        ((JFrame)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      }
    }
    else if (AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT)) {
      AWTUtilitiesWrapper.setWindowOpacity(window, 1.0f - ratio);
    }
    else {
      WindowUtils.setWindowAlpha(window, 1.0f - ratio);
    }
  }
  catch (Throwable e) {
    LOG.debug(e);
  }
}
项目:tools-idea    文件:WindowManagerImpl.java   
private static void setAlphaMode(Window window, float ratio) {
  try {
    if (SystemInfo.isMacOSLeopard) {
      if (window instanceof JWindow) {
        ((JWindow)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      } else if (window instanceof JDialog) {
        ((JDialog)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      } else if (window instanceof JFrame) {
        ((JFrame)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      }
    }
    else if (AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT)) {
      AWTUtilitiesWrapper.setWindowOpacity(window, 1.0f - ratio);
    }
    else {
      WindowUtils.setWindowAlpha(window, 1.0f - ratio);
    }
  }
  catch (Throwable e) {
    LOG.debug(e);
  }
}
项目:consulo    文件:DesktopWindowManagerImpl.java   
private static void setAlphaMode(Window window, float ratio) {
  try {
    if (SystemInfo.isMacOSLeopard) {
      if (window instanceof JWindow) {
        ((JWindow)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      }
      else if (window instanceof JDialog) {
        ((JDialog)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      }
      else if (window instanceof JFrame) {
        ((JFrame)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
      }
    }
    else if (AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT)) {
      AWTUtilitiesWrapper.setWindowOpacity(window, 1.0f - ratio);
    }
    else {
      WindowUtils.setWindowAlpha(window, 1.0f - ratio);
    }
  }
  catch (Throwable e) {
    LOG.debug(e);
  }
}
项目:incubator-netbeans    文件:NativeWindowSystemImpl.java   
@Override
public void setWindowMask(Window w, Icon mask) {
    try {
        WindowUtils.setWindowMask(w, mask);
    } catch( ThreadDeath td ) {
        throw td;
    } catch( Throwable e ) {
        LOG.log(Level.INFO, null, e);
    }
}
项目:poker-bot    文件:User32Utils.java   
public static DesktopWindow findAndShowWindow(String title) {
    List<DesktopWindow> allWindows = WindowUtils.getAllWindows(true);
    for (DesktopWindow window : allWindows) {
        if (window.getTitle().equals(title)) {
            user32.SetForegroundWindow(window.getHWND());
            return window;
        }
    }
    return null;
}
项目:Mem-Eater-Bug    文件:Kernel32Util.java   
/**
 * Gets a list of currently active processes by creating a snapshot.
 * 
 * @return List of currently active processes
 * @throws Win32Exception
 *             If the operation was not successful
 */
public static ProcessList getProcessList() throws Win32Exception {
    final ProcessList plist = new ProcessList();

    final List<PROCESSENTRY32> list = new LinkedList<>();

    final HANDLE hProcessSnap = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS,
            new DWORD(0));

    PROCESSENTRY32 pe32 = new PROCESSENTRY32();
    if (!Kernel32.INSTANCE.Process32First(hProcessSnap, pe32)) {
        throw new Win32Exception(Native.getLastError());
    }

    do {
        if (pe32.th32ProcessID.intValue() != 0) {
            list.add(pe32);
        }
        pe32 = new PROCESSENTRY32();
    } while (Kernel32.INSTANCE.Process32Next(hProcessSnap, pe32));

    for (final PROCESSENTRY32 pe : list) {
        plist.add(new Process(pe));
    }

    Kernel32.INSTANCE.CloseHandle(hProcessSnap);

    final List<DesktopWindow> windows = WindowUtils.getAllWindows(false);
    final IntByReference lpdwProcessId = new IntByReference();
    int pid = 0;
    for (final DesktopWindow window : windows) {
        User32.INSTANCE.GetWindowThreadProcessId(window.getHWND(), lpdwProcessId);
        pid = lpdwProcessId.getValue();
        plist.add(pid, window.getHWND());
    }
    return plist;
}
项目:MercuryTrade    文件:AppMain.java   
private static String getGamePath() {
    return WindowUtils.getAllWindows(false).stream().filter(window -> {
        char[] className = new char[512];
        User32.INSTANCE.GetClassName(window.getHWND(), className, 512);
        return Native.toString(className).equals("POEWindowClass");
    }).map(it -> {
        String filePath = it.getFilePath();
        return StringUtils.substringBeforeLast(filePath, "\\");
    }).findAny().orElse(null);
}
项目:MercuryTrade    文件:MercuryStoreCoreTest.java   
@Test
public void testSoundReducer() throws IOException {
    TestSubscriber<Map<String,String>> testSubscriber = new TestSubscriber<>();
    List<DesktopWindow> allWindows = WindowUtils.getAllWindows(false);
    allWindows.forEach(window -> {
        System.out.println(window.getFilePath());
    });
}
项目:intellij-ce-playground    文件:WindowManagerImpl.java   
private static boolean calcAlphaModelSupported() {
  if (AWTUtilitiesWrapper.isTranslucencyAPISupported()) {
    return AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT);
  }
  try {
    return WindowUtils.isWindowAlphaSupported();
  }
  catch (Throwable e) {
    return false;
  }
}
项目:intellij-ce-playground    文件:WindowManagerImpl.java   
@Override
public void setWindowMask(final Window window, @Nullable final Shape mask) {
  try {
    if (AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.PERPIXEL_TRANSPARENT)) {
      AWTUtilitiesWrapper.setWindowShape(window, mask);
    }
    else {
      WindowUtils.setWindowMask(window, mask);
    }
  }
  catch (Throwable e) {
    LOG.debug(e);
  }
}
项目:tools-idea    文件:WindowManagerImpl.java   
private static boolean calcAlphaModelSupported() {
  if (AWTUtilitiesWrapper.isTranslucencyAPISupported()) {
    return AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT);
  }
  try {
    return WindowUtils.isWindowAlphaSupported();
  }
  catch (Throwable e) {
    return false;
  }
}
项目:tools-idea    文件:WindowManagerImpl.java   
public void setWindowMask(final Window window, @Nullable final Shape mask) {
  try {
    if (AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.PERPIXEL_TRANSPARENT)) {
      AWTUtilitiesWrapper.setWindowShape(window, mask);
    }
    else {
      WindowUtils.setWindowMask(window, mask);
    }
  }
  catch (Throwable e) {
    LOG.debug(e);
  }
}
项目:jitsi    文件:UIServiceImpl.java   
/**
 * Repaints and revalidates the whole UI Tree.
 *
 * Calls {@link SwingUtilities#updateComponentTreeUI(Component c)}
 * for every window owned by the application which cause UI skin and
 * layout repaint.
 */
public void repaintUI()
{
    if(!SwingUtilities.isEventDispatchThread())
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                repaintUI();
            }
        });
        return;
    }

    if (UIManager.getLookAndFeel() instanceof SIPCommLookAndFeel)
        ((SIPCommLookAndFeel) UIManager.getLookAndFeel()).loadSkin();

    Constants.reload();
    ImageLoader.clearCache();

    Window[] windows
        = net.java.sip.communicator.plugin.desktoputil.WindowUtils
            .getWindows();

    for(Window win : windows)
    {
        reloadComponents(win);
        ComponentUtils.updateComponentTreeUI(win);
    }
}
项目:consulo    文件:DesktopWindowManagerImpl.java   
private static boolean calcAlphaModelSupported() {
  if (AWTUtilitiesWrapper.isTranslucencyAPISupported()) {
    return AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT);
  }
  try {
    return WindowUtils.isWindowAlphaSupported();
  }
  catch (Throwable e) {
    return false;
  }
}
项目:consulo    文件:DesktopWindowManagerImpl.java   
@Override
public void setWindowMask(final Window window, @Nullable final Shape mask) {
  try {
    if (AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.PERPIXEL_TRANSPARENT)) {
      AWTUtilitiesWrapper.setWindowShape(window, mask);
    }
    else {
      WindowUtils.setWindowMask(window, mask);
    }
  }
  catch (Throwable e) {
    LOG.debug(e);
  }
}
项目:NanoUI    文件:ContextWindow.java   
@Override
public void update(float delta) {
    compWin.update(delta, window);
    if (run) {
        compWin.dispose(window);
        Container bottomBtns = new Container(0, 0, 200, 60);

        char[] name = new char[1024];
        User32Ext.INSTANCE.GetWindowTextW(hwndWin, name, name.length);
        String title = Native.toString(name);

        Button btnClose = new Button(0, 0, 200, 30, "Close");
        btnClose.setPreicon(Theme.ICON_CHROME_CLOSE);
        btnClose.setPreiconSize(12);
        btnClose.setOnButtonPress(() -> {
            User32.INSTANCE.PostMessage(this.hwndWin, WM_CLOSE, new WPARAM(), new LPARAM());
            TaskManager.addTask(() -> window.setVisible(false));
        });
        Button btnOpen = new Button(0, 30, 200, 30, title);
        btnOpen.setOnButtonPress(() -> {
            char[] classNameC = new char[128];
            User32.INSTANCE.GetClassName(hwndWin, classNameC, classNameC.length);
            String className = Native.toString(classNameC);
            if (!className.equals("ApplicationFrameWindow"))
                try {
                    new ProcessBuilder(WindowUtils.getProcessFilePath(hwndWin), "").start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            TaskManager.addTask(() -> window.setVisible(false));
        });
        bottomBtns.addComponent(btnClose);
        bottomBtns.addComponent(btnOpen);

        Image icon = new Image(13, 38, 16, 16, Util.getIcon(hwndWin, window), true);
        bottomBtns.addComponent(icon);
        compWin.addComponent(bottomBtns);

        Container tasks = new Container(-20, 0, 220, 140);
        tasks.setLayout(new FlowLayout(Direction.DOWN, 0, 10));
        for (int i = 0; i < 4; i++) {
            Button t = new Button(0, 0, 220, 30, "Task " + i);
            t.setWindowAlignment(Alignment.LEFT_TOP);
            t.setAlignment(Alignment.RIGHT_BOTTOM);
            tasks.addComponent(t);
        }
        compWin.addComponent(tasks);
        TaskManager.addTask(() -> window.setVisible(true));
        run = false;
    }

}
项目:jitsi    文件:UIServiceImpl.java   
/**
 * Initializes all frames and panels and shows the GUI.
 */
void loadApplicationGui()
{
    this.setDefaultThemePack();

    // Initialize the single window container if we're in this case. This
    // should be done before initializing the main window, because he'll
    // search for it.
    if (ConfigurationUtils.isSingleWindowInterfaceEnabled())
        singleWindowContainer = new SingleWindowContainer();

    // Initialize the main window.
    this.mainFrame = new MainFrame();

    if (UIManager.getLookAndFeel() instanceof SIPCommLookAndFeel)
        initCustomFonts();

    /*
     * The mainFrame isn't fully ready without the MetaContactListService so
     * make sure it's set before allowing anything, such as LoginManager, to
     * use the mainFrame. Otherwise, LoginManager, for example, will call
     * back from its event listener(s) into the mainFrame and cause a
     * NullPointerException.
     */
    mainFrame.setContactList(GuiActivator.getContactListService());

    // Initialize main window bounds.
    this.mainFrame.initBounds();

    // Register the main window as an exported window, so that other bundles
    // could access it through the UIService.
    GuiActivator.getUIService().registerExportedWindow(mainFrame);

    // Initialize the login manager.
    this.loginManager = new LoginManager(new LoginRendererSwingImpl());

    this.popupDialog = new PopupDialogImpl();

    this.wizardContainer = new AccountRegWizardContainerImpl(mainFrame);

    if (ConfigurationUtils.isTransparentWindowEnabled())
    {
        try
        {
            WindowUtils.setWindowTransparent(mainFrame, true);
        }
        catch (UnsupportedOperationException ex)
        {
            logger.error(ex.getMessage(), ex);
            ConfigurationUtils.setTransparentWindowEnabled(false);
        }
    }

    if(ConfigurationUtils.isApplicationVisible()
        || Boolean.getBoolean("disable-tray")
        || ConfigurationUtils.isMinimizeInsteadOfHide())
    {
        mainFrame.setFrameVisible(true);
    }

    SwingUtilities.invokeLater(new RunLoginGui());

    this.initExportedWindows();

    KeyboardFocusManager focusManager
        = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addKeyEventDispatcher(
            new KeyBindingsDispatching(focusManager));
}
项目:jitsi    文件:UIServiceImpl.java   
/**
 * Indicates that a <tt>PropertyChangeEvent</tt> has occurred.
 *
 * @param evt the <tt>PropertyChangeEvent</tt> that notified us
 */
public void propertyChange(PropertyChangeEvent evt)
{
    String propertyName = evt.getPropertyName();

    if (propertyName.equals(
        "impl.gui.IS_TRANSPARENT_WINDOW_ENABLED"))
    {
        String isTransparentString = (String) evt.getNewValue();

        boolean isTransparentWindowEnabled
            = Boolean.parseBoolean(isTransparentString);

        try
        {
            WindowUtils.setWindowTransparent(   mainFrame,
                isTransparentWindowEnabled);
        }
        catch (UnsupportedOperationException ex)
        {
            logger.error(ex.getMessage(), ex);

            if (isTransparentWindowEnabled)
            {
                ResourceManagementService resources
                    = GuiActivator.getResources();

                new ErrorDialog(
                        mainFrame,
                        resources.getI18NString("service.gui.ERROR"),
                        resources.getI18NString(
                                "service.gui.TRANSPARENCY_NOT_ENABLED"))
                    .showDialog();
            }

            ConfigurationUtils.setTransparentWindowEnabled(false);
        }
    }
    else if (propertyName.equals(
        "impl.gui.WINDOW_TRANSPARENCY"))
    {
        mainFrame.repaint();
    }
}