<pre><b>unit</b> USndVol;

<b>interface</b>

<b>uses</b>
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    btnMute: TButton;
    btnLoud: TButton;
    btnBeep: TButton;
    procedure btnMuteClick(Sender: TObject);
    procedure btnLoudClick(Sender: TObject);
    procedure btnBeepClick(Sender: TObject);
  <b>private</b>
    adwVol: <b>array</b> <b>of</b> DWORD;
  <b>end</b>;
<b>var</b>
  Form1: TForm1;
<b>implementation</b>

<b>uses</b>
  <em>mmsystem;</em>

{&#36;R *.DFM}

<b>procedure</b> TForm1.btnMuteClick(Sender: TObject);
<b>var</b>
  i, iDev: integer;
  dwVolume: DWORD;
<b>begin</b>
  iDev := <em>waveOutGetNumDevs</em>;       // サウンドデバイス数を取得
  SetLength(adwVol, iDev);         // 音量配列の初期化
  <b>for</b> i := 0 <b>to</b> Pred(iDev) <b>do</b>
  <b>begin</b>
    <em>waveOutGetVolume</em>(i, @dwVolume); // それぞれのデバイスの音量を取得
    adwVol[i] := dwVolume;         // 音量を配列に保存
    <em>waveOutSetVolume</em>(i, &#36;0000);    // 消音
  <b>end</b>;
<b>end</b>;

<b>procedure</b> TForm1.btnLoudClick(Sender: TObject);
<b>var</b>
  i, iDev: integer;
<b>begin</b>
  iDev := <em>waveOutGetNumDevs</em>;       // サウンドデバイス数を取得
  <b>for</b> i := 0 <b>to</b> Pred(iDev) <b>do</b>
    <em>waveOutSetVolume</em>(i, adwVol[i]); // 音量を復元
<b>end</b>;

<b>procedure</b> TForm1.btnBeepClick(Sender: TObject);
<b>begin</b>
  Beep;        // テスト用
<b>end</b>;
<b>end</b>.
</pre>