Minimize all other applications excluding my own program

末鹿安然 提交于 2019-12-24 13:22:36

问题


I am trying to minimize all running applications in Windows when running my own program. I am using the following code, but it's minimizing the all windows including my program. Is there any way that I can minimize the applications excluding my program?

My code is following:

try {
    Runtime.getRuntime().exec(
        new String[]{
            "cmd.exe",
            "/c",
            "\"" + System.getenv("APPDATA") +
            "\\Microsoft\\Internet Explorer\\Quick Launch\\Show Desktop.scf\""});
} catch (Exception ex) {
}

回答1:


Why don't you use JNA, it gives you scores of options to play with windows... this is how you do it using JNA. download JNA.jar

HWND hwnd = User32.INSTANCE.FindWindow(null, nameOfWindow); // window title 
User32.INSTANCE.ShowWindow(hwnd, 9); // SW_RESTORE
User32.INSTANCE.SetForegroundWindow(hwnd); // bring to front

Hope this helps...




回答2:


I am trying to minimize all running applications in windows when running my own program

Don't do that. Instead, do either of:

  • Call setAlwaysOnTop(true) (and slug it out with every other app. that wants to be always on top).
  • Use Full Screen Exclusive Mode. You get to (have to) paint every pixel of the screen, other apps. become irrelevant.

Both those solutions are cross-platform & will work for Windows, Linux/Unix & OS X.




回答3:


You can send Windows+D hotkey or Fn + F11 under Mac:

Robot r = new Robot();
r.setAutoDelay(250);
r.keyPress(KeyEvent.VK_WINDOWS);
r.keyPress(KeyEvent.VK_D);
r.keyRelease(KeyEvent.VK_D);
r.keyRelease(KeyEvent.VK_WINDOWS);



回答4:


This works for me.

import java.awt.Robot;
import java.awt.event.KeyEvent;

{ 
Robot r = null;
    try {
        r = new Robot();
    } catch (AWTException ex) {
        Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
    }
r.setAutoDelay(250);
r.keyPress(KeyEvent.VK_WINDOWS);
r.keyPress(KeyEvent.VK_D);
r.keyRelease(KeyEvent.VK_D);
r.keyRelease(KeyEvent.VK_WINDOWS);
}


来源:https://stackoverflow.com/questions/18973185/minimize-all-other-applications-excluding-my-own-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!