【问题标题】:How can I made a button that is only visible at a specific page? (Inno Setup)如何制作仅在特定页面上可见的按钮? (Inno 设置)
【发布时间】:2012-06-30 19:17:45
【问题描述】:

我在向导页面中制作了一个按钮。但我只想在此串行表单页面上显示该按钮。现在,该按钮显示在所有向导页面上。我怎样才能让它只显示在连续页面上?

这是我用于串行表单页面的代码:

[Code]
enter code here function SetFocus(hWnd: HWND): HWND;
  external 'SetFocus@user32.dll stdcall';
function OpenClipboard(hWndNewOwner: HWND): BOOL;
  external 'OpenClipboard@user32.dll stdcall';
function GetClipboardData(uFormat: UINT): THandle;
  external 'GetClipboardData@user32.dll stdcall';
function CloseClipboard: BOOL;
  external 'CloseClipboard@user32.dll stdcall';
function GlobalLock(hMem: THandle): PAnsiChar;
  external 'GlobalLock@kernel32.dll stdcall';
function GlobalUnlock(hMem: THandle): BOOL;
  external 'GlobalUnlock@kernel32.dll stdcall';

var
  SerialPage: TWizardPage;
  SerialEdits: array of TEdit;

const
  CF_TEXT = 1;
  VK_BACK = 8;
  SC_EDITCOUNT = 6;
  SC_CHARCOUNT = 5;

function GetClipboardText: string;
var
  Data: THandle;
begin
  Result := '';
  if OpenClipboard(0) then
  try
    Data := GetClipboardData(CF_TEXT);
    if Data <> 0 then
      Result := String(GlobalLock(Data));
  finally
    if Data <> 0 then
      GlobalUnlock(Data);
    CloseClipboard;
  end;
end;

function TryPasteSerialNumber: Boolean;
var  
  S: string;
  I: Integer;
  J: Integer;
  Delimiter: string;
begin
  Result := True;
  Delimiter := '-';
  S := GetClipboardText;    
  if Length(S) <> ((SC_EDITCOUNT * SC_CHARCOUNT) + 
    ((SC_EDITCOUNT - 1) * Length(Delimiter))) then
    Exit;    
  for I := 0 to GetArrayLength(SerialEdits) - 1 do
  begin
    J := (I * SC_CHARCOUNT) + (I * Length(Delimiter)) + 1;
    SerialEdits[I].Text := Copy(S, J, SC_CHARCOUNT);
  end;
end;

function GetSerialNumber(const ADelimiter: Char): string;
var
  I: Integer;
begin
  Result := '';
  for I := 0 to GetArrayLength(SerialEdits) - 1 do
    Result := Result + SerialEdits[I].Text + ADelimiter;
  Delete(Result, Length(Result), 1);
end;

procedure OnSerialEditChange(Sender: TObject);
var
  CanContinue: Boolean;
begin
  CanContinue := GetSerialNumber('-') = 'my serial';
  WizardForm.NextButton.Enabled := CanContinue;
end;

procedure OnSerialEditKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  Edit: TEdit;
  EditIndex: Integer;
begin
  Edit := TEdit(Sender);
  EditIndex := Edit.TabOrder - SerialEdits[0].TabOrder;
  if (EditIndex = 0) and (Key = Ord('V')) and (Shift = [ssCtrl]) then
  begin
    if TryPasteSerialNumber then
      Key := 0;
  end
  else
  if (Key >= 32) and (Key <= 255) then
  begin
    if Length(Edit.Text) = SC_CHARCOUNT - 1 then
    begin
      if EditIndex < GetArrayLength(SerialEdits) - 1 then
        SetFocus(SerialEdits[EditIndex + 1].Handle)
      else
        SetFocus(WizardForm.NextButton.Handle);
    end;
  end
  else
  if Key = VK_BACK then
    if (EditIndex > 0) and (Edit.Text = '') and (Edit.SelStart = 0) then
      SetFocus(SerialEdits[EditIndex - 1].Handle);
end;

procedure CreateSerialNumberPage;
var
  I: Integer;
  Edit: TEdit;
  DescLabel: TLabel;
  EditWidth: Integer;
begin
  SerialPage := CreateCustomPage(wpWelcome, 'Serial number validation',
    'Enter the valid serial number');

  DescLabel := TLabel.Create(SerialPage);
  DescLabel.Top := 16;
  DescLabel.Left := 0;
  DescLabel.Parent := SerialPage.Surface;
  DescLabel.Caption := 'Enter the valid serial number and continue with the installation...';
  DescLabel.Font.Style := [fsBold];

  SetArrayLength(SerialEdits, SC_EDITCOUNT);
  EditWidth := (SerialPage.SurfaceWidth - ((SC_EDITCOUNT - 1) * 8)) div SC_EDITCOUNT;

  for I := 0 to SC_EDITCOUNT - 1 do
  begin
    Edit := TEdit.Create(SerialPage);
    Edit.Top := 40;
    Edit.Left := I * (EditWidth + 8);
    Edit.Width := EditWidth;
    Edit.CharCase := ecUpperCase;
    Edit.MaxLength := SC_CHARCOUNT;
    Edit.Parent := SerialPage.Surface;
    Edit.OnChange := @OnSerialEditChange;
    Edit.OnKeyDown := @OnSerialEditKeyDown;
    SerialEdits[I] := Edit;
  end;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = SerialPage.ID then
    WizardForm.NextButton.Enabled := False;  
end;

procedure AboutButtonOnClick(Sender: TObject);
var
  ErrorCode: Integer;
begin
  ShellExecAsOriginalUser('open', 'http://www.mywebsite.com', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;

procedure CreateAboutButton(ParentForm: TSetupForm; CancelButton: TNewButton);
var
  AboutButton: TNewButton;
begin
  AboutButton := TNewButton.Create(ParentForm);
  AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  AboutButton.Top := CancelButton.Top;
  AboutButton.Width := CancelButton.Width;
  AboutButton.Height := CancelButton.Height;
  AboutButton.Caption := '&Get Serial';
  AboutButton.OnClick := @AboutButtonOnClick;
  AboutButton.Parent := ParentForm;
end;

procedure InitializeWizard;
begin
  CreateSerialNumberPage;
  CreateAboutButton(WizardForm, WizardForm.CancelButton);
end;

希望你们能帮帮我!

【问题讨论】:

    标签: url button inno-setup serial-number custom-pages


    【解决方案1】:

    您已经有一个CurPageChanged 过程,您可以根据当前页面在此处设置按钮的可见性。当然,您需要将“AboutButton”设为全局变量:

    ...
    
    var
      AboutButton: TNewButton;
    
    procedure CreateAboutButton(ParentForm: TSetupForm; CancelButton: TNewButton);
    begin
      AboutButton := TNewButton.Create(ParentForm);
      ...
    end;
    
    
    procedure CurPageChanged(CurPageID: Integer);
    begin
      ...
      AboutButton.Visible := CurPageID = SerialPage.ID;
    end;
    

    【讨论】:

    • 我不知道如何集成您的代码。它看起来不错,但我不知道我必须将它粘贴到哪里。你能把整个代码发给我吗?
    • @korteder - 集成它需要对问题中发布的代码进行很少的修改。如答案所示,将varAboutButton 声明移到CreateAboutButton 过程之外。然后将AboutButton.Visible .. 行添加到CurPageChanged 过程中,如答案所示。
    • 我收到以下错误:未知标识符“AboutButton”。我怎样才能解决这个问题?但感谢您抽出宝贵时间!
    • @korteder - 在出现此错误的地方插入var AboutButton: TNewButton;。在答案中查看它是如何完成的。
    • 谢谢!有用!当用户在欢迎屏幕上单击下一步时,设置是否也有可能自动打开一个 URL?
    【解决方案2】:

    如果您将按钮实际放在您希望它可见的页面上,那么它只会在该页面可见时出现。您必须将其位置设置为适合该页面,然后将其 Parent 设置为该页面上已存在的某个其他控件的 Parent。

    否则(如果您希望它出现在正常页面区域之外),请按照 Sertac 所说的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 2014-09-05
      • 2013-04-24
      • 1970-01-01
      相关资源
      最近更新 更多