-1

I want to minimize all application that are running in the system, except mine. How can i do this?

I used this code but it works only on some computers:

procedure MinAllWnd_ByShell;
VAR IntHwnd: Integer;
begin
 IntHwnd:= FindWindow('Shell_TrayWnd', nil);
 PostMessage(IntHwnd, WM_COMMAND, 419, 0);
end;

then

procedure TFrmMain.btnMinimizeAll_Click(Sender: TObject);
begin
 { Send MINIMIZE message }
 MinAllWnd_ByShell;                                                            { This sends a message to Windows. Windows sends the minimize signal back to us after a delay }
 Delay(150);                                                                   { We wait few miliseconds to receive the message in our message queue }
 Application.ProcessMessages;                                                  { By now we should have received the message so we process the queue. }

 { Now self restore }
 BringToFront;
 ShowWindow(frmMain.Handle, SW_RESTORE);
end;

.


Delphi XE/Win XP/Win 7

TLama
  • 75,147
  • 17
  • 214
  • 392
Gabriel
  • 20,797
  • 27
  • 159
  • 293

1 Answers1

3

I am not saying this is a good idea, but you could try to replace the 419 with a simulated Win+M:

keybd_event(VK_LWIN, 0, 0, 0);
keybd_event(ord('M'), 0, 0, 0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384