如何停止通过SndPlaySound开始的音乐 [英] How to stop music started via SndPlaySound
本文介绍了如何停止通过SndPlaySound开始的音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此网站中,我找到了如何将音乐添加到. res文件,然后在delphi .exe中使用它.这是开始播放WAVE歌曲的代码.
At this Website I found how to add music into a .res file and then use it in your delphi .exe. Here is the code for starting the WAVE song.
procedure TForm2.FormActivate(Sender: TObject);
var
hFind, hRes: THandle;
Song: PChar;
begin
hFind := FindResource(HInstance, 'SonicSong', '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;
所以我想知道的是,如何在不关闭应用程序的情况下停止音乐?
So what I would like to know is how do I stop the music when I want to without closing the application?
推荐答案
Call the sndPlaySound
function with the first parameter set to nil
, which causes the currently playing sound to stop. As the second parameter use the SND_ASYNC
flag, because as the reference says, you must use this flag to terminate an asynchronously played waveform sound, which you are playing in your code:
sndPlaySound(nil, SND_ASYNC);
这篇关于如何停止通过SndPlaySound开始的音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文