Stuart_Johnson
asked on
Detecting if form minimized
Can anyone tell me how to detect if a form is minimized? I cannot find any info on this at all.
Ok. I already had a procedure OnResize, but when the minimize button is pressed, the program does not even trace to this procedure.
I know the OnResize procedure is working, because if the window is moved, this procedure is called perfectly.
I need to know if there is an API which detects when the minimize button is pressed.
Any help would be appreciated.
Stuart
Ok. I already had a procedure OnResize, but when the minimize button is pressed, the program does not even trace to this procedure.
I know the OnResize procedure is working, because if the window is moved, this procedure is called perfectly.
I need to know if there is an API which detects when the minimize button is pressed.
Any help would be appreciated.
Stuart
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a bit of code to detect the Minimize, Maximize and restore of a form.
The windows message WM_SYSCOMMAND is captured as well as creating
a message handler for the application.
The message handler for the form needs to be there because when the user right clicks the application button in 95 the windows message for the form is not created but instead the windows message is sent to the application.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
WINTYPES, WINPROCS, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
procedure WMSIZE(var Msg: TMessage); message WM_SYSCOMMAND;
procedure MyMessage(var Msg: TMSG; var Handled: Boolean);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMSIZE(var Msg: TMessage);
begin
inherited;
case Msg.WParam of
SC_MINIMIZE: ShowMessage('Minimize');
SC_MAXIMIZE: ShowMessage('Maximize');
SC_RESTORE: ShowMessage('Restore');
end;
end;
procedure TForm1.MyMessage(var Msg: TMsg; var Handled: Boolean);
begin
if (Msg.Message = WM_SYSCOMMAND) then
begin
case Msg.wParam of
SC_MINIMIZE: ShowMessage('Minimize');
SC_MAXIMIZE: ShowMessage('Maximize');
SC_RESTORE: ShowMessage('Restore');
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := MyMessage;
end;
end.
Try this out...
Good luck
The windows message WM_SYSCOMMAND is captured as well as creating
a message handler for the application.
The message handler for the form needs to be there because when the user right clicks the application button in 95 the windows message for the form is not created but instead the windows message is sent to the application.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
WINTYPES, WINPROCS, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
procedure WMSIZE(var Msg: TMessage); message WM_SYSCOMMAND;
procedure MyMessage(var Msg: TMSG; var Handled: Boolean);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMSIZE(var Msg: TMessage);
begin
inherited;
case Msg.WParam of
SC_MINIMIZE: ShowMessage('Minimize');
SC_MAXIMIZE: ShowMessage('Maximize');
SC_RESTORE: ShowMessage('Restore');
end;
end;
procedure TForm1.MyMessage(var Msg: TMsg; var Handled: Boolean);
begin
if (Msg.Message = WM_SYSCOMMAND) then
begin
case Msg.wParam of
SC_MINIMIZE: ShowMessage('Minimize');
SC_MAXIMIZE: ShowMessage('Maximize');
SC_RESTORE: ShowMessage('Restore');
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := MyMessage;
end;
end.
Try this out...
Good luck
ASKER