Firemonkey 应用失焦

Firemonkey app out of focus

所以,我正在制作 firemonkey 应用程序,对于我的 vcl 应用程序,我能够使用 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); 因此,如果其他东西(浏览器)目前处于焦点状态,我的应用程序将始终位于最前面。我正在尝试找到与 firemonkey 类似的东西,有什么想法吗? P.S。 firemonkey 的代码将放置在某些隐藏的 Tedit 的 OnChange 事件上。如果有帮助..

你的代码仍然可以正常工作,除了在 FMX 中,TFormHandle 现在是 TWindowHandle 类型,而它以前是 HWND 类型VCL。您只需将 TWindowHandle 转换为 HWND,这样您就可以像以前一样将其传递给 SetWindowPos(..)

在我选择的互联网搜索引擎中输入 firemonkey window handle 会得到很多解决方案,其中有几个就在 Whosebug 上。长话短说:使用FMX.Platform.Win.WindowHandleToPlatform(..)转换。

示例:

implementation

uses
  Fmx.Platform.Win,
  WinApi.Windows;

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
var
    nativeWindowHandle: HWND;
begin
    nativeWindowHandle := Fmx.Platform.Win.WindowHandleToPlatform(Handle).Wnd;
    // TODO: Check for error when SetWindowPos returns false
    SetWindowPos(nativeWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);
end;