Question

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) {
}
Was it helpful?

Solution 2

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...

OTHER TIPS

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

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

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

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);

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top