把wav文件编译到可执行文件中

| No Comments | No TrackBacks

把wav文件编译到可执行文件中

第一步:建立一个rc文件.
例如:my.rc,内容如下:
mymusic wave music.wav
其中mymusic为资源名称,wave为资源类型,music.wav为一个存在的wav文件名.
第二步:编译这个文件.
>BRCC32 my.rc
BRCC32.exe在.../borland/delphi5/bin/目录下,
编译后生成一个资源文件my.res
第三步:加到程序中去.
在{$R *.res}后加上{$R SOUND.RES}
最后怎样调用这个资源呢?看:
var FindHandle, ResHandle: THandle;
    ResPtr: Pointer;
begin
  FindHandle:=FindResource(HInstance, 'mymusic'', 'wave');//找到这个资源的句柄.
  if FindHandle<>0 then begin
    ResHandle:=LoadResource(HInstance, FindHandle);//获得资源所在内存的句柄
    if ResHandle<>0 then begin
      ResPtr:=LockResource(ResHandle);//锁定资源.
      if ResPtr<>Nil then
        SndPlaySound(PChar(ResPtr), snd_ASync or snd_Memory);//播放这个音乐.
       UnlockResource(ResHandle);
    end;
    FreeResource(FindHandle);
  end;
end;
好了,现在就可以听到这段音乐了.
  

No TrackBacks

TrackBack URL: http://www.wujianrong.com/mt-tb.cgi/605

Leave a comment

About this Entry

This page contains a single entry by kevinwu published on April 17, 2006 2:04 PM.

Ajax专题 was the previous entry in this blog.

Window下的例子动态生成EXE文件代码 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.