[源代码]系统音量控制
来源:互联网 发布:mac不小心删除了文件 编辑:程序博客网 时间:2024/06/11 02:56
因为网上关于API控制系统音量的资料都是C++的,于是我先用C++写了个。这个程序能设置系统的当前音量。有时间用汇编再写一遍,主要里面的用到的结构定义很繁琐。一份好的参考资料:
http://202.38.64.13/personal/cs011/csli/vc_note/MIXER.htm
PS:无语掉。程序拿到Win7后说不行。在CSDN上查说,Vista之后,设置全局的音量的话用ISimpleAudioVolume::SetMasterVolume 。。。。
http://topic.csdn.net/u/20100930/18/f6ad08c7-43e6-4c23-a70f-3c8a3cd4f06c.html
无奈说下面是XP版控制音量:
Win7版:
参考资料:
http://msdn.microsoft.com/en-us/library/dd370892(v=VS.85).aspx
http://www.cnblogs.com/gingerjws/archive/2010/10/28/1863560.html
http://audacity.googlecode.com/svn-history/r10708/audacity-src/vendor/portaudio-v19/current/src/hostapi/wasapi/mingw-include/mmdeviceapi.h
http://www.portaudio.com/docs/v19-doxydocs/endpointvolume_8h-source.html
.386
.model flat,stdcall
option casemap:none
include e:/masm32/include/windows.inc
include e:/masm32/include/kernel32.inc
includelib e:/masm32/lib/kernel32.lib
include e:/masm32/include/user32.inc
includelib e:/masm32/lib/user32.lib
include e:/masm32/include/ole32.inc
includelib e:/masm32/lib/ole32.lib
eRender equ 0
eConsole equ 0
.data?
lpEnumerator dd ?
lpDevice dd ?
lpAudioEndpointVolume dd ?
fLevel dd ?
bMute db ?
szBuffer db 32 dup (?)
.data
;CLSID_MMDeviceEnumerator = {BCDE0395-E52F-467C-8E3D-C4579291692E}
;IID_IMMDeviceEnumerator = {A95664D2-9614-4F35-A746-DE8DB63617E6}
;IID_IAudioEndpointVolume = {5CDF2C82-841E-4546-9722-0CF74078229A}
CLSID_MMDeviceEnumerator GUID <0BCDE0395h,0E52Fh,467Ch,<8Eh,3Dh,0C4h,57h,92h,91h,69h,2Eh>>
IID_IMMDeviceEnumerator GUID <0A95664D2h,9614h,4F35h,<0A7h,46h,0DEh,8Dh,0B6h,36h,17h,0E6h>>
IID_IAudioEndpointVolume GUID <5CDF2C82h,841Eh,4546h,<97h,22h,0Ch,0F7h,40h,78h,22h,9Ah>>
.code
_MsgBoxHex proc uses ebx edi esi,_dwInt
local @szBuffer[9]:byte
local @szFormat[5]:byte
push eax
mov @szFormat[0],'%'
mov @szFormat[1],'0'
mov @szFormat[2],'8'
mov @szFormat[3],'X'
mov @szFormat[4],0
invoke wsprintf,addr @szBuffer,addr @szFormat,_dwInt
invoke MessageBox,NULL,addr @szBuffer,addr @szFormat,MB_OK
pop eax
ret
_MsgBoxHex endp
start:
invoke CoInitialize,NULL
invoke CoCreateInstance,offset CLSID_MMDeviceEnumerator,NULL,/
CLSCTX_INPROC_SERVER,offset IID_IMMDeviceEnumerator,/
offset lpEnumerator
;Enumerator.GetDefaultAudioEndpoint方法
mov esi,lpEnumerator
mov esi,[esi]
push offset lpDevice
push eConsole
push eRender
push lpEnumerator
call dword ptr [esi+16]
;Device.Activate方法
mov esi,lpDevice
mov esi,[esi]
push offset lpAudioEndpointVolume
push NULL
push CLSCTX_ALL
push offset IID_IAudioEndpointVolume
push lpDevice
call dword ptr [esi+12]
;AudioEndpointVolume.GetMasterVolumeLevelScalar方法,获取音量大小
mov esi,lpAudioEndpointVolume
mov esi,[esi]
push offset fLevel
push lpAudioEndpointVolume
call dword ptr [esi+36]
;显示fLevelDB在内存中的浮点型数据
invoke _MsgBoxHex,fLevel
;此处将令fLevel为3F333333h,即0.7
mov fLevel,3F333333h
;AudioEndpointVolume.SetMasterVolumeLevelScalar方法,设置音量大小,设置范围0~1
mov esi,lpAudioEndpointVolume
mov esi,[esi]
push NULL
push fLevel
push lpAudioEndpointVolume
call dword ptr [esi+28]
;AudioEndpointVolume.GetMute方法,获取静音状态
;mov esi,lpAudioEndpointVolume
;mov esi,[esi]
;push offset bMute
;push lpAudioEndpointVolume
;call dword ptr [esi+60]
;AudioEndpointVolume.SetMute方法,更改静音状态
;mov esi,lpAudioEndpointVolume
;mov esi,[esi]
;push NULL
;not bMute
;movzx eax,bMute
;push eax
;push lpAudioEndpointVolume
;call dword ptr [esi+56]
;Release方法
mov esi,lpAudioEndpointVolume
mov esi,[esi]
push lpAudioEndpointVolume
call dword ptr [esi+8]
mov esi,lpDevice
mov esi,[esi]
push lpDevice
call dword ptr [esi+8]
mov esi,lpEnumerator
mov esi,[esi]
push lpEnumerator
call dword ptr [esi+8]
invoke CoUninitialize
invoke ExitProcess,NULL
end start
- [源代码]系统音量控制
- 控制windows系统音量
- Android 系统音量控制
- iOS 系统音量控制
- Android系统的音量控制
- vc 系统音量控制详解
- 调用系统的媒体音量控制显示
- win7 系统下实现音量控制
- iOS系统音量控制——MPVolumeView
- 音量控制
- 自定义控件 设置系统音量时 屏蔽掉系统自带音量控制条
- 【转】Vista下系统音量控制(VC版)
- C代码实现控制Win 7系统音量
- Android中自定义SeekBar来控制音量,并与系统音量键的操作保持同步
- c#音量控制
- [翻译]VISTA音量控制
- 12.1.7 控制音量
- VISTA音量控制
- Delphi 与 C/C++ 数据类型对照表
- 又一个多月啦
- 百度即将开源JavaScript框架Tangram
- U3d常规性能优化技巧
- 数说
- [源代码]系统音量控制
- 改变magento前台和后台的ico图标
- 初学者如何用日语自我介绍
- 要配一台新的电脑
- WEB安全测试
- 2010年中国IT行业的十大案件
- 每天的工作
- 结构体net_device在2.6.31中函数接口的改动
- org.hibernate.hql.ast.QuerySyntaxError错误