Delphi-OleContainer-PowerPoint-AutoPlay
下午好:-),在我的应用程序中,我使用OleContainer从Microsoft Powerpoint查看演示文稿 我用来加载和运行演示文件的代码如下:Delphi-OleContainer-PowerPoint-AutoPlay,delphi,powerpoint,autoplay,Delphi,Powerpoint,Autoplay,下午好:-),在我的应用程序中,我使用OleContainer从Microsoft Powerpoint查看演示文稿 我用来加载和运行演示文件的代码如下: with oleContainer do begin Parent := mediaPanel; Left := 0; Top := 0; Width := mediaPanel.Width; Height := mediaPanel.Height; CreateObjectFromFile('C:\Users\Nan
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;
演示文稿创建为自动播放幻灯片放映(在Microsoft PowerPoint working中),但在我的应用程序中,演示文稿仍在第一张幻灯片上。Run命令不正确?
Run
是一种TOleContainer
的方法,它不是特定于任何类型的OLE对象的方法,例如power point演示或位图图像。。状态为“调用运行以确保服务器应用程序正在运行…”
您需要调用特定于对象的方法来对其进行操作,请参见。示例代码:
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;
尽管上面的演示文稿将以幻灯片形式运行,但它可能不是您想要的,因为它是全屏运行的。我不知道如何在容器窗口中运行它。在应用程序的容器中运行演示文稿时,不需要使用OLECTONTAINER。在表单中放置一个面板容器以运行演示文稿,然后尝试以下例程:
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;
我手头没有文档,但我的想法是运行。宽度和运行。高度必须以点为单位提供,而不是以像素为单位。我的穷人解决方案将像素转换为点在这里,它在我的测试中对我有效。。。在您的环境中找到正确的转换方式取决于您
假设您可以从
oPPTPres.SlideShowSettings.Run.HWND
属性获取演示文稿窗口的句柄,但这对我来说不起作用,因此需要FindWindow调用。感谢您的解决方案:-)。为什么我不能通过:OleContainer1.OleObject.Application.Presentations.Item(1).Run访问?是否有可能检查剧本的结尾?@Nanik-因为“Presentation”没有“Run”方法,所以演示文稿的“SlideShowSettings”对象有。应该是:OleContainer1.OleObject.Application.Presentations.Item(1.SlideShowSettings.Run代码>检查我提供的链接(或与此相关的代码)。@Nanik-应用程序对象有一个“SlideShowEnd”事件。@Nanik-您可能最终希望单击我发布的链接并开始使用对象模型文档。。无论如何,调用“SlideShowView”对象的“Exit”方法。对于我发布的代码示例,它将是S.Run.View.Exit
。对于“jachguate”的代码,我想你可以自己解决。如果所有其他方法都失败,模拟“Esc”键可能会成功。如果确实存在HWND属性,这不应被视为黑客行为:)但没有()。@JachGrate:我如何在演示结束前停止演示并将HWND属性返回默认值?@Nanik,我不明白你的问题。。。我从不更改HWND属性,因此没有返回的默认值。@JachGrate:我可以在演示结束之前停止演示并在面板中自由查看吗?@Nanik:我想到的一件简单的事情是,如果您事先知道演示将花费多少时间,就可以使用计时器停止它。