Я в свое время тоже над этим бился...
Вот такая конструкция получилась (Delphi 10.2.3):
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
FMX.Platform.Win,
FMX.Platform,
Winapi.Windows,
Winapi.Messages,
FMX.Memo;
type
TForm1 = class(TForm)
private
type
TShowAction = (saNone, saNormal, saMinimize, saMaximize);
protected
procedure CreateHandle; override;
private
AppIsActive : Boolean;
FOldFMXWndProc : TFNWndProc;
FNewFMXWndProc : Pointer;
FShowAction: TShowAction;
procedure FMXFormWndProc(var Msg: Winapi.Messages.TMessage);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.CreateHandle;
var
H : HWND;
begin
inherited CreateHandle;
H := FormToHWND(Self);
FOldFMXWndProc := TFNWndProc(GetWindowLong(H, GWL_WNDPROC));
FNewFMXWndProc := MakeObjectInstance(FMXFormWndProc);
SetWindowLong(H, GWL_WNDPROC, NativeInt(FNewFMXWndProc));
end ;
procedure TForm1.FMXFormWndProc(var Msg: Winapi.Messages.TMessage);
begin
case Msg.Msg of
WM_SHOWWINDOW :
begin
case TWMShowWindow(Msg).Status of
SW_PARENTCLOSING:
if FShowAction = saNone then
begin
if IsIconic(FormToHWND(Self)) then
FShowAction := saMinimize
else
if IsZoomed(FormToHWND(Self)) then
FShowAction := saMaximize
else
FShowAction := saNormal;
TThread.CurrentThread.ForceQueue(nil,
procedure
begin
SendMessage(FormToHWND(Self),WM_SYSCOMMAND, SC_MINIMIZE,0);
WindowState := TWindowState.wsMinimized;
end);
end;
SW_PARENTOPENING:
if FShowAction <> saNone then
begin
if FShowAction = saMaximize then
WindowState := TWindowState.wsMaximized
else
if FShowAction = saNormal then
WindowState := TWindowState.wsNormal;
FShowAction := saNone;
exit;
end;
end;
end;
WM_NCACTIVATE :
begin
if (Msg.WParam = 0) then
Msg.WParam := Byte(AppIsActive);
end;
end;
Msg.Result := CallWindowProc(FOldFMXWndProc, FormToHWND(Self), Msg.Msg, Msg.WParam, Msg.LParam);
case Msg.Msg of
WM_ACTIVATEAPP :
begin
AppIsActive := Msg.WParam = 1 ;
end ;
end;
end;
end.