The notification that the OS sends to the window when its status has been changed is a WM_SIZE message. This is not obvious from the code quote you quoted, but VCL is already listening on the WM_SIZE class in TScrollingWinControl ( TCustomForm ) and invokes the Resizing virtual procedure during message processing.
Thus, you can override this method of your form to receive a notification.
type TForm1 = class(TForm) .. protected procedure Resizing(State: TWindowState); override; .... procedure TForm1.Resizing(State: TWindowState); begin inherited; case State of TWindowState.wsNormal: ; TWindowState.wsMinimized: ; TWindowState.wsMaximized: ; end; end;
Please note that a notification can be sent several times for a given state, for example, when changing the size of the window or changing the visibility. You may need to keep track of the previous value to find out when the state is really changed.
Depending on your requirements, you can also use the OnResize event of the form. The difference is that this event is fired before the OS notifies the window of the change. VCL retrieves window status information by calling GetWindowPlacement , and TCustomForm processes WM_WINDOWPOSCHANGING .
The following is an example of using a flag to track the status of a previous window.
TForm1 = class(TForm) .. private FLastWindowState: TWindowState; // 0 -> wsNormal (initial value) ... procedure TForm1.FormResize(Sender: TObject); begin if WindowState <> FLastWindowState then case WindowState of TWindowState.wsNormal: ; TWindowState.wsMinimized: ; TWindowState.wsMaximized: ; end; FLastWindowState := WindowState; end;
source share