Delphi - OleContainer - PowerPoint - 自动播放

发布于 2024-11-01 10:05:43 字数 586 浏览 0 评论 0原文

下午好:-),在我的应用程序中,我使用 OleContainer 从 Microsoft Powerpoint 查看演示文稿

我使用此代码加载和运行演示文稿文件

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 中工作),但在我的应用程序演示文稿中仍然< /strong> 在第一张幻灯片上。运行命令不对?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把梦留给海 2024-11-08 10:05:44

您不需要 OleContainer 来在应用程序的容器内运行演示文稿。将面板容器放在表单中运行演示文稿并尝试此例程:

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;

我手头没有文档,但我的想法是 Run.Width 和 Run.Height 必须以点为单位提供,而不是以点为单位提供像素。我将像素转换为点的可怜人解决方案就在这里,它在我的测试中对我有用......找到在您的环境中转换的正确方法取决于您。

假设您可以从 oPPTPres.SlideShowSettings.Run.HWND 属性获取演示文稿窗口的句柄,但这对我来说不起作用,因此调用了 FindWindow。

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.

囍孤女 2024-11-08 10:05:44

RunTOleContainer 的一种方法,它不是特定于任何类型的 OLE 对象(例如幻灯片演示文稿或位图图像)的方法。文档指出“调用 Run 以确保服务器应用程序正在运行..”。

您需要调用对象特定的方法来对其进行操作,请参阅 PowerPoint 对象模型参考。示例代码:

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;

虽然上面的演示文稿将以幻灯片形式运行,但它可能不是您想要的,因为它以全屏方式运行。我不知道如何在容器窗口中运行它。

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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文