1.创建2个工程,一个是window application ,一个bpl 工程(multi-device Forml),创建方式见:
在delphi Form窗体调用Fmx窗体_zjg076000的博客-CSDN博客(这里不再重复)
2.调整一下windows应用的界面,放入panel 来嵌入fmx窗体
3.编写代码
文章来源地址https://www.toymoban.com/news/detail-484043.html
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,testfmxform, Vcl.ExtCtrls;type
TForm2 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Panel2: TPanel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
privatepublic
FmxForm: Tfrmtestfrmform;
FMHWnd: HWND;
end;var
Form2: TForm2;implementation
uses FMX.Platform.Win,FMX.Forms;
{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
frmtestfrmform:=tfrmtestfrmform.Create(self);
frmtestfrmform.ShowModal;
end;procedure TForm2.Button2Click(Sender: TObject);
beginFmxForm := Tfrmtestfrmform.Create(panel2);
FmxForm.Left :=0;
FmxForm.Top := 0;
FMHWnd := FmxHandleToHWND(FmxForm.Handle);SetWindowLong(FMHWnd, GWL_STYLE, GetWindowLong(FMHwnd, GWL_STYLE) or WS_CHILD);
Winapi.Windows.SetParent(WindowHandleToPlatform(FmxForm.Handle).Wnd, Panel2.Handle);
MoveWindow(WindowHandleToPlatform(FmxForm.Handle).Wnd, 0, 0, Round(Panel2.Width), Round(Panel2.Height), True);FmxForm.WindowState := wsMaximized;
FmxForm.Show;
FmxForm.EndUpdate;
end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FmxForm.Close;
end;procedure TForm2.FormResize(Sender: TObject);
begin
if FmxForm <> nil then
MoveWindow(WindowHandleToPlatform(FmxForm.Handle).Wnd, 0, 0, Round(Panel2.Width), Round(Panel2.Height), True);
end;end.
4.运行效果
文章来源:https://www.toymoban.com/news/detail-484043.html
到了这里,关于在delphi Form窗体的panel 中嵌入 Fmx窗体的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!