How to detect when the form is maximized?


I would like to detect when the form is going to be maximized to save certain settings (not related to the size nor position) and modify the size and position a little bit. Is there an universal way to do it ? I've tried to catch the WM_SYSCOMMAND message like in this article. It works well for maximization from menu, by maximize button, but it's not fired when I press the WIN + UP keystroke. Does anyone know an universal way how to catch the maximization event including the case with WIN + UP keystroke ?


You can use the WM_GETMINMAXINFO message to save the state of the window and then use the WMSize message to check if the window was maximized.

in you form declare the mesage handler like so :

procedure WMSize(var Msg: TMessage); message WM_SIZE;

And handle like this :

procedure TForm57.WMSize(var Msg: TMessage);
  if Msg.WParam  = SIZE_MAXIMIZED then