当进度达到 100 时停止播放 WAV 文件

Stop playing WAV file when progress reaches 100

procedure TfrmWelcome.tmr1Timer(Sender: TObject);
begin
  pgb1.StepBy(10);
  imgWelcome.Stretch := True;
  if (pgb1.Position = 10) then
  begin
    sndPlaySound('Mammoth.wav', SND_NODEFAULT or SND_ASYNC); // plays Wav File
  end;

如何在进度条达到 100 时停止播放 WAV 文件?

答案在documentation:

SND_ASYNC
The sound is played asynchronously and the function returns immediately after beginning the sound. To terminate an asynchronously played sound, call sndPlaySound with lpszSound set to NULL.

试试这个:

procedure TfrmWelcome.tmr1Timer(Sender: TObject);
begin
  pgb1.StepBy(10);
  imgWelcome.Stretch := True;
  Case pgb1.Position of
    10: begin
      sndPlaySound('Mammoth.wav', SND_NODEFAULT or SND_ASYNC); // plays Wav File
    end;
    100: begin
      sndPlaySound(nil, SND_ASYNC); // stops Wav File
    end;
  end;
end;