It's well known that the sound volume functions do not work for Vista's master volume because of Vista's new audio stream system. There's a way to do it, but it requires COM interfaces / objects that AutoIt cannot natively access**, so I wrote a plugin. Here's a collection of the useful interface methods, an example script, and an OSD Volume script. Enjoy!
/**************************************************************************** * _GetMasterVolume_Vista() * * Returns master volume level in decibels. **************************************************************************** * _GetMasterVolumeScalar_Vista() * * Returns master volume level as a scalar value from 0 to 100. **************************************************************************** * _SetMasterVolume_Vista() * * Sets master volume in decibels. **************************************************************************** * _SetMasterVolumeScalar_Vista() * * Sets master volume level as a scalar value from 0 to 100. **************************************************************************** * _GetVolumeRange_Vista() * * Gets volume decibel range information: * LevelMinDB = minimum decibel value * LevelMaxDB = maximum decibel value * VolumeIncrementDB = decibel increment value **************************************************************************** * _IsMute_Vista() * * Gets the mute state. **************************************************************************** * _SetMute_Vista() * * Sets the mute state. **************************************************************************** * _GetVolumeStepInfo_Vista() * * Gets volume step information: * nStep = current volume step * nStepCount = step range; from 0 to nStepCount - 1 **************************************************************************** * _VolumeStepUp_Vista() * * Increases the volume by 1 step. **************************************************************************** * _VolumeStepDown_Vista() * * Decreases the volume by 1 step. ****************************************************************************/
** Well, it can using ProgAndy's solution with the MemoryDLL funcs. But it's a real pain, and it's unclear whether it will work with all DEP settings.
Example -
#AutoIt3Wrapper_Plugin_Funcs=_GetMasterVolume_Vista,_GetMasterVolumeScalar_Vista, _ _SetMasterVolume_Vista,_SetMasterVolumeScalar_Vista,_GetVolumeRange_Vista,_IsMute_Vista, _ _SetMute_Vista,_GetVolumeStepInfo_Vista,_VolumeStepUp_Vista,_VolumeStepDown_Vista $hDLL = PluginOpen("vista_vol.dll") ; ## Get current volume levels $vol = _GetMasterVolume_Vista() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (decibels)" & @CRLF) $vol = _GetMasterVolumeScalar_Vista() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (scalar)" & @CRLF) ; ## Set new volume levels ConsoleWrite("Set vol to -20db..." & @CRLF) _SetMasterVolume_Vista(-20) ConsoleWrite("Set Vol Error: " & @error & @CRLF) $vol = _GetMasterVolume_Vista() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (decibels)" & @CRLF) ConsoleWrite("Set vol to scalar 30..." & @CRLF) _SetMasterVolumeScalar_Vista(30) ConsoleWrite("Set Vol Error: " & @error & @CRLF) $vol = _GetMasterVolumeScalar_Vista() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (scalar)" & @CRLF) ; ## Get volume range information $range = DllStructCreate("float LevelMinDB;float LevelMaxDB;float VolumeIncrementDB") ConsoleWrite("Get range info..." & @CRLF) _GetVolumeRange_Vista(DllStructGetPtr($range)) ConsoleWrite("Get Range Error: " & @error & @CRLF) ConsoleWrite("MinDB: " & DllStructGetData($range, "LevelMinDB") & @CRLF) ConsoleWrite("MaxDB: " & DllStructGetData($range, "LevelMaxDB") & @CRLF) ConsoleWrite("Increment: " & DllStructGetData($range, "VolumeIncrementDB") & @CRLF) ; ## Set mute states ConsoleWrite("Set mute true..." & @CRLF) _SetMute_Vista(True) ConsoleWrite("Set Mute Error: " & @error & @CRLF) $mute = _IsMute_Vista() ConsoleWrite("Get Mute Error: " & @error & @CRLF) ConsoleWrite("Muted: " & $mute & @CRLF) Sleep(2000) ConsoleWrite("Set mute false..." & @CRLF) _SetMute_Vista(False) ConsoleWrite("Set Mute Error: " & @error & @CRLF) $mute = _IsMute_Vista() ConsoleWrite("Get Mute Error: " & @error & @CRLF) ConsoleWrite("Muted: " & $mute & @CRLF) ; ## Get volume step info ; ## Steps range from 0 to nStepCount - 1 $step = DllStructCreate("uint nStep;uint nStepCount") ConsoleWrite("Get step info..." & @CRLF) _GetVolumeStepInfo_Vista(DllStructGetPtr($step)) ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & DllStructGetData($step, "nStep") & @CRLF) ConsoleWrite("Total steps: 0 to " & DllStructGetData($step, "nStepCount") - 1 & @CRLF) ConsoleWrite("Increase 5 steps..." & @CRLF) For $i = 1 To 5 _VolumeStepUp_Vista() Next _GetVolumeStepInfo_Vista(DllStructGetPtr($step)) ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & DllStructGetData($step, "nStep") & @CRLF) ConsoleWrite("Decrease 2 steps..." & @CRLF) For $i = 1 To 2 _VolumeStepDown_Vista() Next _GetVolumeStepInfo_Vista(DllStructGetPtr($step)) ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & DllStructGetData($step, "nStep") & @CRLF) PluginClose($hDLL)
Volume OSD Script -
#NoTrayIcon #Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Plugin_Funcs=_GetMasterVolumeScalar_Vista,_SetMasterVolumeScalar_Vista #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Comment=OSD Volume Control #AutoIt3Wrapper_Res_Description=VolumeOSD #AutoIt3Wrapper_Res_Fileversion=1.0.1.1 #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/striponly #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** #include <GuiConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> #include <Timers.au3> #include <Misc.au3> #include <WinAPI.au3> #include <StaticConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $Volume_OSD_MSG = _WinAPI_RegisterWindowMessage("Volume_OSD_MSG") If _Singleton("VolumeOSD_Mutex", 1) == 0 Then; another instance If $CmdLine[0] == 0 Then Exit; exit if no cmd args If $CmdLine[1] == "exit" Then _SendMessage(WinGetHandle("VolumeOSD_GUI"), $Volume_OSD_MSG, 1, 0); exit remote prog Exit EndIf HotKeySet("{VOLUME_UP}", "_vol_up") HotKeySet("{VOLUME_DOWN}", "_vol_down") Global $gui, $prog, $label, $th, $show, $timer = "" Global $hDLL = PluginOpen("vista_vol.dll") Global $hUserDLL = DllOpen("user32.dll") Global $transColor = 0x232323 $th = WinGetPos("[CLASS:Shell_TrayWnd]") $th = $th[3] $gui = GUICreate("VolumeOSD_GUI", 40, 150, @DesktopWidth - 8 - 40, @DesktopHeight - $th - 8 - 150, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED)) GUISetBkColor($transColor) $prog = GUICtrlCreateProgress(28, 0, 12, 150, BitOR($PBS_SMOOTH, $PBS_VERTICAL)) $label = GUICtrlCreateLabel("", 0, 135, 25, 20, $SS_RIGHT) GUICtrlSetFont(-1, 10, 600) GUICtrlSetColor(-1, 0xDDDDDD) WinSetOnTop($gui, "", 1) _WinAPI_SetLayeredWindowAttributes($gui, $transColor, 0, 0x03, True) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUIRegisterMsg($WM_TIMER, "_MY_WM_TIMER") GUIRegisterMsg($Volume_OSD_MSG, "_MY_CUSTOM_MSG") GUISetState() While 1 Sleep(1000) WEnd Func _MY_WM_TIMER($hWnd, $iMsg, $iwParam, $ilParam) Switch $hWnd Case $gui Switch _Timer_GetTimerID($iwParam) Case $timer _ProgHide() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _vol_up() Local $vol $vol = _GetMasterVolumeScalar_Vista() + 1 If $vol > 100 Then $vol = 100 _SetVolume($vol) EndFunc Func _vol_down() Local $vol $vol = _GetMasterVolumeScalar_Vista() - 1 If $vol < 0 Then $vol = 0 _SetVolume($vol) EndFunc Func _SetVolume($vol) Local $rvol = Round($vol) _SetMasterVolumeScalar_Vista($vol) GUICtrlSetData($prog, $rvol) GUICtrlSetData($label, $rvol) If Not $show Then _ProgShow() If $timer = "" Then $timer = _Timer_SetTimer($gui, 3000) Else $timer = _Timer_SetTimer($gui, 3000, "", $timer) EndIf EndFunc Func _ProgShow() $show = True For $i = 0 To 255 Step 20 _WinAPI_SetLayeredWindowAttributes($gui, $transColor, $i, 0x03, True) Sleep(10) Next _WinAPI_SetLayeredWindowAttributes($gui, $transColor, 255, 0x03, True) EndFunc Func _ProgHide() $show = False For $i = 255 To 0 Step -10 _WinAPI_SetLayeredWindowAttributes($gui, $transColor, $i, 0x03, True) Sleep(10) Next _WinAPI_SetLayeredWindowAttributes($gui, $transColor, 0, 0x03, True) _Timer_KillAllTimers($gui) $timer = "" EndFunc Func _MY_CUSTOM_MSG($hwnd, $msg, $wparam, $lparam) Switch $hwnd Case $gui Switch $wparam Case 1 _Exit() EndSwitch EndSwitch EndFunc ;=============================================================================== ; ; Function Name: _WinAPI_SetLayeredWindowAttributes ; Description:: Sets Layered Window Attributes:) See MSDN for more informaion ; Parameter(s): ; $hwnd - Handle of GUI to work on ; $i_transcolor - Transparent color ; $Transparency - Set Transparancy of GUI ; $isColorRef - If True, $i_transcolor is a COLORREF( 0x00bbggrr ), else an RGB-Color ; Requirement(s): Layered Windows ; Return Value(s): Success: 1 ; Error: 0 ; @error: 1 to 3 - Error from DllCall ; @error: 4 - Function did not succeed - use ; _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information ; Author(s): Prog@ndy ; ; Link : @@MsdnLink@@ SetLayeredWindowAttributes ; Example : Yes ;=============================================================================== Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False) If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03 If Not $isColorRef Then $i_transcolor = Hex(String($i_transcolor), 6) $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2)) EndIf Local $Ret = DllCall($hUserDLL, "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages) Select Case @error Return SetError(@error, 0, 0) Case $Ret[0] = 0 Return SetError(4, _WinAPI_GetLastError(), 0) Case Else Return 1 EndSelect EndFunc;==>_WinAPI_SetLayeredWindowAttributes Func _Exit() PluginClose($hDLL) DllClose($hUserDLL) Exit EndFunc
Attached File(s)
-
vista_vol_plugin.zip (17.45K)
Number of downloads: 459
This post has been edited by wraithdu: 27 April 2009 - 04:26 AM

Sign In
Register
Help


MultiQuote
