?
Solved

Detect Minimize on form?

Posted on 1999-08-11
10
Medium Priority
?
760 Views
Last Modified: 2012-05-05
How do I execute a procedure on Minimize (form) ?
0
Comment
Question by:sunemangs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 

Author Comment

by:sunemangs
ID: 1394041
Edited text of question.
0
 

Expert Comment

by:haehnen
ID: 1394042
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1394043
LIke this:

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

Cheers,

Raymond.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:sunemangs
ID: 1394044
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1394045
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
 
LVL 2

Expert Comment

by:mahara
ID: 1394046
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
 
LVL 2

Accepted Solution

by:
gallaghe earned 120 total points
ID: 1394047
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
 
LVL 2

Expert Comment

by:gallaghe
ID: 1394048
----------------------------------
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1394049
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
 

Author Comment

by:sunemangs
ID: 1394050
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

719 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