系统音量控制问题,急急急! 怎么去系统总音量是否静音?怎么控制总音量静音? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit Unit2;interfaceuses MMSystem, Dialogs;Type TDeviceType = (dtMaster, dtMicrophone, dtWaveOut, dtSynth,dtCD);//主音量,MIC,Wave输出,MIDI输出,CD输出. TValueType = (vtVolume, vtMute, vtDeviceName); TAUDIODevice=Class private FDeviceType:TDeviceType; FDeviceName:String; procedure SetMute(const Value: Boolean); procedure SetVolume(const Value: Word); function GetValue(ValueType:TValueType): Word; function GetVolume: Word; function GetMute: Boolean; procedure SetValue(Value: Word;ValueType:TValueType); function GetDeviceName: String; Public Property DeviceType:TDeviceType read FDeviceType write FDeviceType; Property DeviceName:String Read GetDeviceName; Property Volume:Word Read GetVolume Write SetVolume; Property Mute:Boolean Read GetMute Write SetMute; end;const DeviceTypeName:Array [TDeviceType] of String = ('Master', 'Microphone', 'WaveOut', 'Synth','CD');implementationUses sysutils;{ TAUDIODevice }//设置音量或者静音procedure TAUDIODevice.SetValue(Value : Word;ValueType:TValueType);var PriMixer: HMIXER; PriMixLineControl: MIXERLINECONTROLS; PriMixerControlDetails: TMIXERCONTROLDETAILS; PriMixerControlDetails_Unsigned: TMIXERCONTROLDETAILS_UNSIGNED; PriMixerControl: MIXERCONTROL; PriMixerLine: TMixerLine; iReturn: Integer;begin if (mixerGetNumDevs() < 1) then Exit; if ValueType=vtDeviceName then Exit; iReturn := mixerOpen(@PriMixer, 0, 0, 0, 0); if iReturn = MMSYSERR_NOERROR then begin case FDeviceType of dtMaster : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; dtMicrophone : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE; dtWaveOut : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT; dtSynth : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER; dtCD : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC; end; PriMixerLine.cbStruct := SizeOf(PriMixerLine); iReturn := mixerGetLineInfo(PriMixer, @PriMixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE); if iReturn = MMSYSERR_NOERROR then begin FillChar(PriMixLineControl, SizeOf(PriMixLineControl),0); PriMixLineControl.cbStruct := SizeOf(PriMixLineControl); PriMixLineControl.dwLineID := PriMixerLine.dwLineID; if ValueType=vtMute then PriMixLineControl.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE else if ValueType=vtVolume then PriMixLineControl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME; PriMixLineControl.cControls := 1; PriMixLineControl.cbmxctrl := SizeOf(PriMixerControl); PriMixLineControl.pamxctrl := @PriMixerControl; iReturn := mixerGetLineControls(PriMixer, @PriMixLineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE); if iReturn = MMSYSERR_NOERROR then begin FillChar(PriMixerControlDetails, SizeOf(PriMixerControlDetails),0); PriMixerControlDetails.dwControlID := PriMixerControl.dwControlID; PriMixerControlDetails.cbStruct := SizeOf(PriMixerControlDetails); PriMixerControlDetails.cMultipleItems := 0; PriMixerControlDetails.cbDetails := SizeOf(PriMixerControlDetails_Unsigned); PriMixerControlDetails.paDetails := @PriMixerControlDetails_Unsigned; PriMixerControlDetails.cChannels := 1; PriMixerControlDetails_Unsigned.dwValue := Value; iReturn := mixerSetControlDetails(PriMixer, @PriMixerControlDetails,MIXER_SETCONTROLDETAILSF_VALUE); if iReturn <> MMSYSERR_NOERROR then Raise Exception.Create('Set Control Details Error!'); end else Raise Exception.Create('Get Control Line Information Error!'); end; mixerClose(PriMixer); end;end;function TAUDIODevice.GetValue(ValueType:TValueType): Word;var PriMixer: HMIXER; PriMixLineControl: MIXERLINECONTROLS; PriMixerControlDetails: TMIXERCONTROLDETAILS; PriMixerControlDetails_Unsigned: TMIXERCONTROLDETAILS_UNSIGNED; PriMixerControl: MIXERCONTROL; PriMixerLine: TMixerLine; iReturn: Integer;begin Result:=0; //检查是否有相关设备. FDeviceName:=''; if (mixerGetNumDevs() < 1) then Exit; //打开Mixer设备. iReturn := mixerOpen(@PriMixer, 0, 0, 0, 0); if iReturn = MMSYSERR_NOERROR then begin //初始化参数. case FDeviceType of dtMaster : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; dtMicrophone : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE; dtWaveOut : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT; dtSynth : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER; dtCD : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC; end; PriMixerLine.cbStruct := SizeOf(PriMixerLine); //得到设备信息. iReturn := mixerGetLineInfo(PriMixer, @PriMixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE); if iReturn = MMSYSERR_NOERROR then //返回正常. begin if ValueType=vtDeviceName then FDeviceName:=PriMixerLine.szName else begin FillChar(PriMixLineControl, SizeOf(MIXERLINECONTROLS),0); //清零. PriMixLineControl.cbStruct := SizeOf(PriMixLineControl); PriMixLineControl.dwLineID := PriMixerLine.dwLineID; if ValueType=vtMute then PriMixLineControl.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE else if ValueType=vtVolume then PriMixLineControl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME; PriMixLineControl.cControls := 1; PriMixLineControl.cbmxctrl := SizeOf(MIXERCONTROL); PriMixLineControl.pamxctrl := @PriMixerControl; iReturn := mixerGetLineControls(PriMixer, @PriMixLineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE); if iReturn = MMSYSERR_NOERROR then begin FillChar(PriMixerControlDetails, SizeOf(PriMixerControlDetails),0); PriMixerControlDetails.dwControlID := PriMixerControl.dwControlID; PriMixerControlDetails.cbStruct := SizeOf(PriMixerControlDetails); PriMixerControlDetails.cMultipleItems := 0; PriMixerControlDetails.cbDetails := SizeOf(PriMixerControlDetails_Unsigned); PriMixerControlDetails.paDetails := @PriMixerControlDetails_Unsigned; PriMixerControlDetails.cChannels := 1; //得到详细信息. iReturn := mixerGetControlDetails(PriMixer, @PriMixerControlDetails,MIXER_SETCONTROLDETAILSF_VALUE); //音量. Result := PriMixerControlDetails_Unsigned.dwValue; if iReturn <> MMSYSERR_NOERROR then Raise Exception.Create('Get Control Details Error!'); end else Raise Exception.Create('Get Control Line Information Error!'); end; end; mixerClose(PriMixer); //关闭. end;end;function TAUDIODevice.GetMute: Boolean;begin Result:=GetValue(vtMute)<>0;end;procedure TAUDIODevice.SetMute(const Value: Boolean);begin SetValue(ABS(ORD(Value)),vtMute);end;procedure TAUDIODevice.SetVolume(const Value: Word);begin SetValue(Value,vtVolume);end;function TAUDIODevice.GetVolume: Word;begin Result:=GetValue(vtVolume);end;function TAUDIODevice.GetDeviceName: String;begin GetValue(vtDeviceName); Result:=FDeviceName;end; 贴少了 个 "end."再最后,自己注意一下 http://www.delphiun.com/down_view.asp?id=1803http://www.delphibox.com/article.asp?articleid=1158http://www.coderpub.com/View.aspx?fbId=5&Id=2341 用Mixer控制API即可上面都说了的 关于网络监控 运行出错问题 一个非常反常的问题,百思不得其解。大家来试试 请问调用DLL动态连接库的时候为什么老是出错,应该怎么调用? activex的变量类型的问题 如何用combobox实现动态模糊筛选数据表的内容并显示 InterBase server安装的注册码是多少? 用ado连接orcale 数据库时怎么使它不出现密码输入框?(我已经选择了允许保存密码) 关于字符串表达式的计算问题 各位大神。请问这段C++代码翻译成Delphi 是什么? delphi7如何安装winsock2呀? !!!重金悬赏!:客户机访问服务器数据的连接问题
TDeviceType = (dtMaster, dtMicrophone, dtWaveOut, dtSynth,dtCD);
//主音量,MIC,Wave输出,MIDI输出,CD输出.
TValueType = (vtVolume, vtMute, vtDeviceName);
TAUDIODevice=Class
private
FDeviceType:TDeviceType;
FDeviceName:String;
procedure SetMute(const Value: Boolean);
procedure SetVolume(const Value: Word);
function GetValue(ValueType:TValueType): Word;
function GetVolume: Word;
function GetMute: Boolean;
procedure SetValue(Value: Word;ValueType:TValueType);
function GetDeviceName: String;
Public
Property DeviceType:TDeviceType read FDeviceType write FDeviceType;
Property DeviceName:String Read GetDeviceName;
Property Volume:Word Read GetVolume Write SetVolume;
Property Mute:Boolean Read GetMute Write SetMute;
end;const DeviceTypeName:Array [TDeviceType] of String = ('Master', 'Microphone', 'WaveOut', 'Synth','CD');implementation
Uses sysutils;
{ TAUDIODevice }//设置音量或者静音
procedure TAUDIODevice.SetValue(Value : Word;ValueType:TValueType);
var
PriMixer: HMIXER;
PriMixLineControl: MIXERLINECONTROLS;
PriMixerControlDetails: TMIXERCONTROLDETAILS;
PriMixerControlDetails_Unsigned: TMIXERCONTROLDETAILS_UNSIGNED;
PriMixerControl: MIXERCONTROL;
PriMixerLine: TMixerLine;
iReturn: Integer;
begin
if (mixerGetNumDevs() < 1) then
Exit;
if ValueType=vtDeviceName then
Exit; iReturn := mixerOpen(@PriMixer, 0, 0, 0, 0);
if iReturn = MMSYSERR_NOERROR then
begin
case FDeviceType of
dtMaster : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
dtMicrophone : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
dtWaveOut : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
dtSynth : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
dtCD : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;
end;
PriMixerLine.cbStruct := SizeOf(PriMixerLine); iReturn := mixerGetLineInfo(PriMixer, @PriMixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE); if iReturn = MMSYSERR_NOERROR then
begin
FillChar(PriMixLineControl, SizeOf(PriMixLineControl),0);
PriMixLineControl.cbStruct := SizeOf(PriMixLineControl);
PriMixLineControl.dwLineID := PriMixerLine.dwLineID;
if ValueType=vtMute then
PriMixLineControl.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE
else if ValueType=vtVolume then
PriMixLineControl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
PriMixLineControl.cControls := 1;
PriMixLineControl.cbmxctrl := SizeOf(PriMixerControl); PriMixLineControl.pamxctrl := @PriMixerControl;
iReturn := mixerGetLineControls(PriMixer, @PriMixLineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE); if iReturn = MMSYSERR_NOERROR then
begin
FillChar(PriMixerControlDetails, SizeOf(PriMixerControlDetails),0);
PriMixerControlDetails.dwControlID := PriMixerControl.dwControlID;
PriMixerControlDetails.cbStruct := SizeOf(PriMixerControlDetails);
PriMixerControlDetails.cMultipleItems := 0;
PriMixerControlDetails.cbDetails := SizeOf(PriMixerControlDetails_Unsigned);
PriMixerControlDetails.paDetails := @PriMixerControlDetails_Unsigned;
PriMixerControlDetails.cChannels := 1; PriMixerControlDetails_Unsigned.dwValue := Value; iReturn := mixerSetControlDetails(PriMixer, @PriMixerControlDetails,MIXER_SETCONTROLDETAILSF_VALUE); if iReturn <> MMSYSERR_NOERROR then
Raise Exception.Create('Set Control Details Error!');
end
else
Raise Exception.Create('Get Control Line Information Error!');
end;
mixerClose(PriMixer);
end;
end;function TAUDIODevice.GetValue(ValueType:TValueType): Word;
var
PriMixer: HMIXER;
PriMixLineControl: MIXERLINECONTROLS;
PriMixerControlDetails: TMIXERCONTROLDETAILS;
PriMixerControlDetails_Unsigned: TMIXERCONTROLDETAILS_UNSIGNED;
PriMixerControl: MIXERCONTROL;
PriMixerLine: TMixerLine;
iReturn: Integer;
begin
Result:=0;
//检查是否有相关设备.
FDeviceName:='';
if (mixerGetNumDevs() < 1) then
Exit; //打开Mixer设备.
iReturn := mixerOpen(@PriMixer, 0, 0, 0, 0);
if iReturn = MMSYSERR_NOERROR then
begin
//初始化参数.
case FDeviceType of
dtMaster : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
dtMicrophone : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
dtWaveOut : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
dtSynth : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
dtCD : PriMixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;
end;
PriMixerLine.cbStruct := SizeOf(PriMixerLine); //得到设备信息.
iReturn := mixerGetLineInfo(PriMixer, @PriMixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE); if iReturn = MMSYSERR_NOERROR then
//返回正常.
begin
if ValueType=vtDeviceName then
FDeviceName:=PriMixerLine.szName
else
begin
FillChar(PriMixLineControl, SizeOf(MIXERLINECONTROLS),0);
//清零.
PriMixLineControl.cbStruct := SizeOf(PriMixLineControl);
PriMixLineControl.dwLineID := PriMixerLine.dwLineID;
if ValueType=vtMute then
PriMixLineControl.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE
else if ValueType=vtVolume then
PriMixLineControl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
PriMixLineControl.cControls := 1;
PriMixLineControl.cbmxctrl := SizeOf(MIXERCONTROL); PriMixLineControl.pamxctrl := @PriMixerControl;
iReturn := mixerGetLineControls(PriMixer, @PriMixLineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE); if iReturn = MMSYSERR_NOERROR then
begin
FillChar(PriMixerControlDetails, SizeOf(PriMixerControlDetails),0);
PriMixerControlDetails.dwControlID := PriMixerControl.dwControlID;
PriMixerControlDetails.cbStruct := SizeOf(PriMixerControlDetails);
PriMixerControlDetails.cMultipleItems := 0;
PriMixerControlDetails.cbDetails := SizeOf(PriMixerControlDetails_Unsigned);
PriMixerControlDetails.paDetails := @PriMixerControlDetails_Unsigned;
PriMixerControlDetails.cChannels := 1; //得到详细信息.
iReturn := mixerGetControlDetails(PriMixer, @PriMixerControlDetails,MIXER_SETCONTROLDETAILSF_VALUE); //音量.
Result := PriMixerControlDetails_Unsigned.dwValue; if iReturn <> MMSYSERR_NOERROR then
Raise Exception.Create('Get Control Details Error!');
end
else
Raise Exception.Create('Get Control Line Information Error!');
end;
end;
mixerClose(PriMixer);
//关闭.
end;
end;function TAUDIODevice.GetMute: Boolean;
begin
Result:=GetValue(vtMute)<>0;
end;procedure TAUDIODevice.SetMute(const Value: Boolean);
begin
SetValue(ABS(ORD(Value)),vtMute);
end;procedure TAUDIODevice.SetVolume(const Value: Word);
begin
SetValue(Value,vtVolume);
end;function TAUDIODevice.GetVolume: Word;
begin
Result:=GetValue(vtVolume);
end;function TAUDIODevice.GetDeviceName: String;
begin
GetValue(vtDeviceName);
Result:=FDeviceName;
end;
http://www.delphibox.com/article.asp?articleid=1158
http://www.coderpub.com/View.aspx?fbId=5&Id=2341
上面都说了的