• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 762
  • Last Modified:

Detect Minimize on form?

How do I execute a procedure on Minimize (form) ?
0
sunemangs
Asked:
sunemangs
  • 3
  • 2
  • 2
  • +3
1 Solution
 
sunemangsAuthor Commented:
Edited text of question.
0
 
haehnenCommented:
Hi,
you can't execute a procedure on a (really) minimized Form.
You must, Height and Width to 0 and BorderStyle:=bsNone.
Then you "simulat" a "minimized" Form. And you can execute your procedure.
bye
0
 
rwilson032697Commented:
LIke this:

procedure TForm1.FormResize(Sender: TObject);
begin
  If WindowState = wsMinimized then
    begin
      ShowMessage('The form has been minimised...');
    end;
end;

Cheers,

Raymond.
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
sunemangsAuthor Commented:
It doesn't work - as Haehnen wrote. When Executing Form1.Resize, WindowsState = wsNormal. Not wsMinimized.

Isn't it possible to fix this without "simulating" minimized?

Regards

/Sune
0
 
kretzschmarCommented:
hi sunemangs,

does this help?

unit f_mini_u;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    Procedure MyOnMinimize(Sender : TObject);
    Procedure MyOnRestore(Sender : TObject);
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

Procedure TForm1.MyOnMinimize(Sender : TObject);
begin
  Application.Title := 'Now Minimized';  //Look at the taskbarButton
end;

Procedure TForm1.MyOnRestore(Sender : TObject);
begin
  Application.Title := 'Now Restored'; //Look at the taskbarButton
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMinimize := MyOnMinimize;
  Application.OnRestore := MyOnRestore;
  Application.Title := 'Something'; //Look at the taskbarButton
end;

end.

meikl
0
 
maharaCommented:
can you please describe it more clearly? i wonder if i really understood the problem. if i did, i think i might have the answer...
0
 
gallagheCommented:
The following code uses WM_SYSCOMMAND to detect when a
request is made to minimize your form.


type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMSysCommand(var Msg: TWMSysCommand);
      message WM_SYSCOMMAND;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMSysCommand;
begin
  case (msg.cmdtype and $FFF0) of
    SC_MINIMIZE: { Do something }
    SC_MAXIMIZE: { Do something }
    SC_RESTORE:  { Do something }
    else
      inherited;
    end;
end;

Note: If you need to double check else were if the form is
in a minimized state refer to
BOOL IsIconic(

    HWND  hWnd       // handle of window
   );

i.e.
if IsIconic(Application.Handle) then
  ...


Kevin
0
 
gallagheCommented:
----------------------------------
My proposed answer needs a change.
----------------------------------
I have "inherited" in the "Else" portion of the Case statement. Having this prohibits any actions to occur from the users request,so this is the revised code:

procedure TForm1.WMSysCommand;
begin
  case (msg.cmdtype and $FFF0) of
    SC_MINIMIZE: ShowMEssage('Min');
    SC_MAXIMIZE: ShowMEssage('Max');
    SC_RESTORE:  ShowMEssage('res');
//    else
//      inherited;
    end;
  inherited;
end;

Originally I was using the code to stop minimizing,
maximizing... which is why I coded "inherited" in the
"else" clause.

Kevin
0
 
kretzschmarCommented:
hi kevin (gallaghe),

i've provided your answer here on this q

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10193472 

be free to lock this q

meikl
0
 
sunemangsAuthor Commented:
Thank you guys, works very well. Your help is invaluable!

I am just curious, are you able to see my comment, although if I accept the answer?

Regards

/Sune

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now