A piece of Delphi code for setting and canceling windows mute Effect

Source: Internet
Author: User

Seeing perfect mm asking for such a DOS command in windows, I found no, so I excerpted the following code and compiled a console program.

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
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.