3
votes

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?

2

2 Answers

5
votes

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.

4
votes

Run is a method of TOleContainer, it is not a method specific to any kind of OLE object, say, a power point presentation or a bitmap image.. Documentation states "Call Run to ensure that the server application is running..".

You need to call object specific methods to operate on them, see PowerPoint Object Model Reference. Sample code:

procedure TForm1.Button1Click(Sender: TObject);
const
  ppAdvanceOnTime = $00000002;
var
  P: OleVariant;
  S: OleVariant;
  i: Integer;
begin
  P :=  OleContainer1.OleObject.Application.Presentations.Item(1);

  // below block would not be necessary for a slide show (i.e. a *.pps)
  for i := 1 to P.Slides.Count do begin
    P.Slides.Item(i).SlideShowTransition.AdvanceOnTime := True;
    P.Slides.Item(i).SlideShowTransition.AdvanceTime := 1;
  end;
  S := P.SlideShowSettings;
  S.AdvanceMode := ppAdvanceOnTime;

  S.Run;
end;


Though the above will run the presentation as a slide show, it is probably not what you'd want because it runs in full screen. I have no idea how to run it in the container window..