Project: SWT
Bug 37782 Shell setMinimized(true) doesn't deactivate Shell
Reported: 2003-05-16 14:42:43 | Status: resolved fixed

Calling setMinimized(true) on a shell doesn't behave in the same way as clicking on the minimize button of the title bar. Specifically, calling setMinimized doesn't cause the shell to become deactivated. The following code snipped illustrates the problem: public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setLayout(new FillLayout(SWT.HORIZONTAL)); final Button current = new Button(shell, SWT.PUSH); current.setText("Minimize (Current)"); final Button proposed = new Button(shell, SWT.PUSH); proposed.setText("Minimize (Proposed)"); Listener l = new Listener() { public void handleEvent(Event e) { System.out.print("Minimize "); if(e.widget == current) { System.out.println(" (Current)"); shell.setMinimized(true); } else if (e.widget == proposed) { System.out.println(" (Proposed)"); OS.SendMessage(shell.handle, OS.WM_SYSCOMMAND, OS.SC_MINIMIZE, 0); } System.out.println("Active Shell: " + display.getActiveShell()); } }; current.addListener(SWT.Selection, l); proposed.addListener(SWT.Selection, l); shell.addListener(SWT.Deactivate, new Listener() { public void handleEvent(Event e) { System.out.println("Shell Deactivated"); } }); shell.pack(); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } Clicking the "Minimize (Current)" button causes the shell to be minimized but it remains active. Hence, no deactivate event is fired (but one is fire when you click on the shell in the taskbar to restore it!), and the application under the shell (if there is one) doesn't become active. Clicking on the "Minimize (Proposed)" button minimizes the shell and does cause it to be become deactivated. Hence, the above issues are resolved. My proposal is that the setMinimized method in Decorations be changed from: public void setMinimized (boolean minimized) { checkWidget (); if (OS.IsWinCE) return; swFlags = OS.SW_RESTORE; if (minimized) swFlags = OS.SW_SHOWMINNOACTIVE; if (!OS.IsWindowVisible (handle)) return; if (minimized == OS.IsIconic (handle)) return; OS.ShowWindow (handle, swFlags); OS.UpdateWindow (handle); } to public void setMinimized (boolean minimized) { checkWidget (); if (OS.IsWinCE) return; swFlags = OS.SW_RESTORE; if (minimized) swFlags = OS.SW_SHOWMINNOACTIVE; if (!OS.IsWindowVisible (handle)) return; if (minimized == OS.IsIconic (handle)) return; int flag = (minimized) ? OS.SC_MINIMIZE : OS.SC_RESTORE; OS.SendMessage(handle, OS.WM_SYSCOMMAND, flag, 0); }

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java