將系統中的com接口包裝為控件,Delphi代碼,以往估計見的不多,參考一下還是不枉的。
01
unit Unit1;
02
interface
03
uses
04
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
05
Dialogs, Buttons, StdCtrls, OleCtrls, ShockwaveFlashObjects_TLB,
06
MediaPlayer_TLB;
07
type
08
TForm1 = class(TForm)
09
BitBtn1: TBitBtn;
10
SpeedButton1: TSpeedButton;
11
OpenDialog1: TOpenDialog;
12
WMediaPlayer1: TWMediaPlayer;
13
procedure BitBtn1Click(Sender: TObject);
14
procedure SpeedButton1Click(Sender: TObject);
15
private
16
{ Private declarations }
17
public
18
{ Public declarations }
19
end;
20
var
21
Form1: TForm1;
22
PS_Status: boolean;
23
implementation
24
{$R *.dfm}
25
procedure TForm1.BitBtn1Click(Sender: TObject);
26
begin
27
if opendialog1.Execute then
28
begin
29
WMediaPlayer1.FileName := Opendialog1.FileName;
30
PS_Status := True;
31
end;
32
end;
33
procedure TForm1.SpeedButton1Click(Sender: TObject);
34
begin
35
if PS_Status = True then
36
begin
37
WMediaPlayer1.Stop;
38
speedbutton1.Glyph.LoadFromFile('./VCRPLAY.BMP');
39
PS_Status := False;
40
end
41
else
42
begin
43
WMediaPlayer1.Play;
44
speedbutton1.Glyph.LoadFromFile('./VCRSTOP.BMP');
45
PS_Status := True;
46
end;
47
end;
48
end.
可以在Delphi7下順利編譯,運行截圖如下所示:
