Solved

Intercepting maximization in a form

Posted on 1998-12-19
3
673 Views
Last Modified: 2008-02-20
I need to perform a procedure when a form is maximized or restored.
I used to write in OnResize, but it only works when you resize the window by its borders.
Any idea?

Thx.
0
Comment
Question by:forns
3 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 30 total points
ID: 1351965
Override the WM_MAXIMIZE method like this:

procedure WMMaximize(var Message : TMessage); message WM_MAXIMIZE;

Cheers,

Raymond.
0
 
LVL 1

Expert Comment

by:Oli2
ID: 1351966
On Resize also captures the resizing of the Form by the border icons !!
If that doesn't work in your app, then there might be an error somewhere else.

Try yourself:

Make a new app, with one TForm only.

then write to the OnResize event:

procedure Form1.OnResize ( Sender: TObject );
begin
    ShowMessage ( 'Resized!' );
end;

It doesn' work, if the Form was minimized into the Windows task bar and re-opened. Is that, what you mean? In that case, use OnPaint. ( Because the Form will get repainted ).

Greetings, Oli
0
 

Expert Comment

by:teechong
ID: 1351967
The message to intercept is WM_SIZE. The wparam part of the message tells whether the window (or form, in this case) is maximized or restored (but not minimized - this is a different story).

Remember to call inherited in your message handler though.

To handle the restore situation completely, you need a little extra work. Due to the TApplication architecture in Delphi, you need to assign an event handler for Application.OnRestore. This event is fired when the main form is minimized then restored (as opposed to maximized then restored).


SAMPLE:

TForm1 = class(TForm)
:
:
procedure WMSize (var msg : TWMSize); message WM_SIZE;
procedure AppRestore ( Sender : TObject );
:
end;

implementation

procedure TForm1.FormCreate ( Sender : TObject );
begin
   Application.OnRestore := AppRestore;
end;


procedure TForm1.AppRestore ( Sender : TObject );
begin
   ShowMessage ('appRestore');
end;

procedure TForm1.WMSize ( var msg: TWMSize );
begin
   inherited;
   case msg.SizeType of
      SIZE_MAXIMIZED: ShowMessage ('maximized');
      SIZE_RESTORED: ShowMessage ('restored');
   end;
end;


0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 102
Run video youtube webbrowse 10 65
Create a path if not exists 7 89
How to Get Images From Server to Client using App Tethering 1 26
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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