acidfear Posted May 6, 2007 Posted May 6, 2007 I want to write a little program that shows the current volume at all times, and changes when the volume is changed. Is there a way to read what the current system Volume level is (Windows XP Pro) ?
xcal Posted May 6, 2007 Posted May 6, 2007 You'll probably want to have a look in the help file at the Drive*() functions. I think you want DriveSpaceFree()? How To Ask Questions The Smart Way
acidfear Posted May 6, 2007 Author Posted May 6, 2007 (edited) Oops. I should clarify. I meant audio volume. Hmm.. but you did give me a good idea to work on! Edited May 6, 2007 by acidfear
BrettF Posted May 6, 2007 Posted May 6, 2007 You'll probably want to have a look in the help file at the Drive*() functions. I think you want DriveSpaceFree()?I thought he wanted the sound volume???If so....This topic may have what you want.... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
xcal Posted May 6, 2007 Posted May 6, 2007 Heh oops... when I see volume my brain sees harddrive. The 'volume level' part at the end should have clued me in. How To Ask Questions The Smart Way
acidfear Posted May 6, 2007 Author Posted May 6, 2007 Hmm I couldn't find anything on reading volume levels. Maybe I was just too confused and didn't undetstand
Valuater Posted May 6, 2007 Posted May 6, 2007 maybe... expandcollapse popup#include <GuiConstants.au3> $Volume = _SoundGetWaveVolume() GUICreate("MyGUI", 393, 125, -1, -1) $Slider_1 = GUICtrlCreateSlider(20, 40, 360, 30) GUICtrlSetLimit($Slider_1, 100, 0) GUICtrlSetData($Slider_1, $Volume); $Label_2 = GUICtrlCreateLabel("Volume Control", 30, 10, 140, 20) $Close = GUICtrlCreateButton("Close", 150, 90, 60, 20) SoundSetWaveVolume($Volume) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $Slider_1 SoundSetWaveVolume(GUICtrlRead($Slider_1)) ToolTip(GUICtrlRead($Slider_1)) Sleep(300) ToolTip("") Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Close Exit EndSelect WEnd Exit Func _SoundGetWaveVolume() Local $WaveVol = -1, $p, $ret Const $MMSYSERR_NOERROR = 0 $p = DllStructCreate("dword") If @error Then SetError(2) Return -2 EndIf $ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr($p)) If ($ret[0] == $MMSYSERR_NOERROR) Then $WaveVol = Round(Dec(StringRight(Hex(DllStructGetData($p, 1), 8), 4)) / 0xFFFF * 100) Else SetError(1) EndIf $Struct = 0 Return $WaveVol EndFunc ;==>_SoundGetWaveVolume function from gafrost 8)
acidfear Posted May 14, 2007 Author Posted May 14, 2007 maybe... expandcollapse popup#include <GuiConstants.au3> $Volume = _SoundGetWaveVolume() GUICreate("MyGUI", 393, 125, -1, -1) $Slider_1 = GUICtrlCreateSlider(20, 40, 360, 30) GUICtrlSetLimit($Slider_1, 100, 0) GUICtrlSetData($Slider_1, $Volume); $Label_2 = GUICtrlCreateLabel("Volume Control", 30, 10, 140, 20) $Close = GUICtrlCreateButton("Close", 150, 90, 60, 20) SoundSetWaveVolume($Volume) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $Slider_1 SoundSetWaveVolume(GUICtrlRead($Slider_1)) ToolTip(GUICtrlRead($Slider_1)) Sleep(300) ToolTip("") Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Close Exit EndSelect WEnd Exit Func _SoundGetWaveVolume() Local $WaveVol = -1, $p, $ret Const $MMSYSERR_NOERROR = 0 $p = DllStructCreate("dword") If @error Then SetError(2) Return -2 EndIf $ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr($p)) If ($ret[0] == $MMSYSERR_NOERROR) Then $WaveVol = Round(Dec(StringRight(Hex(DllStructGetData($p, 1), 8), 4)) / 0xFFFF * 100) Else SetError(1) EndIf $Struct = 0 Return $WaveVol EndFunc ;==>_SoundGetWaveVolume function from gafrost 8) Thank you!!
FreeFry Posted May 15, 2007 Posted May 15, 2007 (edited) I was wondering one thing, this can only read/change the Wave volume, is there any way to read the Master volume?I'm using a fix that I made to make my keyboard's volume buttons that change only the Master volume, to also affect the Wave volume, though this involves having a sndvol32.exe process(window) running, and using dll calls to read the value of the Master-volume-slider, and writing that value to the Wave-volume-slider.This is the code I use for this:expandcollapse popupOpt("WinTitleMatchMode", 4) DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) ; This was a workaround to make it work on Windows XP 64bit, though this have probably been fixed by now... Global $pID Global $WindowHandle Global $ControlHandle1 Global $ControlHandle2 Global $Muted = False Global Const $TBM_GETPOS = 0x400 Global Const $TBM_SETPOS = 0x405 Global Const $WM_VSCROLL = 0x115 Global Const $SB_LINEDOWN = 0x1 Global Const $SB_LINEUP = 0x0 $g_szVersion = "Volume Control Fixer v1.1" If WinExists($g_szVersion) Then Exit AutoItWinSetTitle($g_szVersion) While 1 If Not WinExists($WindowHandle) Then _GetHandles() Else $data1 = DllCall("user32.dll", "int", "SendMessage", "hwnd", $ControlHandle1, "int", $TBM_GETPOS, "int", 0, "int", 0) $data2 = DllCall("user32.dll", "int", "SendMessage", "hwnd", $ControlHandle2, "int", $TBM_GETPOS, "int", 0, "int", 0) If $data1[0] <> $data2[0] Then ; Code below is outcommented because it was a little annoying... ;~ If $data1[0] > $data2[0] Then ;~ TrayTip("", "Volume @ " & Int(100-($data1[0]/5)) & "%", 0) ;~ DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $ControlHandle2, "int", $TBM_SETPOS, "int", 1, "int", $data1[0]) ;~ DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $WindowHandle, "int", $WM_VSCROLL, "int", $SB_LINEDOWN, "int", $ControlHandle2) ;~ ElseIf $data1[0] < $data2[0] Then ;~ TrayTip("", "Volume @ " & Int(100-($data1[0]/5)) & "%", 0); works, but buggs out sometimes... annoying, therefore removed ;~ DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $ControlHandle2, "int", $TBM_SETPOS, "int", 1, "int", $data1[0]) ;~ DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $WindowHandle, "int", $WM_VSCROLL, "int", $SB_LINEUP, "int", $ControlHandle2) ;~ EndIf DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $ControlHandle2, "int", $TBM_SETPOS, "int", True, "long", $data1[0]) ; problem with the code above was that even though the $TBM_SETPOS message has the update parameter set to True, it did not update the new position ; so the volume did not change, that's why the $WM_VSCROLL message is sent below. This made it update the window/change the volume.. DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $WindowHandle, "int", $WM_VSCROLL, "int", $SB_LINEDOWN, "int", $ControlHandle2) Else If ControlCommand($WindowHandle, "", "Button2", "IsChecked") And Not $muted Then ControlCommand($WindowHandle, "", "Button4", "Check") TrayTip("Muted!", "Sound Muted!", 0) $muted = True ElseIf Not ControlCommand($WindowHandle, "", "Button2", "IsChecked") And $muted Then ControlCommand($WindowHandle, "", "Button4", "UnCheck") TrayTip("Unmuted!", "Sound Unmuted!", 0) $muted = False EndIf EndIf EndIf Sleep(100) WEnd Func OnAutoItExit() ; less reliable ;~ If WinExists($WindowHandle) Then ;~ WinClose($WindowHandle) ;~ EndIf ; more reliable/preferable.. If ProcessExists($pID) Then ProcessClose($pID) EndIf EndFunc ;==>OnAutoItExit Func _GetHandles() $pID = Run(@SystemDir & "\sndvol32.exe", @SystemDir, @SW_HIDE) If Not WinWait("classname=Volume Control", "", 7500) Then MsgBox(0, "Error!", "Volume Control could not be opened! Exiting..") Exit EndIf $WindowHandle = WinGetHandle("classname=Volume Control") $ControlHandle1 = ControlGetHandle($WindowHandle, "", 1001) $ControlHandle2 = ControlGetHandle($WindowHandle, "", 2001) EndFuncI would gladly like to know if anyone knows a 'proper' fix to the non-update problem I described in the code. Edited May 15, 2007 by FreeFry
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now