Solved

Intercepting maximization in a form

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 191
Delphi Form ownership 4 126
Open a URL with Internet Explorer in a new tab (not a new window) 1 147
shape, triangle, dbctrlgrid 3 32
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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