源程序(一个VCD播放器)如下:
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, jpeg, OleCtrls, MediaPlayer_TLB;
type
TMainForm = class(TForm)
Image1: TImage;
Image2: TImage;
Image3: TImage;
OpenDialog1: TOpenDialog;
MPlayer1: TMPlayer;
procedure FormCreate(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure Image3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
AppPath: String;
Rgn: HRgn;
implementation
{$R *.DFM}
procedure TMainForm.FormCreate(Sender: TObject);
var
RgnDataSize:integer;
RgnData
RgnData;
Reader:TFileStream;
begin
AppPath:=ExtractFilePath(Paramstr(0));
try
Reader:=TFileStream.Create(AppPath+'video.msk',fmOpenRead);
Reader.Read(RgnDataSize,Sizeof(RgnDataSize));
if RgnDataSize=0 then
exit;
GetMem(RgnData,RgnDataSize);
//为重绘区域申请内存
Reader.Read(RgnData^,RgnDataSize);
Reader.Free;
Rgn:=ExtCreateRegion(Nil,RgnDataSize,RgnData^);
//根据内存建立一个绘制区域
if Rgn=0 then
exit;
SetWindowRgn(Handle,Rgn,True);
//重新绘制窗口
Image1.Picture.LoadFromFile(AppPath+'video.bmp');
Width:=Image1.Picture.Bitmap.Width;
Height:=Image1.Picture.Bitmap.Height;
except
MessageDlg('Can not load .msk files',mtError,[mbOK],0);
Application.Terminate;
exit;
end;
end;
procedure TMainForm.Image2Click(Sender: TObject);
begin
Close;
end;
procedure TMainForm.Image3Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
if OpenDialog1.FileName<> '' then
begin
MPlayer1.FileName:= OpenDialog1.FileName;
MPlayer1.Play;
end
else
ShowMessage('请选择视频文件!');
end;
end;
end.