delphi - 将应用程序(exe 文件)嵌入到另一个 exe 文件中(类似 mozEmbed)

标签 delphi firefox embed dde

我想将 mozilla firefox 嵌入到我的应用程序中,而不使用任何 activex 控件(TWebBrowser 包装器、mozilla ActiveX...)。我尝试使用 TWebBrowser(实际上 bsalsa 的嵌入式 webBrowser 效果要好得多),但所有版本的 IE 似乎都与流行的 javascript 框架和库(JQuery、ExtJS...)的某些功能不兼容。

我的问题是:我可以从我的应用程序中调用 firefox 的 Exe(是否可以使用 DDE 或 OLE),最重要的是使用 TFrame 或类似的东西在我的应用程序中显示它?

等待您的建议 问候,M

最佳答案

您需要稍微清理一下代码,并弄清楚如何与 Firefox 进行“对话”。
以下是如何将任何应用程序嵌入到 Delphi 表单中。

DFM 文件

object frmMain: TfrmMain
  Left = 195
  Top = 154
  Width = 527
  Height = 363
  Caption = 'Containership Test'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  DesignSize = (
    519
    329)
  PixelsPerInch = 96
  TextHeight = 13
  object pnlTop: TPanel
    Left = 0
    Top = 0
    Width = 519
    Height = 292
    Align = alTop
    Anchors = [akLeft, akTop, akRight, akBottom]
    BevelInner = bvLowered
    TabOrder = 0
  end
  object btnLoadApp: TButton
    Left = 172
    Top = 297
    Width = 75
    Height = 25
    Anchors = [akLeft, akBottom]
    Caption = 'Load'
    TabOrder = 1
    OnClick = btnLoadAppClick
  end
  object btnKill: TButton
    Left = 260
    Top = 297
    Width = 75
    Height = 25
    Anchors = [akLeft, akBottom]
    Caption = 'Kill'
    TabOrder = 2
    OnClick = btnKillClick
  end
end

main.pas文件

unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ShellApi;

type
  TfrmMain = class(TForm)
    pnlTop: TPanel;
    btnLoadApp: TButton;
    btnKill: TButton;
    procedure btnLoadAppClick(Sender: TObject);
    procedure btnKillClick(Sender: TObject);
  private
    { Private declarations }
    AppWnd : DWORD;
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.btnLoadAppClick(Sender: TObject);
var
  ExecuteFile : string;
  SEInfo: TShellExecuteInfo;
begin
  ExecuteFile:='c:\Windows\notepad.exe';

  FillChar(SEInfo, SizeOf(SEInfo), 0) ;
  SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
  with SEInfo do
  begin
    fMask := SEE_MASK_NOCLOSEPROCESS;
    Wnd := pnlTop.Handle;
    lpFile := PChar(ExecuteFile) ;
    nShow := SW_HIDE;
  end;
  if ShellExecuteEx(@SEInfo) then
  begin
    AppWnd := FindWindow(nil, PChar('Untitled - Notepad'));
    if AppWnd <> 0 then
    begin
      Windows.SetParent(AppWnd, SEInfo.Wnd);
      ShowWindow(AppWnd, SW_SHOWMAXIMIZED);
      ShowWindow(AppWnd, SW_SHOWMAXIMIZED);
    end;
  end
  else
    ShowMessage('Error starting notepad!') ;
end;

procedure TfrmMain.btnKillClick(Sender: TObject);
begin
  if (AppWnd <> 0) then
  begin
    PostMessage(AppWnd, WM_Close, 0, 0);
    AppWnd := 0;
  end;
end;

end.

关于delphi - 将应用程序(exe 文件)嵌入到另一个 exe 文件中(类似 mozEmbed),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2154560/

相关文章:

delphi - 如何在 Delphi 10.3.3 中访问 TWebBrowser.Document 时克服内存泄漏

delphi - 在构建时更改版本号

jquery - 当 URL 结束时告诉 jQuery?

delphi - 如何销毁运行时定义的 TClientDataSet TFields?

multithreading - 在线程停止时关闭窗口

安卓模拟器 : Adding FireFox app?

c# - 在加载了 firefox 插件的 selenium 中打开 firefox 窗口?

javascript - 文档就绪()在 firefox 中不工作,为 DOM 元素提供 null...ie7 工作正常

html - 如何在我的网站上嵌入 Flash 对象?

html - YouTube嵌入式视频不能在我的所有浏览器中运行:FireFox,IE和Chrome