I am in the process of adding a BASS Audio Project in my Pascal Script. Adding a music playback for a very long installation is not bad for the user. But it is good to stop the music when user minimizes the WizardForm
to taskbar. And automatically start music if user restores it again from taskbar.
I like to know how can I detect if WizardForm
is minimized or restored and pause or start BASS music playing according to WizardForm
's window state. (Using functions like like BASS_Pause
,BASS_Stop
or BASS_Start.
)
How and what should I choose to do this? TWindowState
or WMSYSCOMMAND?
Thanks in advance.
I do not think there's any event that will notify you when the wizard form is minimized or restored. The TForm.WindowState
is not available in the Inno Setup Pascal Script either.
But you can schedule a frequent timer and check for changes in the form state.
Note the the form is actually hidden, not minimized, when you click the minimize button (there's no minimize animation). So use the GetWindowLong
WinAPI function to check for the WS_VISIBLE
window style.
[Code]
const
GWL_STYLE = -16;
WS_VISIBLE = $10000000;
function GetWindowLong(hWnd: THandle; nIndex: Integer): LongInt;
external 'GetWindowLongW@User32.dll stdcall';
function SetTimer(
hWnd: longword; nIDEvent, uElapse: LongWord; lpTimerFunc: LongWord): LongWord;
external 'SetTimer@user32.dll stdcall';
var
WasHidden: Boolean;
procedure HiddenTimerProc(H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
var
Hidden: Boolean;
Style: LongInt;
begin
Style := GetWindowLong(WizardForm.Handle, GWL_STYLE);
Hidden := (Style and WS_VISIBLE) = 0;
if Hidden and not WasHidden then
begin
Log('Minimized, stopping music...');
end
else
if not Hidden and WasHidden then
begin
Log('Restored, resuming music...');
end;
WasHidden := Hidden;
end;
procedure InitializeWizard();
begin
WasHidden := False;
SetTimer(0, 0, 500, CreateCallback(@HiddenTimerProc));
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.