答案 0 :(得分:1)
由于Inno Setup API中缺少OnEnter
事件,这很难实现。
首先,您要将按钮的TabStop
属性设置为False
,以防止按钮使用 Tab 键获得焦点。
Button.TabStop := False;
(In your case,它是SoundCtrlButton
)。
如果您对焦点感到满意,请始终返回"下一步" 按钮,当鼠标点击时,它很容易。只需将焦点明确设置为按钮OnClick
处理程序末尾的"下一步" 按钮:
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
)。
但是,如果你想要很好地实现这一点,通过将焦点返回到之前实际具有焦点的控件,它会更加困难。
我想不出更好的解决办法,而不是安排一个频繁的计时器(使用InnoCallback library)来监控聚焦控制。
[Files]
Source: InnoCallback.dll; Flags: dontcopy
[Code]
type
TTimerProc = procedure(H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
function SetTimer(hWnd: LongWord; nIDEvent, uElapse: LongWord;
lpTimerFunc: LongWord): LongWord; external 'SetTimer@user32.dll stdcall';
function WrapTimerProc(Callback: TTimerProc; ParamCount: Integer): LongWord;
external 'wrapcallback@files:innocallback.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();
var
FocusMonitorCallback: LongWord;
begin
{ Set up 50ms timer to monitor the focus }
FocusMonitorCallback := WrapTimerProc(@FocusMonitorProc, 4);
SetTimer(0, 0, 50, FocusMonitorCallback);
{ Create the "unfocusable" button }
SomeButton := TNewButton.Create(WizardForm);
{ Initialize button }
SomeButton.TabStop := False;
end;
替代解决方案是使用类似按钮的图像(TBitmapImage
control),而不是实际的TButton
。 TBitmapImage
控件(不是TWinControl
)根本无法获得焦点。
它实际上可以让你一个很好的&#34;静音&#34;图像而不是简单的&#34;静音&#34; 标题。