zig*_*zig 4 delphi wmp delphi-7 windows-media-player
我有一个 Windows Media Player ActiveX 控件。我希望它与它的 parent 对齐TPanel。
问题是,无论我尝试什么,WMP 控件始终设置为其初始大小,而无法调整其大小。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, XpMan, ExtCtrls, WMPLib_TLB;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
public
Panel: TPanel;
MP: TWindowsMediaPlayer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Width := 450;
Height := 260;
Panel := TPanel.Create(Self);
Panel.Parent := Self;
Panel.Align := alClient;
MP := TWindowsMediaPlayer.Create(Self);
// MP.stretchToFit := True;
MP.Parent := Panel;
MP.Align := alClient;
MP.URL := 'https://www.w3schools.com/html/mov_bbb.mp4';
end;
Run Code Online (Sandbox Code Playgroud)
当您打开表单时,WMP 控件看起来不错:
但是当您调整表单大小时,WMP 控件不会与父面板对齐:
这实际上是我在尝试放大时看到的效果:
我该怎么做才能使 WMP 控件按预期运行?
我尝试了很多愚蠢的事情,例如:
procedure TForm1.FormResize(Sender: TObject);
begin
if not Assigned(MP) then Exit;
MP.Width := Panel.ClientWidth;
MP.Height := Panel.ClientHeight;
Panel.Realign;
end;
Run Code Online (Sandbox Code Playgroud)
但没有任何作用!
这是TOleControl.SetBoundsOleCtrls中 Delphi 7中的一个错误。它在较新的版本中得到了修复。
procedure TOleControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
var
LRect: TRect;
begin
if ((AWidth <> Width) and (Width > 0)) or ((AHeight <> Height) and (Height > 0)) then
begin
if (FMiscStatus and OLEMISC_INVISIBLEATRUNTIME <> 0) or
((FOleObject.SetExtent(DVASPECT_CONTENT, Point(
MulDiv(AWidth, 2540, Screen.PixelsPerInch),
MulDiv(AHeight, 2540, Screen.PixelsPerInch))) <> S_OK)) then
begin
AWidth := Width;
AHeight := Height;
end;
{ fix start }
if FOleInplaceObject <> nil then
begin
LRect := Rect(Left, Top, AWidth, AHeight);
FOleInplaceObject.SetObjectRects(LRect, LRect);
end;
{ fix end }
end;
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
end;
Run Code Online (Sandbox Code Playgroud)
将其应用于 OleCtrls 的本地副本后,一切正常。