Max Smith
Max Smith

Reputation: 405

Minimizing application following Windows Show desktop command when modal form is opened

I have a multiple form application and open one of my forms using ShowModal. Is there a way to minimize the whole application when Show Desktop command in Windows is envoked?

P.S. Delphi 2009, Win 7

My code:

unit Unit1;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
     Form2.ShowModal;
end;

end.

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

end.

DPR:

program Project1;

uses
  ExceptionLog,
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

Upvotes: 2

Views: 268

Answers (1)

user4846140
user4846140

Reputation:

I just tried it on D2007 and Win 8.1 It behaves as it should, with or without the button press. Maybe there is an issue with your windows itself. I note that you have uses ExceptionLog in the dpr file. - This would be the culprit.

Upvotes: 1

Related Questions