Solved

Intercepting maximization in a form

Posted on 1998-12-19
3
668 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

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

864 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

16 Experts available now in Live!

Get 1:1 Help Now