网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Delphi
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.用Delphi编写系统进程监控程序.
.COM/DCOM中如何传递数组.
.DELPHI面向对象支持特点--保护级.
.利用Delphi和金山词霸制作批量单.
.delphi制作的托盘程序.
.如何得到硬盘物理序号.
.在Delphi中进行指纹仪的二次开发.
.通过实例看VCL组件开发全过程(四.
.Delphi中的线程类--之(2).
.Delphi数据库编程教程(三).
.Delphi实现Singleton模式.
.Delphi的桌面设置功能挖掘.
.创建Photoshop式浮动窗口应用程序.
.根据数据库表中记录自动构造一棵.
.利用INI文件实现界面无闪烁多语言.
.代码重构——之获得封装性DELPHI.
.TComboBox下拉取值.
.Delphi和Office程序开发.
.XP/2003下开放3389最简单的方法.
.MIDAS中动态强制约束编程.

音量调节及静音

发表日期:2006-2-4


 

在进行多媒体软件开发时,经常要调整各种设备的音量和设置静音,本人编写了一个单元,四个函数,分别用于获取音量(GetVolume(DN))、设置音量(SetVolume(DN,Value))、获取静音(GetVolumeMute(DN))及设置静音(SetVolumeMute(DN,Value))。

unit funVolume;

interface

uses MMSystem, Dialogs;

Type TDeviceName = (Master, Microphone, WaveOut, Synth);

function  GetVolume(DN:TDeviceName) : Word ;
procedure SetVolume(DN:TDeviceName; Value:Word);
function  GetVolumeMute(DN:TDeviceName) : Boolean;
procedure  SetVolumeMute(DN:TDeviceName; Value:Boolean);

implementation

//获取音量
function GetVolume(DN:TDeviceName) : Word;
var
 hMix: HMIXER;
 mxlc: MIXERLINECONTROLS;
 mxcd: TMIXERCONTROLDETAILS;
 vol: TMIXERCONTROLDETAILS_UNSIGNED;
 mxc: MIXERCONTROL;
 mxl: TMixerLine;
 intRet: Integer;
 nMixerDevs: Integer;
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);

   // get line 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_VOLUME;
     mxlc.cControls := 1;
     mxlc.cbmxctrl := SizeOf(mxc);

     mxlc.pamxctrl := @mxc;
     intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);

     if intRet = MMSYSERR_NOERROR then
     begin
       FillChar(mxcd, SizeOf(mxcd),0);
       mxcd.dwControlID := mxc.dwControlID;
       mxcd.cbStruct := SizeOf(mxcd);
       mxcd.cMultipleItems := 0;
       mxcd.cbDetails := SizeOf(Vol);
       mxcd.paDetails := @vol;
       mxcd.cChannels := 1;

       intRet := mixerGetControlDetails(hMix, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);

       Result := vol.dwValue ;

       if intRet <> MMSYSERR_NOERROR then
         ShowMessage('GetControlDetails Error');
     end
     else
       ShowMessage('GetLineInfo Error');
   end;
   intRet := mixerClose(hMix);
 end;
end;

//设置音量
procedure setVolume(DN:TDeviceName; Value : Word);
var
 hMix: HMIXER;
 mxlc: MIXERLINECONTROLS;
 mxcd: TMIXERCONTROLDETAILS;
 vol: TMIXERCONTROLDETAILS_UNSIGNED;
 mxc: MIXERCONTROL;
 mxl: TMixerLine;
 intRet: Integer;
 nMixerDevs: Integer;
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);

   // get line 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_VOLUME;
     mxlc.cControls := 1;
     mxlc.cbmxctrl := SizeOf(mxc);

     mxlc.pamxctrl := @mxc;
     intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);

     if intRet = MMSYSERR_NOERROR then
     begin
       FillChar(mxcd, SizeOf(mxcd),0);
       mxcd.dwControlID := mxc.dwControlID;
       mxcd.cbStruct := SizeOf(mxcd);
       mxcd.cMultipleItems := 0;
       mxcd.cbDetails := SizeOf(Vol);
       mxcd.paDetails := @vol;
       mxcd.cChannels := 1;

       vol.dwValue := 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;

//获取静音
function  GetVolumeMute(DN:TDeviceName) : 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;

       // Get  mute
       intRet := mixerGetControlDetails(hMix, @mxcd, MIXER_SETCONTROLDETAILSF_VALUE);

       if mcdMute.fValue = 0 then Result:=false
       else Result := True;

       if intRet <> MMSYSERR_NOERROR then
         ShowMessage('SetControlDetails Error');
     end
     else
       ShowMessage('GetLineInfo Error');
   end;

   intRet := mixerClose(hMix);
 end;
end;

//设置静音
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.

上一篇:基本图象处理代码(2) 人气:3883
下一篇:给Delphi/C++Builder程序员:编写高质量代码的一个小窍门 人气:3873
浏览全部Delphi的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐