Search code examples
videoinno-setuppascalscript

Inno Setup Maximize splash video


I am using Inno Media Player by TLama to show a splash video at the beginning of the setup.

Therefore I am using the following code:

[Code]
const
  EC_COMPLETE = $01;

type
  TDirectShowEventProc = procedure(EventCode, Param1, Param2: Integer);

function DSGetLastError(var ErrorText: WideString): HRESULT;
  external 'DSGetLastError@files:mediaplayer.dll stdcall';
function DSPlayMediaFile: Boolean;
  external 'DSPlayMediaFile@files:mediaplayer.dll stdcall';
function DSStopMediaPlay: Boolean;
  external 'DSStopMediaPlay@files:mediaplayer.dll stdcall';
function DSInitializeVideoFile(FileName: WideString; WindowHandle: HWND; var Width,
  Height: Integer; CallbackProc: TDirectShowEventProc): Boolean;
  external 'DSInitializeVideoFile@files:mediaplayer.dll stdcall';

var
  VideoForm: TSetupForm;

procedure OnMediaPlayerEvent(EventCode, Param1, Param2: Integer); 
begin
  if EventCode = EC_COMPLETE then
    VideoForm.Close;
end;

procedure OnVideoFormShow(Sender: TObject);
var
  ErrorCode: HRESULT;
  ErrorText: WideString; 
  Width, Height: Integer;
  begin
  if DSInitializeVideoFile(ExpandConstant('{tmp}\{#MyVideo}'), VideoForm.Handle, Width, 
    Height, @OnMediaPlayerEvent) then
  begin
    VideoForm.ClientWidth := Width;
    VideoForm.ClientHeight := Height;
    DSPlayMediaFile;
  end
  else
  begin
    ErrorCode := DSGetLastError(ErrorText);
    MsgBox('TDirectShowPlayer error: ' + IntToStr(ErrorCode) + '; ' + 
      ErrorText, mbError, MB_OK);
  end;
end;

procedure OnVideoFormClose(Sender: TObject; var Action: TCloseAction);
begin
  DSStopMediaPlay;
end;

procedure InitializeWizard;
begin
ExtractTemporaryFile('{#MyVideo}');

  VideoForm := CreateCustomForm;
  VideoForm.Position := poScreenCenter;
  VideoForm.OnShow := @OnVideoFormShow;
  VideoForm.OnClose := @OnVideoFormClose;
  VideoForm.FormStyle := fsStayOnTop;
  VideoForm.Caption := 'Popup Video Window';
  VideoForm.ShowModal;

end;

procedure DeinitializeSetup;
begin
  DSStopMediaPlay;
end;

Now I wanted to ask if there is a possibility to maximize the video window.

Thanks in advance


Solution

  • Use the ShowWindow with the SW_SHOWMAXIMIZED flag to maximize the window.

    The DSInitializeVideoFile accepts the desired size of the video in an input value of the Width and Height parameters.

    So if you display and maximize the window prior to starting the video, you can pass a size of the maximized window.

    Something like:

    function ShowWindow(hWnd: DWord; nCmdShow: Integer): Boolean;
      external 'ShowWindow@user32.dll stdcall';
    
    procedure OnVideoFormShow(Sender: TObject);
    var
      Width: Integer;
      Height: Integer;
      VideoForm: TForm;
    begin
      VideoForm := TForm(Sender);
    
      ShowWindow(VideoForm.Handle, SW_SHOWMAXIMIZED);
    
      Width := VideoForm.ClientWidth;
      Height := VideoForm.ClientHeight;
    
      if not DSInitializeVideoFile(ExpandConstant('{tmp}\{#MyVideo}'), VideoForm.Handle,
        Width, Height, @OnMediaPlayerEvent) then
      begin
        VideoForm.Close;
      end;
    end;
    
    procedure InitializeWizard;
    begin
      VideoForm := CreateCustomForm;
      ...
      VideoForm.ShowModal;
    end;