Delphi - OleContainer - PowerPoint - AutoPlay

Nanik picture Nanik · Apr 15, 2011 · Viewed 7.5k times · Source

Good afternoon :-), in my application I use OleContainer to view presentation from Microsoft Powerpoint.

This code I use to load and run presentation file:

with oleContainer do begin
    Parent := mediaPanel; Left := 0; Top := 0;
    Width := mediaPanel.Width; Height := mediaPanel.Height;
    CreateObjectFromFile('C:\Users\Nanik\Desktop\Present.ppt', false);
    Iconic := false; Visible := true; Run;
 end;

The presentation was created as autoplay slideshow (in Microsoft PowerPoint working), but in my application presentation was still on first slide. Run command isn't right?

Answer

jachguate picture jachguate · Apr 16, 2011

You do not need a OleContainer to run the presentation inside a container in your application. Put a panel container to run the presentation in your form and try this routine:

procedure TForm2.Button3Click(Sender: TObject);
const
  ppShowTypeSpeaker = 1;
  ppShowTypeInWindow = 1000;
  SHOW_FILE = 'C:\Users\jcastillo\Documents\test.pps';
var
  oPPTApp: OleVariant;
  oPPTPres: OleVariant;

  screenClasshWnd: HWND;
  pWidth, pHeight: Integer;

  function PixelsToPoints(Val: Integer; Vert: Boolean): Integer;
  begin
    if Vert then
      Result := Trunc(Val * 0.75)
    else
      Result := Trunc(Val * 0.75);
  end;

begin
  oPPTApp := CreateOleObject('PowerPoint.Application');
  oPPTPres := oPPTApp.Presentations.Open(SHOW_FILE, True, True, False);
  pWidth := PixelsToPoints(Panel1.Width, False);
  pHeight := PixelsToPoints(Panel1.Height, True);
  oPPTPres.SlideShowSettings.ShowType := ppShowTypeSpeaker;
  oPPTPres.SlideShowSettings.Run.Width := pWidth;
  oPPTPres.SlideShowSettings.Run.Height := pHeight;
  screenClasshWnd := FindWindow('screenClass', nil);
  Windows.SetParent(screenClasshWnd, Panel1.Handle);
end;

I do not have documentation at hand, but my thought is Run.Width and Run.Height must be provided in points, not in pixels. My poor man solution to convert pixels to points is here, and it works for me in my tests here... to find the correct way to convert in your environment is up to you.

Is supposed you can get the Handle of the presentation window from the oPPTPres.SlideShowSettings.Run.HWND property, but that does not work here for me, hence the FindWindow call.