Solved

Detecting if form minimized

Posted on 1997-06-24
3
292 Views
Last Modified: 2010-04-03
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
0
Comment
Question by:Stuart_Johnson
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
CFantin earned 50 total points
ID: 1337743
You can Check the if the WindowState property is wsMinimized.
This property is updated when you form state is changed.
Therefore you can check if the form is Maximized or normal as well with the wsMaximized and wsNormal.

Hope this helps
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1337744
Edited text of question
0
 
LVL 1

Expert Comment

by:CFantin
ID: 1337745
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get a Metafile from Clipboard and convert it into a PNG to save to file or stream. 2 96
Delphi OLE Error 8 93
find a node in VST 2 63
Base1 Encode/Decode 3 67
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now