Delphi - OleContainer - PowerPoint - AutoPlay

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

This code that I use to download and run the 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 an auto play slideshow (in Microsoft PowerPoint), but in my presentation the application was still on the first slide . Wrong start command?

+3
source share
2 answers

You do not need an OleContainer to run a presentation inside a container in your application. Place the panel container to launch the presentation in your form and try this procedure:

 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 don't have the documentation at hand, but I thought that Run.Width and Run.Height should be provided in points, not pixels. My poor solution for converting pixels to points here, and it works for me in my tests here ... to find the right way to convert to your environment, is up to you.

It is assumed that you can get the Presentation Window Handle from the oPPTPres.SlideShowSettings.Run.HWND property, but this does not work for me, therefore, the call to FindWindow.

+3
source

Run is a TOleContainer method, it is not a method specific to any type of OLE object, say, for representing a power point or bitmap. "Documentation" indicates "Make a call to ensure that the server application is running."

You need to call methods specific to specific objects to work with them, see the PowerPoint Object Model Reference . Code example:

 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 (ie 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; 


Although the above will show the presentation as a slide show, this is probably not what you want, because it works in full screen mode. I do not know how to run it in the container window.

+4
source

Source: https://habr.com/ru/post/919628/


All Articles