2010-07-09 48 views
14

我正在使用Inno Setup(其惊人的!)。我希望定制安装程序,以便我可以接受来自用户的输入字段形式的字符串,并可能向其添加消息。Inno Setup:添加自定义输入字段

我该怎么做?我查看了文档,谷歌搜索,并没有多少出现!

感谢所有的帮助

+0

花了一段时间,我花了所有的假和断开的链接来找到isfd208.exe(InnoSetup窗体设计器2.08)。正如Thorsten所说,原始链接已被破坏,但是[this one](http://uploaded.to/file/swq33y)在本评论发布之日起生效。 (注意:它不能在我的Windows 7上运行,但在xp上运行) – Joe 2011-06-21 03:22:02

+0

来自Joe的链接也被中断。 这是一个工作的:[http://www.cenadep.org/2012/02/09/innosetup-form-designer/](http://www.cenadep.org/2012/02/09/innosetup-表单设计师/) – 2013-07-05 08:20:23

回答

34

您可以使用InnoSetup帕斯卡尔脚本来创建用于安装新的页面。这些页面可以集成到正常的安装流程中。这在InnoSetup documentation内有很好的记录(谷歌搜索也应该拿出样品)。 Program Files \ InnoSetup中的Samples文件夹也有一些代码示例。

前段时间,有一个名为InnoSetup Form设计器的软件,它允许您在视觉上设计页面。链接仍然存在,但在页面上我找不到下载。也许如果你环顾一下你可以找到它?

编辑
这是我制作一次的页面示例。这是国际空间站文件的代码段[代码]

var 
    EnableFolderPage: Boolean; 
    lblBlobFileFolder: TLabel; 
    lblBlobFileWarning1: TLabel; 
    lblBlobFileWarning2: TLabel; 
    tbBlobFileFolder: TEdit; 
    btnBlobFileFolder: TButton; 



function GetBlobFolder(param: String): String; 
begin 
    Result := Trim(tbBlobFileFolder.Text); 
end; 


{ BlobFileForm_Activate } 
procedure BlobFileForm_Activate(Page: TWizardPage); 
var 
    s: string; 
begin 
    s := Trim(tbBlobFileFolder.Text); 
    if (s = '') then 
    begin 
    tbBlobFileFolder.Text := ExpandConstant('{sys}'); 
    end; 
end; 


{ BlobFileForm_NextButtonClick } 
function BlobFileForm_NextButtonClick(Page: TWizardPage): Boolean; 
var 
    s: string; 
begin 
    s := Trim(tbBlobFileFolder.Text); 
    if (s = '') then 
    begin 
    MsgBox(ExpandConstant('{cm:BlobFileForm_NoFolder}'), mbError, MB_OK); 
    Result := false; 
    end else 
    begin 
    if not DirExists(s) then 
    begin 
     MsgBox(ExpandConstant('{cm:BlobFileForm_DirDoesntExist}'), mbError, MB_OK); 
     Result := false; 
    end else 
    begin 
     Result := True; 
    end; 
    end; 
end; 

procedure btnBlobFileFolder_Click(sender: TObject); 
var 
    directory: string; 
begin 
    if BrowseForFolder('', directory, true) then 
    begin 
    tbBlobFileFolder.Text := directory; 
    end; 
end; 


{ BlobFileForm_CreatePage } 
function BlobFileForm_CreatePage(PreviousPageId: Integer): Integer; 
var 
    Page: TWizardPage; 
begin 
    Page := CreateCustomPage(
    PreviousPageId, 
    ExpandConstant('{cm:BlobFileForm_Caption}'), 
    ExpandConstant('{cm:BlobFileForm_Description}') 
); 

{ lblBlobFileFolder } 
    lblBlobFileFolder := TLabel.Create(Page); 
    with lblBlobFileFolder do 
    begin 
    Parent := Page.Surface; 
    Caption := ExpandConstant('{cm:BlobFileForm_lblBlobFileFolder_Caption0}'); 
    Left := ScaleX(8); 
    Top := ScaleY(8); 
    Width := ScaleX(167); 
    Height := ScaleY(13); 
    end; 

    { lblBlobFileWarning1 } 
    lblBlobFileWarning1 := TLabel.Create(Page); 
    with lblBlobFileWarning1 do 
    begin 
    Parent := Page.Surface; 
    Caption := ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning1_Caption0}'); 
    Left := ScaleX(8); 
    Top := ScaleY(80); 
    Width := ScaleX(50); 
    Height := ScaleY(13); 
    Font.Color := -16777208; 
    Font.Height := ScaleY(-11); 
    Font.Name := 'Tahoma'; 
    Font.Style := [fsBold]; 
    end; 

    { lblBlobFileWarning2 } 
    lblBlobFileWarning2 := TLabel.Create(Page); 
    with lblBlobFileWarning2 do 
    begin 
    Parent := Page.Surface; 
    Caption := 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption0}') + #13 + 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption1}') + #13 + 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption2}') + #13 + 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption3}') + #13 + 
     ExpandConstant('{cm:BlobFileForm_lblBlobFileWarning2_Caption4}'); 
    Left := ScaleX(8); 
    Top := ScaleY(96); 
    Width := ScaleX(399); 
    Height := ScaleY(133); 
    AutoSize := False; 
    WordWrap := True; 
    end; 

    { tbBlobFileFolder } 
    tbBlobFileFolder := TEdit.Create(Page); 
    with tbBlobFileFolder do 
    begin 
    Parent := Page.Surface; 
    Left := ScaleX(8); 
    Top := ScaleY(24); 
    Width := ScaleX(401); 
    Height := ScaleY(21); 
    TabOrder := 0; 
    end; 

    { btnBlobFileFolder } 
    btnBlobFileFolder := TButton.Create(Page); 
    with btnBlobFileFolder do 
    begin 
    Parent := Page.Surface; 
    Caption := ExpandConstant('{cm:BlobFileForm_btnBlobFileFolder_Caption0}'); 
    Left := ScaleX(320); 
    Top := ScaleY(48); 
    Width := ScaleX(91); 
    Height := ScaleY(23); 
    TabOrder := 1; 
    end; 

    with Page do 
    begin 
    OnActivate := @BlobFileForm_Activate; 
    OnNextButtonClick := @BlobFileForm_NextButtonClick; 
    end; 

    with btnBlobFileFolder do 
    begin 
    OnClick := @btnBlobFileFolder_Click; 
    end; 

    Result := Page.ID; 
end; 


procedure InitializeWizard(); 
begin 
    BlobFileForm_CreatePage(wpSelectDir); 
end; 

EDIT 2
要输入用户输入的注册表项值,创建一个新的功能:

function GetUserEnteredText(param: String): String; 
begin 
    Result := Trim(tbTextBox.Text); 
end; 

该功能仅返回在文本框中输入的内容。请注意,该函数必须采用字符串参数 - 即使您忽略它!

在脚本的[Registry]部分,声明应该这样写,关键:

Root: HKLM; Subkey: SOFTWARE\MyCompany\MyTool; ValueType: string; ValueName: MyValue; ValueData: {code:GetUserEnteredText}; Flags: createvalueifdoesntexist uninsdeletekeyifempty uninsdeletevalue 

这将创建HKLM \ SOFTWARE名为“myvalue的”注册表值\ MyCompany的\ MyTool包含什么用户在文本框中输入。

+1

谢谢你的例子,这真的有帮助!只是最后一件事,我如何捕获用户输入的内容?然后我可以在写入注册表项时使用它作为变量。 – Abs 2010-07-09 11:48:31

+0

查看我的编辑2 ... :-) – 2010-07-09 11:58:27

+3

omg,非常感谢! +1是不够的。对于那些看到这个问题的人,请给他一些代表吧! :) – Abs 2010-07-09 12:18:08