d7用TWindowsMediaPlayer 9 如何改变动态创建的播放控件的大小?急 ( 积分: 100 )

  • 主题发起人 主题发起人 error2002
  • 开始时间 开始时间
E

error2002

Unregistered / Unconfirmed
GUEST, unregistred user!
程序中需要动态设置播放窗口大小,可是这个mediaplayer 9 的
大小变不了,aligen=alclient 或者 更改 width height都不能
像其他控件那样改变大小
 
程序中需要动态设置播放窗口大小,可是这个mediaplayer 9 的
大小变不了,aligen=alclient 或者 更改 width height都不能
像其他控件那样改变大小
 
自己得到其Handle,然后调用SetWindowPos

BOOL SetWindowPos(HWND hWnd,
HWND hWndInsertAfter,
int X,
int Y,
int cx,//[in] Specifies the new width of the window, in pixels.
int cy,//[in] Specifies the new height of the window, in pixels.
UINT uFlags
);
 
我可能没说清,我开发一个程序,嵌入一个TWindowsMediaPlayer 控件,动态创建后,放在一个Panel上,然后想改变其大小

请 dawnsong 说详细些好吗?
 
procedure TForm1.FormCreate(Sender: TObject);
begin

wmp :=TWindowsMediaPlayer.Create(Self);
wmp.Parent :=Panel1;
wmp.Align :=alClient;//关键在此处
{我也试着改了下Width和Height,确实不管用,但上面Align就可以了,应该解决问题了:)}
wmp.Show;
end;


procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin

wmp.Destroy;
end;


procedure TForm1.FormDblClick(Sender: TObject);
begin

Panel1.Left :=10;
Panel1.Top :=10;
Panel1.Width :=Self.Width-20;
Panel1.Height:=Self.Height-20;
end;
 
谢谢dawnsong ,答案已经很接近了,但是我想要的是,播放窗口
初始化完后,再动态创建TWindowsMediaPlayer,这样动态创建的
大小我无法改变,关键在此,再帮着想想办法,呵呵
 
不懂何意,不妨把代码发过来,我试着改改dawnsong@sohu.com
 
全部程序如下,运行没问题,我已测试过了。
2年前我倒也做过你这样的项目,呵呵,不过代码都丢了
type
TfrmMain = class(TForm)
MainMenu1: TMainMenu;
N41: TMenuItem;
N42: TMenuItem;
N43: TMenuItem;
N3: TMenuItem;
H1: TMenuItem;
A1: TMenuItem;
procedure N43Click(Sender: TObject);
procedure N42Click(Sender: TObject);
procedure N41Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
panels :array of TPanel;
wmps :array of TWindowsMediaPlayer;

procedure CreateMediaPlayers;overload;
procedure CreateMediaPlayers(const ACount:Integer);overload;
procedure FreeMediaPlayers;
procedure ArrangePanels;
public
{ Public declarations }
end;


var
frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.CreateMediaPlayers;
var
i :Integer;
begin

for i:=Low(panels) to High(panels)do

begin

panels :=TPanel.Create(Self);
panels.Parent :=Self;
panels.Name :=Format('idPanel%d',[i+1]);
panels.Caption:=Format('第%d号播放器',[i+1]);
end;


ArrangePanels;

for i:=Low(wmps) to High(wmps)do

begin

wmps :=TWindowsMediaPlayer.Create(panels);
wmps.Name :=Format('idWmp%d',[i+1]);
wmps.Parent :=panels;
wmps.Align :=alClient;
wmps.Show;
end;

end;

procedure TfrmMain.CreateMediaPlayers(const ACount:Integer);
begin

FreeMediaPlayers;

SetLength(panels,ACount);
SetLength(wmps,High(panels) -Low(panels) +1);
CreateMediaPlayers;
end;

procedure TfrmMain.FreeMediaPlayers;
var
i :Integer;
begin

for i:=Low(panels) to High(wmps)do

if Assigned(wmps) then
wmps.Destroy;
for i:=Low(wmps) to High(panels)do

if Assigned(panels) then
panels.Destroy;

end;

procedure TfrmMain.ArrangePanels;
var
i,j :Integer;
x :Integer;
begin

x := Round(Sqrt(High(panels)));
for i:=Low(panels) to High(panels)do

begin

panels.Align :=alNone;
panels.Width :=panels.Parent.ClientWidth div x -4;
panels.Height:=panels.Parent.ClientHeight div x -4;
end;

for j:=0 to x-1do

for i:=0 to x-1do

begin

panels[j + x *i].Left :=(i mod x) *(panels[j + x *i].Width +2);
panels[j + x *i].top :=j *(panels[j + x *i].Height +2);
end;

end;



procedure TfrmMain.FormClose(Sender: TObject;
var Action: TCloseAction);
begin

FreeMediaPlayers;
end;


procedure TfrmMain.N41Click(Sender: TObject);
begin

CreateMediaPlayers(4);
end;


procedure TfrmMain.N42Click(Sender: TObject);
begin

CreateMediaPlayers(9);
end;


procedure TfrmMain.N43Click(Sender: TObject);
begin

CreateMediaPlayers(16);
end;


end.
 
已发送到你信箱,注意查收
 
问题已解决,谢谢dawnsong参与,你的例子可能是mediaplayer 6.4的吧?
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1850558
 
呵呵,问题解决了

我是在Win Xp +Windows MEdiaPlayer 10下测试的,仅仅导入了一下MediaPlayer10的Dll,然后动态创建的
 
我用的是 media player 9
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部