Reputation: 381
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".
Upvotes: 2
Views: 665
Reputation: 202292
This is difficult to implement due to a lack of OnEnter
event in Inno Setup API.
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;
(In your case, it's the SoundCtrlButton
).
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;
(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 the focused control.
[Code]
function SetTimer(hWnd: LongWord; nIDEvent, uElapse: LongWord;
lpTimerFunc: LongWord): LongWord; external '[email protected] 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;
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.
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.
Upvotes: 3