阻止按钮在Inno Setup中获得焦点 [英] Prevent button from receiving focus in Inno Setup

查看:152
本文介绍了阻止按钮在Inno Setup中获得焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的脚本中,单击音频按钮时,它会收到焦点(那个蓝色的粗边框)

In my script, when the audio button is clicked, it receives a focus (That blue thick border)

我希望它是,即使您单击音频按钮,焦点按钮仍然是下一步/安装" .

I want it to be, even when you click the audio button, the focused button is still the "Next/Install".

推荐答案

由于Inno Setup API中缺少OnEnter事件,因此难以实现.

This is difficult to implement due to a lack of OnEnter event in Inno Setup API.

首先,要将按钮的TabStop属性设置为False,以防止使用 Tab 键使按钮获得焦点.

First, you want to set TabStop property of the button to False to prevent the button from receiving focus using the Tab key.

Button.TabStop := False;

(在您的情况下,它是SoundCtrlButton).

(In your case, it's the SoundCtrlButton).

如果您对焦点感到满意,请始终返回到下一步" 按钮,单击该按钮很简单.只需将焦点明确设置为按钮OnClick处理程序末尾的下一步" 按钮:

If you are happy with focus always going back to the "Next" button, when it's mouse-clicked, it's easy. Just set the focus explicitly to the "Next" button at the end of the button's OnClick handler:

procedure ButtonClick(Sender: TObject);
begin
  { Some actual code }

  { If the button is focused (it won't be, when access key was used to "click" it) ... }
  if TButton(Sender).Focused then
    { ... focus the "Next" button }
    WizardForm.ActiveControl := WizardForm.NextButton;
end;

(在您的情况下,OnClick处理程序为SoundCtrlButtonClick).

(In your case, the OnClick handler is SoundCtrlButtonClick).

但是,如果您想很好地实现此目的,则可以通过将焦点返回到以前实际具有焦点的控件来,这会更加困难.

Though, if you want to implement this nicely, by returning the focus back to the control that actually had the focus previously, it's more difficult.

除了安排一个频繁的计时器来监视集中控制之外,我想不出更好的解决方案.

I cannot think of better solution than scheduling a frequent timer to monitor to the focused control.

[Code]

function SetTimer(hWnd: LongWord; nIDEvent, uElapse: LongWord; 
  lpTimerFunc: LongWord): LongWord; external 'SetTimer@user32.dll stdcall';

var
  LastFocusedControl: TWinControl;

procedure FocusMonitorProc(
  H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
begin
  { Remember focused control, unless the currently focused control is already the one, }
  { we do not want to get focused }
  if (WizardForm.ActiveControl = nil) or
     WizardForm.ActiveControl.TabStop then
  begin
    LastFocusedControl := WizardForm.ActiveControl;
  end;
end;

procedure ButtonClick(Sender: TObject);
begin
  { Some actual code }

  { If the button is focused (it won't be, when access key was used to "click" it) ... }
  if TButton(Sender).Focused and (LastFocusedControl <> nil) then
    { ... focus the previously focused control }
    WizardForm.ActiveControl := LastFocusedControl;
end;

procedure InitializeWizard();
begin
  { Set up 50ms timer to monitor the focus }
  SetTimer(0, 0, 50, CreateCallback(@FocusMonitorProc));  

  { Create the "unfocusable" button }
  SomeButton := TNewButton.Create(WizardForm);
  { Initialize button }
  SomeButton.TabStop := False;  
end;

对于 CreateCallback函数,您需要Inno设置6.如果您对Inno Setup 5不满意,则可以使用 InnoTools中的WrapCallback函数InnoCallback 库.

For CreateCallback function, you need Inno Setup 6. If you are stuck with Inno Setup 5, you can use WrapCallback function from InnoTools InnoCallback library.

替代解决方案是使用类似按钮的图像( TBitmapImage控件),而不是实际的TButton. TBitmapImage控件(不是 TWinControl )根本无法获得焦点.

Alternative solution is to use a button-like image (the TBitmapImage control), instead of the actual TButton. The TBitmapImage control (not being the TWinControl) cannot receive focus at all.

实际上,它可以使您获得漂亮的静音"图像,而不是普通的静音" 标题.

And it can actually get you a nice "mute" image instead of the plain "Mute" caption.

这篇关于阻止按钮在Inno Setup中获得焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆