Borland Delphi
Including (Linking/Embeding) Resources to Executables
Clock WAVE "c:mysoundsprojectsclock.wav"
MailBeep WAVE "c:windowsmedia
ewmail.wav"
Cool AVI cool.avi
Intro RCDATA introsong.mp3
{$R *.DFM} {$R Delphi.RES}
procedure TForm1.FormCreate(Sender: TObject) ;
begin
with Animate1 do begin
ResName := ´cool´;
ResHandle := hInstance;
Active := TRUE;
end;
end;
uses mmsystem;
...
procedure TForm1.Button1Click(Sender: TObject) ;
var
hFind, hRes: THandle;
Song: PChar;
begin
hFind := FindResource(HInstance, ´MailBeep´, ´WAVE´) ;
if hFind <> 0 then begin
hRes:=LoadResource(HInstance, hFind) ;
if hRes <> 0 then begin
Song:=LockResource(hRes) ;
if Assigned(Song) then SndPlaySound(Song, snd_ASync or snd_Memory) ;
UnlockResource(hRes) ;
end;
FreeResource(hFind) ;
end;
end;
procedure TForm1.Button2Click(Sender: TObject) ;
var
rStream: TResourceStream;
fStream: TFileStream;
fname: string;
begin
{this part extracts the mp3 from exe}
fname := ExtractFileDir(Paramstr(0))+´Intro.mp3´;
rStream := TResourceStream.Create(hInstance, ´Intro´, RT_RCDATA) ;
try
fStream := TFileStream.Create(fname, fmCreate) ;
try
fStream.CopyFrom(rStream, 0) ;
finally
fStream.Free;
end;
finally
rStream.Free;
end;
{this part plays the mp3}
MediaPlayer1.Close;
MediaPlayer1.FileName:=fname;
MediaPlayer1.Open;
end;
MailBeep WAVE "c:windowsmedia
ewmail.wav"
Cool AVI cool.avi
Intro RCDATA introsong.mp3
{$R *.DFM} {$R Delphi.RES}
procedure TForm1.FormCreate(Sender: TObject) ;
begin
with Animate1 do begin
ResName := ´cool´;
ResHandle := hInstance;
Active := TRUE;
end;
end;
uses mmsystem;
...
procedure TForm1.Button1Click(Sender: TObject) ;
var
hFind, hRes: THandle;
Song: PChar;
begin
hFind := FindResource(HInstance, ´MailBeep´, ´WAVE´) ;
if hFind <> 0 then begin
hRes:=LoadResource(HInstance, hFind) ;
if hRes <> 0 then begin
Song:=LockResource(hRes) ;
if Assigned(Song) then SndPlaySound(Song, snd_ASync or snd_Memory) ;
UnlockResource(hRes) ;
end;
FreeResource(hFind) ;
end;
end;
procedure TForm1.Button2Click(Sender: TObject) ;
var
rStream: TResourceStream;
fStream: TFileStream;
fname: string;
begin
{this part extracts the mp3 from exe}
fname := ExtractFileDir(Paramstr(0))+´Intro.mp3´;
rStream := TResourceStream.Create(hInstance, ´Intro´, RT_RCDATA) ;
try
fStream := TFileStream.Create(fname, fmCreate) ;
try
fStream.CopyFrom(rStream, 0) ;
finally
fStream.Free;
end;
finally
rStream.Free;
end;
{this part plays the mp3}
MediaPlayer1.Close;
MediaPlayer1.FileName:=fname;
MediaPlayer1.Open;
end;
LetzteChance.Org - Links -