8月302018
AU3控制当前程序的音量
#RequireAdmin
#pre_usex64=n
#QQ交流群:477266297
#include <GUIConstants.au3>
Opt('MustDeclareVars', 1)
Global $MainForm = GUICreate('SoundValueTest', 400, 200, -1, -1)
Global $Sli_SoundValue = GUICtrlCreateSlider(10, 112, 380, 20)
GUICtrlSetLimit($Sli_SoundValue, 100, 0)
GUICtrlSetData($Sli_SoundValue, waveOutGetVolume())
Global $Lbl_CurrentSound = GUICtrlCreateLabel("当前程序音量:", 10, 16, 100, 41)
Global $Lbl_CurrentSoundValue = GUICtrlCreateLabel(waveOutGetVolume(), 110, 16, 164, 41)
GUICtrlSetColor($Lbl_CurrentSoundValue, 0xff0000)
GUISetState()
Local $nMsg
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Sli_SoundValue
waveOutSetVolume(0, GUICtrlRead($Sli_SoundValue))
GUICtrlSetData($Lbl_CurrentSoundValue, waveOutGetVolume())
EndSwitch
WEnd
;~ 第二个参数的低字节是左声道音量,高字节是右声道音量
Func waveOutGetVolume($hHwd = 0)
Local $WaveVol = -1
Local $tBuffer = DllStructCreate("dword")
If @error Then Return SetError(2, 0, -2)
Local $ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", $hHwd, "long", DllStructGetPtr($tBuffer))
If @error Then Return SetError($ret[0], 0, $WaveVol)
$WaveVol = Round(100 * DllStructGetData($tBuffer, 1) / 0xFFFF)
Return SetError($ret[0], 0, $WaveVol)
EndFunc ;==>waveOutGetVolume
Func waveOutSetVolume($hHwd = 0, $Round = 100)
Local $iSoundValue = Round(0xFFFF * $Round / 100)
Local $ret = DllCall('winmm.dll', 'none', 'waveOutSetVolume', 'hwnd', $hHwd, 'dword', $iSoundValue)
Return $ret[0] = ''
EndFunc ;==>waveOutSetVolume```
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!