6

我正在使用 Inno Setup 构建安装,并且正在使用组件部分来允许最终用户选择要安装的可选项目。

其中一些项目需要更长的描述,以便用户有足够的信息来智能地选择它们。

有没有办法在某处添加更深入的描述?

4

2 回答 2

6

此解决方案仅使用正确的 Inno Setup(不是可疑来源的 Inno Setup 的过时的第 3 方构建)。

该解决方案部分基于我对Inno Setup: OnHover event的回答。

HoverComponentChanged根据您的需要调整程序。

[Code]

var
  LastMouse: TPoint;
  CompLabel: TLabel;

function GetCursorPos(var lpPoint: TPoint): BOOL;
  external 'GetCursorPos@user32.dll stdcall';
function SetTimer(
  hWnd: longword; nIDEvent, uElapse: LongWord; lpTimerFunc: LongWord): LongWord;
  external 'SetTimer@user32.dll stdcall';
function ScreenToClient(hWnd: HWND; var lpPoint: TPoint): BOOL;
  external 'ScreenToClient@user32.dll stdcall';
function ClientToScreen(hWnd: HWND; var lpPoint: TPoint): BOOL;
  external 'ClientToScreen@user32.dll stdcall';
function ListBox_GetItemRect(
  const hWnd: HWND; const Msg: Integer; Index: LongInt; var Rect: TRect): LongInt;
  external 'SendMessageW@user32.dll stdcall';  

const
  LB_GETITEMRECT = $0198;
  LB_GETTOPINDEX = $018E;

function FindControl(Parent: TWinControl; P: TPoint): TControl;
var
  Control: TControl;
  WinControl: TWinControl;
  I: Integer;
  P2: TPoint;
begin
  for I := 0 to Parent.ControlCount - 1 do
  begin
    Control := Parent.Controls[I];
    if Control.Visible and
       (Control.Left <= P.X) and (P.X < Control.Left + Control.Width) and
       (Control.Top <= P.Y) and (P.Y < Control.Top + Control.Height) then
    begin
      if Control is TWinControl then
      begin
        P2 := P;
        ClientToScreen(Parent.Handle, P2);
        WinControl := TWinControl(Control);
        ScreenToClient(WinControl.Handle, P2);
        Result := FindControl(WinControl, P2);
        if Result <> nil then Exit;
      end;

      Result := Control;
      Exit;
    end;
  end;

  Result := nil;
end;

function PointInRect(const Rect: TRect; const Point: TPoint): Boolean;
begin
  Result :=
    (Point.X >= Rect.Left) and (Point.X <= Rect.Right) and
    (Point.Y >= Rect.Top) and (Point.Y <= Rect.Bottom);
end;

function ListBoxItemAtPos(ListBox: TCustomListBox; Pos: TPoint): Integer;
var
  Count: Integer;
  ItemRect: TRect;
begin
  Result := SendMessage(ListBox.Handle, LB_GETTOPINDEX, 0, 0);
  Count := ListBox.Items.Count;
  while Result < Count do
  begin
    ListBox_GetItemRect(ListBox.Handle, LB_GETITEMRECT, Result, ItemRect);
    if PointInRect(ItemRect, Pos) then Exit;
    Inc(Result);
  end;
  Result := -1;
end;

procedure HoverComponentChanged(Index: Integer);
var 
  Description: string;
begin
  case Index of
    0: Description := 'This is the description of Main Files';
    1: Description := 'This is the description of Additional Files';
    2: Description := 'This is the description of Help Files';
  else
    Description := 'Move your mouse over a component to see its description.';
  end;
  CompLabel.Caption := Description;
end;

procedure HoverTimerProc(
  H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
var
  P: TPoint;
  Control: TControl; 
  Index: Integer;
begin
  GetCursorPos(P);
  if P <> LastMouse then { just optimization }
  begin
    LastMouse := P;
    ScreenToClient(WizardForm.Handle, P);

    if (P.X < 0) or (P.Y < 0) or
       (P.X > WizardForm.ClientWidth) or (P.Y > WizardForm.ClientHeight) then
    begin
      Control := nil;
    end
      else
    begin
      Control := FindControl(WizardForm, P);
    end;

    Index := -1;
    if (Control = WizardForm.ComponentsList) and
       (not WizardForm.TypesCombo.DroppedDown) then
    begin
      P := LastMouse;
      ScreenToClient(WizardForm.ComponentsList.Handle, P);
      Index := ListBoxItemAtPos(WizardForm.ComponentsList, P);
    end;

    HoverComponentChanged(Index);
  end;
end;

procedure InitializeWizard();
begin
  SetTimer(0, 0, 50, CreateCallback(@HoverTimerProc));

  CompLabel := TLabel.Create(WizardForm);
  CompLabel.Parent := WizardForm.SelectComponentsPage;
  CompLabel.Left := WizardForm.ComponentsList.Left;
  CompLabel.Width := WizardForm.ComponentsList.Width;
  CompLabel.Height := ScaleY(32);
  CompLabel.Top :=
    WizardForm.ComponentsList.Top + WizardForm.ComponentsList.Height -
    CompLabel.Height;
  CompLabel.AutoSize := False;
  CompLabel.WordWrap := True;

  WizardForm.ComponentsList.Height :=
    WizardForm.ComponentsList.Height - CompLabel.Height - ScaleY(8);
end;

在此处输入图像描述

对于CreateCallback函数,您需要 Inno Setup 6。如果您被 Inno Setup 5 卡住,您可以使用InnoTools InnoCallback库中WrapCallback的函数。使用 Inno Setup 5 的 Unicode 版本。

为了在调整大小/调整大小/现代向导中正确工作,您需要进行一些调整。请参阅Inno 设置 - 如何在调整大小的向导中居中动画 gif放大的 Inno 设置向导中的长组件描述

于 2016-06-13T18:13:42.290 回答
-2

使用这个高级编译器(下载链接在下面)。

它支持比标准编译器更多的类和事件。您可以访问属性“OnItemMouseMove”。使用它,您可以存储标签显示的每个项目的描述。这是一个例子:

var
CompLabel: TLabel;

procedure OnItemMouseMove(Sender: TObject; X, Y: Integer; Index: Integer; Area: TItemArea);
begin
  case Index of
    0: CompLabel.Caption := 'This is the description of Component 1';
    1: CompLabel.Caption := 'This is the description of Component 2';
    2: CompLabel.Caption := 'This is the description of Component 3';
    3: CompLabel.Caption := 'This is the description of Component 4'
  else
    CompLabel.Caption := 'Move your mouse over a component to see its description.';
  end;
end;

procedure OnMouseLeave(Sender: TObject);
begin
  CompLabel.Caption := 'Move your mouse over a component to see its description.';
end;

procedure InitializeWizard();
begin
  CompLabel := TLabel.Create(WizardForm);
  CompLabel.Parent := WizardForm.SelectComponentsPage;
  CompLabel.SetBounds(WizardForm.ComponentsList.Left,180,WizardForm.ComponentsList.Width,200);
  CompLabel.Caption := 'Move your mouse over a component to see its description.';
  WizardForm.ComponentsList.OnItemMouseMove := @OnItemMouseMove;
  WizardForm.ComponentsList.OnMouseLeave := @OnMouseLeave;
  WizardForm.ComponentsList.Height := WizardForm.ComponentsList.Height - 40;
end;
于 2012-12-10T18:19:22.343 回答