一段設定和取消windows靜音效果的Delphi代碼

來源:互聯網
上載者:User

 看到完美mm在windows版提問求這麼一個dos命令,發現沒有,於是自己摘錄了以下代碼編譯了一個控制台程式

unit Unit1;
interface
uses MMSystem, Dialogs;
type TDeviceName = (Master, Microphone, WaveOut, Synth);
procedure  SetVolumeMute(DN:TDeviceName; Value:Boolean);
implementation
procedure  SetVolumeMute(DN:TDeviceName; Value:Boolean);
var
hMix: HMIXER;
mxlc: MIXERLINECONTROLS;
mxcd: TMIXERCONTROLDETAILS;
vol: TMIXERCONTROLDETAILS_UNSIGNED;
mxc: MIXERCONTROL;
mxl: TMixerLine;
intRet: Integer;
nMixerDevs: Integer;
mcdMute: MIXERCONTROLDETAILS_BOOLEAN;
begin
// Check if Mixer is available
nMixerDevs := mixerGetNumDevs();
if (nMixerDevs < 1) then
begin
   Exit;
end;
// open the mixer
intRet := mixerOpen(@hMix, 0, 0, 0, 0);
if intRet = MMSYSERR_NOERROR then
begin
   case DN of
     Master :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
     Microphone :
             mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
     WaveOut : mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
     Synth  :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
   end;
    mxl.cbStruct        := SizeOf(mxl);
   // mixerline info
   intRet := mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
   if intRet = MMSYSERR_NOERROR then
   begin
     FillChar(mxlc, SizeOf(mxlc),0);
     mxlc.cbStruct := SizeOf(mxlc);
     mxlc.dwLineID := mxl.dwLineID;
     mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
     mxlc.cControls := 1;
     mxlc.cbmxctrl := SizeOf(mxc);
     mxlc.pamxctrl := @mxc;
     // Get the mute control
     intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
     if intRet = MMSYSERR_NOERROR then
     begin
       FillChar(mxcd, SizeOf(mxcd),0);
       mxcd.cbStruct := SizeOf(TMIXERCONTROLDETAILS);
       mxcd.dwControlID := mxc.dwControlID;
       mxcd.cChannels := 1;
       mxcd.cbDetails := SizeOf(MIXERCONTROLDETAILS_BOOLEAN);
       mxcd.paDetails := @mcdMute;
       // Set and UnSet  mute
       mcdMute.fValue := Ord(Value);
       intRet := mixerSetControlDetails(hMix, @mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
       if intRet <> MMSYSERR_NOERROR then
         ShowMessage('SetControlDetails Error');
     end
     else
       ShowMessage('GetLineInfo Error');
   end;
   intRet := mixerClose(hMix);
end;
end;
end.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.