如何在Inno Setup中更改鼠标光标?

4
我使用Inno安装程序创建了一个安装包,在安装过程中,我进行了一些冗长的操作来检查系统中的某些值(注册表键、某些文件...),在此期间,不向用户显示任何界面,我全部都在InitializeSetup函数内完成。
我想知道是否可以在执行所有这些检查时更改鼠标指针,以便用户知道正在发生某些事情。
我认为我可以创建一个dll,并从inno调用dll内的函数来更改光标,但我不想制作单独的dll,我想知道是否有一种只使用pascal脚本就能实现的方法。
感谢您的帮助。
3个回答

7
也许是因为最近版本的Inno Setup有所改变,但我无法从Mirtheil那里得到答案。相反,我找到了这个解决方法:
procedure SetControlCursor(oCtrl: TControl; oCurs: TCursor);
var 
  i     : Integer;
  oCmp  : TComponent;
begin
  oCtrl.Cursor := oCurs;
  for i := 0 to oCtrl.ComponentCount-1 do
  begin
    oCmp := oCtrl.Components[i];
    if oCmp is TControl then
    begin
      SetControlCursor(TControl(oCmp), oCurs);
    end;
  end;
end;

设置沙漏光标:

SetControlCursor(WizardForm, crHourGlass);    

重置沙漏光标:

SetControlCursor(WizardForm, crDefault);  

希望这能对某些人有所帮助!

1
虽然这样可以工作,但迭代“组件”效率低下。您可以使用原始代码中的“控件”。请参见我的答案 - Martin Prikryl

3

来源: http://www.vincenzo.net/isxkb/index.php?title=Cursor_-_Change_the_mouse_cursor_of_WizardForm

光标 - 改变 WizardForm 的鼠标光标

这个例子展示了一个在 Inno Setup 的安装向导界面中改变鼠标光标的方法。

只需使用 Windows API 函数 `LoadImage` 和 `SetClassLongPtr` 即可实现。

procedure SetControlCursor(control: TWinControl; cursor: TCursor);
var i:Integer;
    wc: TWinControl;
begin
  if (not (control = nil)) then begin
    control.Cursor := cursor;
    try
      for i:=0 to control.ControlCount-1 do begin
        wc := TWinControl(control.Controls[i]);
        if (NOT(wc = nil)) then
          SetControlCursor(wc, cursor)
        else
          control.Controls[i].Cursor := cursor;
      end; {for}
    finally

    end;{try}
  end;{if}
end;{procedure SetControlCursor}

要将其设置为沙漏形状:

SetControlCursor(WizardForm, crHourGlass);

将其恢复正常:

SetControlCursor(WizardForm, crDefault);

谢谢,代码运行得很好,只是需要注意的是,你不能在InitializeSetup中使用它,因为会出现错误提示:"尝试在创建WizardForm之前访问WizardForm"。在我的情况下,我只需要将代码移动到InitializeWizard中就解决了这个问题。 - Vic
2
这确实不再适用于Inno Setup 6.0.5。代码看起来像TWinControl(control.Controls[i])曾经可以像control.Controls[i] as TWinControl一样工作。但是现在不行了。所以(NOT(wc = nil))总是为真,即使控件不是TWinControl。我已经发布了一个更正的答案 - Martin Prikryl

2

结合@mirtheil和@Sirp的回答中的优点,这是我认为最佳的解决方案:

procedure SetControlCursor(Control: TControl; Cursor: TCursor);
var 
  I: Integer;
begin
  Control.Cursor := Cursor;
  if Control is TWinControl then
  begin
    for I := 0 to TWinControl(Control).ControlCount - 1 do
    begin
      SetControlCursor(TWinControl(Control).Controls[I], Cursor);
    end;
  end;
end;

设置沙漏光标:

SetControlCursor(WizardForm, crHourGlass);    

重置默认光标:

SetControlCursor(WizardForm, crDefault);  

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接