Firemonkey MacOS 应用程序 - 关闭与退出
Firemonkey MacOS app - Close vs Quit
我使用 Firemonkey XE8 开发了一个 MacOS 应用程序,我注意到主窗体的 X 按钮实际上终止了应用程序而不是 hiding/minimizing 它,因为它是大多数 MacOS 应用程序的默认行为.
为了解决这个问题,我在 FormCloseQuery 中添加了以下逻辑,以便在有人单击 X 按钮时最小化应用程序:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
{$IFDEF MACOS}
if (Self.WindowState<>TWindowState.wsMinimized) then begin
Self.WindowState:=TWindowState.wsMinimized;
CanClose:=false;
end
else
CanClose:=true;
{$ENDIF MACOS}
end;
这有效,但副作用是如果有人在 Dock 中右键单击应用程序并 select 退出,如果表单尚未最小化,应用程序将被最小化。所以用户应该点击退出两次才能真正关闭应用程序。
有什么办法可以解决这个问题吗?关闭按钮应该 hide/minimize window 并且 Quit 应该终止应用程序。
我没有苹果电脑,但我已经在 Windows 上测试了这段代码,它可以工作。
(XE2 FM 应用程序)
uses
fmx.platform
procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
p:TPointF;
begin
p := Platform.GetMousePos;
p := ScreenToClient(p);
if p.Y > 0 then
CanClose := True
else
begin
Self.WindowState:=TWindowState.wsMinimized;
CanClose:=false;
end;
end;
行为没有不同。
- 关闭 "MainForm" 将终止应用程序
- 关闭 "SubForm" 只会关闭该表单
您刚刚从 多文档应用程序 注意到 MacOS 上的这种行为(与 Windows 已知的 MDI 相当)。
我使用 Firemonkey XE8 开发了一个 MacOS 应用程序,我注意到主窗体的 X 按钮实际上终止了应用程序而不是 hiding/minimizing 它,因为它是大多数 MacOS 应用程序的默认行为.
为了解决这个问题,我在 FormCloseQuery 中添加了以下逻辑,以便在有人单击 X 按钮时最小化应用程序:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
{$IFDEF MACOS}
if (Self.WindowState<>TWindowState.wsMinimized) then begin
Self.WindowState:=TWindowState.wsMinimized;
CanClose:=false;
end
else
CanClose:=true;
{$ENDIF MACOS}
end;
这有效,但副作用是如果有人在 Dock 中右键单击应用程序并 select 退出,如果表单尚未最小化,应用程序将被最小化。所以用户应该点击退出两次才能真正关闭应用程序。
有什么办法可以解决这个问题吗?关闭按钮应该 hide/minimize window 并且 Quit 应该终止应用程序。
我没有苹果电脑,但我已经在 Windows 上测试了这段代码,它可以工作。 (XE2 FM 应用程序)
uses
fmx.platform
procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
p:TPointF;
begin
p := Platform.GetMousePos;
p := ScreenToClient(p);
if p.Y > 0 then
CanClose := True
else
begin
Self.WindowState:=TWindowState.wsMinimized;
CanClose:=false;
end;
end;
行为没有不同。
- 关闭 "MainForm" 将终止应用程序
- 关闭 "SubForm" 只会关闭该表单
您刚刚从 多文档应用程序 注意到 MacOS 上的这种行为(与 Windows 已知的 MDI 相当)。