uses
  MMSystem;function GetLineInHandle(AudioType : integer) : integer;
var
  i : integer;
  AudioCaps : TAuxCaps;
begin
  result := 0;
  for i := 0 to auxGetNumDevs - 1 do begin
    auxGetDevCaps(i, @AudioCaps, sizeof(AudioCaps));
    if AudioCaps.wTechnology = AudioType then begin
      Result := i;
      Break;
    end;
  end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
  v : DWORD;
begin
  AuxGetVolume(GetLineInHandle(AUXCAPS_CDAUDIO), @v);
  Edit1.Text := IntToStr(LoWord(v));
  Edit2.Text := IntToStr(HiWord(v));
end;procedure TForm1.Button2Click(Sender: TObject);
var
  v : DWORD;
begin
  v := MakeLong(Word(StrToInt(Edit1.Text)),
                Word(StrToInt(Edit2.Text)));
  AuxSetVolume(GetLineInHandle(AUXCAPS_CDAUDIO), v);
end;procedure TForm1.Button3Click(Sender: TObject);
var
  v : DWORD;
begin
  AuxGetVolume(GetLineInHandle(AUXCAPS_AUXIN), @v);
  Edit3.Text := IntToStr(LoWord(v));
  Edit4.Text := IntToStr(HiWord(v));
end;procedure TForm1.Button4Click(Sender: TObject);
var
  v : DWORD;
begin
  v := MakeLong(Word(StrToInt(Edit3.Text)),
                Word(StrToInt(Edit4.Text)));
  AuxSetVolume(GetLineInHandle(AUXCAPS_AUXIN), v);
end;

解决方案 »

  1.   

    uses 后面添加 mmSystem 才能用你的代码打开和关闭CD
      

  2.   

    我有用mmsystem可无法实现cd的打开关闭。
      

  3.   

    我写的一个开cd门的,没有要Form,直接在工程文件里写的,win2k + delphi6 通过:
    program OpenCD;uses
      Forms,
      mmSystem;{$R *.res}begin
      Application.Initialize;
      Application.Title := 'Open The CD-Rom';
      Application.Run;
      mciSendString('set cdaudio door open',nil, 0, 0);
      Application.Terminate;
    end.
      

  4.   

    同理,关闭光驱是这样;
    program closed';uses
      Forms,
      mmSystem;{$R *.res}begin
      Application.Initialize;
      Application.Title := 'closed The CD-Rom';
      Application.Run;
      Mcisendstring('Set cdaudio door closed',nil,0,0);
      Application.Terminate;
    end.
      

  5.   

    下面就介绍一种控制Wave波形输出设备音量的方法,该方法不是设置主音量。先在窗体上放两个TTrackBar,分别命名为TrackBar1,TrackBar2,属性Max都设置为65535,如果觉得刻度太密了,可以把Frequency属性值设置大一些,然后在Uses段加入MMSystem,并在TrackBar1和TrackBar2的OnChange事件都写上下列语句:procedure TForm1.TrackBar1Change(Sender: Tobject);
    var Wave:string;
    begin
    Wave:='$'+inttohex(TrackBar1.Position,4)+inttohex(TrackBar2.Position,4);
    waveoutsetvolume(0,strtoint(Wave));
    end;
    /////////////////////////////////////////////
    WaveOutSetVolume(hwo: Integer; dwVolume: Cardinal);hwo is MediaPlayer1.DeviceId,example:                           Right\/ | Left\/
    dwVolume for Full L+R = $FFFFFFFF
    dwVolume for Full L no R = $0000FFFF
    dwVolume for Full R no L = $FFFF0000
    dwVolume for no sound = $00000000
    /////////////////////////////////////////////////uses  MMSystemtype
      TVolType = (vtLeft, vtRight);
      TVol = array[vtLeft..vtRight] of word;procedure TVolForm.GetVolumes(var DevId : word;
                                var VolLeft, VolRight : word);
    {volume is returned as a pointer to a DWord with the most
     significant word for the left channel. The channels are
     extracted by treating the DWord as a two element array and
     accessing the two array elements for the Lt and Rt volumes}
    var
      Error : integer;
      MsgResponse : word;
      TempVol : TVol;
    begin
      Error := AuxGetVolume(DevId, @TempVol);
      if Error <> 0 then begin
        Timer1.Enabled := false;
        MsgResponse := MessageDlg('Error Reading Volume : ' + IntToStr(Error) +
    chr(13)
                                  + 'DevId : ' + IntToStr(DevId) + chr(13)
                                  + chr(13)
                                  + 'Set Next Device ?',
                                  mtError, [mbYes, mbCancel], 0);
        if MsgResponse = mrYes then {try the next Device Id}
          DevId := DevId + 1
        else begin
          DevId := 0;
          PChangeType := Nil;
        end; {else MsgResponse = mrCancel}
        Exit;
      end; {if Error <> 0}
      VolLeft := TempVol[vtLeft];
      VolRight := TempVol[vtRight];
    end;procedure TVolForm.SetVolumes(DevId : word;
                                var VolLeft, VolRight : word);
    {volume is set by passing a DWord value with the most
     significant word set for the left channel, and the least
     significant word set for the right channel. The channels are
     set by treating the DWord as a two element  array and
     setting the two array elements for the Lt and Rt volumes}
    var
      Error : integer;
      TempVol : TVol;
    begin
      TempVol[vtLeft] := VolLeft;
      TempVol[vtRight] := VolRight;
      Error := AuxSetVolume(DevId, longint(TempVol));
      if Error <> 0 then
        MessageDlg('Error Setting Volume : ' + IntToStr(Error),
                   mtError, [mbOK], 0);
    end;come from hubdog