Solved

Intercepting maximization in a form

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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