不久前我不得不解决这个问题,经过大量的谷歌搜索,我发现这个问题有效
Put a WindowsMedaiPlayer object on the Panel, and setting its align to alclient,
the player control area can be hidden with uiMode := none
, set in the ide or code
然后将“面板调整大小”事件指定为
uses Ole2;
procedure TForm1.Panel1Resize(Sender: TObject);
const
IID_IOleInPlaceObject: SYSTEM.TGUID = {00000113-0000-0000-C000-000000000046} ;
var
IOIPObj: IOleInPlaceObject;
begin
SYSTEM.IDispatch(WindowsMediaPlayer1.OleObject).QueryInterface(IID_IOleInPlaceObject, IOIPObj);
IOIPObj.SetObjectRects(Panel1.ClientRect, Panel1.ClientRect);
end;
procedure TForm1.Play;
begin
WindowsMediaPlayer1.uiMode := none ; //show no interface, this can be set from the ide
WindowsMediaPlayer1.URL := movie.mpg ;
WindowsMediaPlayer1.stretchToFit := True;
WindowsMediaPlayer1.Controls.play;
end;
改编自http://our.obor.us/node/1999
Ole2是IOleInPlaceObject的,我不得不添加<code>$(Delphi)源代码
(德尔菲7,wmp 11)
额外:更容易使用的东西
uses Ole2;
procedure SmoothResizeMediaPlayer(aMediaPlayer: TWindowsMediaPlayer; PosRect,ClipRect:Trect);
const
IID_IOleInPlaceObject: SYSTEM.TGUID = {00000113-0000-0000-C000-000000000046} ;
var
IOIPObj: IOleInPlaceObject;
begin
SYSTEM.IDispatch(aMediaPlayer.OleObject).QueryInterface(IID_IOleInPlaceObject, IOIPObj);
IOIPObj.SetObjectRects(PosRect, ClipRect);
end;
和呼叫
SmoothResizeMediaPlayer(WindowsMediaPlayer1, panel1.ClientRect, panel1.ClientRect);