您不需要 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 调用。