How to embed a form from a DLL into an Inno Setup wizard page?

a 夏天 提交于 2019-12-10 21:18:37

问题


I've built some VCL forms in Delphi DLL's which show during the Inno Setup installation. However, it would be much more concise if I could embed these forms into the Inno Setup wizard.

How can I go about doing this?


回答1:


The simplest way for you will be to create an exported function which will do all the stuff in your library. The necessary minimum for such function is a parameter for the handle of the Inno Setup control into which your form should be embedded. The next necessary thing you need to know for embedding are bounds, but those you can get with the Windows API function call on the library side.

Here is the Delphi part showing the unit with the form from your DLL project:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  TEmbeddedForm = class(TForm)
    StringGrid1: TStringGrid;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  end;

procedure CreateEmbeddedForm(ParentWnd: HWND); stdcall;

implementation

{$R *.dfm}

{ TEmbeddedForm }

procedure TEmbeddedForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

{ CreateEmbeddedForm }

procedure CreateEmbeddedForm(ParentWnd: HWND); stdcall;
var
  R: TRect;
  Form: TEmbeddedForm;
begin
  Form := TEmbeddedForm.Create(nil);
  Form.ParentWindow := ParentWnd;
  Form.BorderStyle := bsNone;
  GetWindowRect(ParentWnd, R);
  Form.BoundsRect := R;
  Form.Show;
end;

exports
  CreateEmbeddedForm;

end.

And here is the Inno Setup script:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Files]
Source: "MyDLL.dll"; Flags: dontcopy

[Code]
procedure CreateEmbeddedForm(ParentWnd: HWND);
  external 'CreateEmbeddedForm@files:MyDLL.dll stdcall';

procedure InitializeWizard;
var
  CustomPage: TWizardPage;
begin
  CustomPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');
  CreateEmbeddedForm(CustomPage.Surface.Handle);
end;

Just to note, Inno Setup supports also COM Automation, so the above way is not the only option how to embed an object into the wizard form. However, it's the simplest one.

Oh, and yet one note, which might be good for you to know. If you'd ever need to execute a certain Inno Setup script code from your library, you could do it by making a callback function on the Inno Setup side and passing and executing it on the DLL side.



来源:https://stackoverflow.com/questions/21795300/how-to-embed-a-form-from-a-dll-into-an-inno-setup-wizard-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!