我使用 this question中描述的技巧在VCL应用程序中的TPanel上显示FireMonkey表单.我的问题是单击(控件)嵌入的表单导致VCL表单(包含该TPanel)被取消激活.最明显的结果是窗口边框一直在变色. 当
当在另一个的TPanel上显示VCL表单时,这不会发生;表格显然是“合并”.我应该怎么做才能使用FireMonkey获得类似的结果?我希望FireMonkey表单上的控件可用,但保持父表单激活.
更新1
VCL
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, FMX.Forms, Vcl.Forms,
Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, FMX.Platform.Win;
type
TMainForm = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses FireMonkeyForms;
procedure TMainForm.Button1Click(Sender: TObject);
var
LFMForm: FireMonkeyForms.TForm1;
LFMHWnd: HWND;
begin
LFMForm := FireMonkeyForms.TForm1.Create(nil);
LFMForm.Left := 0;
LFMForm.Top := 0;
LFMForm.Height := Panel1.ClientHeight;
LFMForm.Width := Panel1.ClientWidth;
LFMForm.BorderStyle := TFmxFormBorderStyle.bsNone;
LFMForm.BorderIcons := [];
LFMHWnd := FmxHandleToHWND(LFMForm.Handle);
SetWindowLong(LFMHWnd, GWL_STYLE, GetWindowLong(LFMHwnd, GWL_STYLE) or WS_CHILD);
Winapi.Windows.SetParent(LFMHWnd, Panel1.Handle);
LFMForm.Visible := True;
end;
end.
FireMonkey
unit FireMonkeyForms;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Layouts, FMX.Memo;
type
TForm1 = class(TForm)
Label1: TLabel;
Memo1: TMemo;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
end.
行为的原因是窗口管理器不知道您已将firemonkey窗口设为子窗口,因此在激活firemonkey窗口时它将停用先前活动的窗口.如
SetParent function中所述,您必须手动设置子标志.示例用法可以是:
var FMForm: TFMForm1; FMHWnd: HWND; begin FMForm := TFMForm1.Create(nil); FMForm.Left := 0; FMForm.Top := 0; FMHWnd := FmxHandleToHWND(FMForm.Handle); SetWindowLong(FMHWnd, GWL_STYLE, GetWindowLong(FMHwnd, GWL_STYLE) or WS_CHILD); winapi.windows.SetParent(FMHWnd, Panel1.Handle); FMForm.Visible := True;
更新:
如果必须删除fmx表单的边框,则设置BorderStyle会设置WS_CHILD样式,而WS_CHILD样式不能与WS_CHILD一起使用.在这种情况下,请明确设置您需要的样式,而不是获取和“或”它们. F.i.
.. LFMForm.BorderIcons := []; LFMForm.BorderStyle := TFmxFormBorderStyle.bsNone; LFMHWnd := FmxHandleToHWND(LFMForm.Handle); SetWindowLong(LFMHWnd, GWL_STYLE, WS_CHILDWINDOW or WS_BORDER); ..
