Solved

Intercepting maximization in a form

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

20 Experts available now in Live!

Get 1:1 Help Now