Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InnoSetup: Is it possible to open my custom Delphi form (from the DLL) instead of the standard setup wizard

I need to create a complex form with my own components (kinda OneClick installer), and use it as the replacement of the standard InnoSetup wizard. Is it possible?

My form is placed into DLL, and this DLL will be available for InnoSetup process.

This is how I tried to do that:

Delphi DLL code

library OneClickWizard;

uses
  SysUtils,
  Classes,
  Wizard in 'Wizard.pas' {FormWizard};

{$R *.res}

exports
  CreateWizardForm,
  DestroyWizardForm;

begin
end.

Delphi form

unit Wizard;

interface

type
  TFormWizard = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormWizard: TFormWizard;

procedure CreateWizardForm(AppHandle: THandle); stdcall;
procedure DestroyWizardForm; stdcall;

implementation

{$R *.dfm}

procedure CreateWizardForm(AppHandle: THandle);
begin
  Application.Handle := AppHandle;
  FormWizard := TFormWizard.Create(Application);
  FormWizard.Show;
  FormWizard.Refresh;
end;

procedure DestroyWizardForm;
begin
  FormWizard.Free;
end;

InnoSetup script (iss)

[Setup]
;Disable all of the default wizard pages
DisableDirPage=yes
DisableProgramGroupPage=yes
DisableReadyMemo=true
DisableReadyPage=true
DisableStartupPrompt=true
DisableWelcomePage=true
DisableFinishedPage=true

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

[Code]
procedure CreateWizardForm(AppHandle: Cardinal); 
  external 'CreateWizardForm@files:OneClickWizard.dll stdcall';
procedure DestroyWizardForm;
  external 'DestroyWizardForm@files:OneClickWizard.dll stdcall';


procedure InitializeWizard();
begin
  CreateWizardForm(MainForm.Handle);
end;

The form appearing on the screen, but it doesn't react on my input. Seems it is out of main message cycle. How to do this correctly?

like image 297
Andrew Avatar asked Dec 21 '11 07:12

Andrew


1 Answers

In my setup I do something similar. InnoSetup code I pass the handle as StrToInt(ExpandConstant('{wizardhwnd}')) (my guess is that MainForm.Handle is zero)

in the DLL:

OldAppHandle := Application.Handle;
try
  Application.Handle := hAppHandle; // hAppHandle the handle from InnoSetup
  F := TfmZForm.Create(Application);
  try
    F.Caption := lpTitle;
    F.ShowModal;
    Result := F.ErrorCode;
  finally
    F.Free;
  end;
finally
  Application.Handle := OldAppHandle;
end;
like image 181
kobik Avatar answered Nov 15 '22 02:11

kobik