Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Skinnable Volume Control OSD (WinXP / Win7)


  • Please log in to reply
5 replies to this topic
RedShadow
  • Members
  • 2 posts
  • Last active: Apr 16 2010 12:59 PM
  • Joined: 27 Jan 2008
Hello you guys

It is like the thousands of volume controls you can find on the forums...
Except that this one is fully compatible from Win XP to Win 7, that this one has skins support, and is awesome XD.
It even has OSD animations (like fade in/out slide from left to right and stuffs) and all the configuration is made with INI files.

This script is using:
- Vista Audio Control
- COM Standard Library
- Autohotkey_L

How to use:
Use the following hotkeys to chage the master volume:
Increase the volume:
- WinKey + UpKey
- Mouse5 + WheelUp
- VolumelUp (available on some keyboards and laptops)

Decrease the volume:
- WinKey + DownKey
- Mouse5 + WheelDown
- VolumelDown (available on some keyboards and laptops)

Video:


Code:
;/**
; * VolumeOSD 1.0.0.1
; * A volume control OSD, with skins support, and GUI animations.
; *
; * By RedShadow 2010, use this script as you wish.
; */
#NoEnv
#SingleInstance Force
#include %A_ScriptDir%\lib\COM.ahk
#include %A_ScriptDir%\lib\VA.ahk
SetBatchLines, -1
OnExit, &Exit
COM_Init()


;/**
; * Default values
; */
DEFAULT_VOLUME_STEP 					:= 2						; The percentage by which to raise or lower the volume each time
DEFAULT_VOLUME_DISPLAY_TIME 			:= 1000						; How long to display the volume level bar graphs (in milliseconds)
DEFAULT_SKIN_NAME 						:= "default"				; name of the default skin
GCL_STYLE 								:= -26
CS_DROPSHADOW  							:= &H20000


;/**
; * Core
; */
SplitPath, A_ScriptFullPath, , , , IniPath
IniPath 			:= A_ScriptDir . "\" . IniPath	.	".ini"
xp 					:= IsWinXPOrBelow()
vol_LastMute 		:= -1
vol_Master 			:= Round( getMasterVolume() )
Gosub, ReadIni
Gosub, ReadSkinInfos
Gosub, CreateTray
Gosub, CreateGUI
Return



;// ================================================[ HOTKEYS ]================================================


;/**
; * Hotkeys that are gonna decrease the volume
; */
$Volume_down::
#Down::
~XButton2 & WheelDown::
	Gosub, DecreaseVolume
	Gosub, UpdateGUI
Return


;/**
; * Hotkeys that are gonna increase the volume
; */
$Volume_up::
#Up::
~XButton2 & WheelUp::
	Gosub, IncreaseVolume
	Gosub, UpdateGUI
Return



;// ================================================[ SUBS ]================================================


;/**
; * Increases the master volume
; */
IncreaseVolume:
	; Get volumes in case the user or an external program changed them:
	vol_Master := Round( getMasterVolume() )
	
	if (vol_Master < 100)
	{
		setMasterVolume(vol_Master+=vol_Step)
		if (vol_Master >= 0)
			if (vol_LastMute)
				setMasterMute(False)
	}
Return


;/**
; * Decreases the master volume
; */
DecreaseVolume:
	; Get volumes in case the user or an external program changed them:
	vol_Master := Round( getMasterVolume() )
	
	if (vol_Master > 0)
	{
		setMasterVolume(vol_Master-=vol_Step)
		if (vol_Master <= 0)
			if (!vol_LastMute)
				setMasterMute(True)
	}
Return


;/**
; * Moves the GUI
; */
MoveGUI:
	PostMessage, 0xA1, 2, , , A
Return


;/**
; * Updates the progress bar and text
; */
UpdateGUI:
	vol_Mute := getMasterMute()
	
	if (vol_Mute != vol_LastMute)
	{
		if (vol_Mute)
			vol_Text := textMuted
		else
			vol_Text := text
		
		GuiControl, , MyText, %vol_Text%
		vol_LastMute := vol_Mute
	}
	
	;// Update text
	GuiControl,, MyProgress, %vol_Master%
	
	;// Progress bar borders ?
	if (!barBorder)
		Control ExStyle, -0x20000, , ahk_id %MyProgressHwnd%
	
	;// Animation
	if (showAnimation)
		AnimateWindow(guiID, durationAnimation, showAnimation)
	
	Gui, 1:+LastFound
	Gui, 1:Show, NoActivate Center
	SetTimer, HideGUI, %vol_DisplayTime%
Return


;/**
; * Hides the GUI
; */
HideGUI:
	SetTimer, HideGUI, Off
	
	;// Animation
	if (hideAnimation)
		AnimateWindow(guiID, durationAnimation, hideAnimation)
	
	Gui, 1:Cancel	; Probably faster than Hide
Return


;/**
; * Creates the Tray menu and stuffs
; */
CreateTray:
	;// Add the available skins
	Loop, %A_ScriptDir%\skin\*, 2, 0
	{
		Menu, SkinSubMenu, Add, %A_LoopFileName%, SkinSelected
	}
	Menu, SkinSubMenu, Check, %skinName%
	
	;// Tray stuffs
	Menu, Tray, NoStandard
	Menu, Tray, Add, &Skins, :SkinSubMenu
	Menu, Tray, Add
	Menu, Tray, Add, &Exit
	Menu, Tray, Tip, Volume OSD
Return

	
	
;/**
; * Create the GUI window
; */
CreateGUI:
	;// Add the picture
	Gui, 1:+LastFound +AlwaysOnTop +Disabled -Caption -Border +Owner
	Gui, 1:Margin, 0, 0
	Gui, 1:Add, Picture, x0 y0 -Border, %bgImage%
	guiID := WinExist()
	
	;// Add the window shadow
	if (useShadow)
		DllCall("SetClassLong", "uint", guiID, "int", GCL_STYLE, "int", DllCall("GetClassLong", "uint", guiID, "int", GCL_STYLE) | CS_DROPSHADOW)
	
	;// Add components
	Gui, 1:Hide
	Gui, 1:Font, s%fontSize% c%fontColor% %fontStyle%, %fontName%
	Gui, 1:Add, Text, vMyText wp x0 y%textY% Center BackgroundTrans, %text%
	Gui, 1:Add, Progress, vMyProgress HwndMyProgressHwnd x%barX% y%barY% wp-%barMarginRight% h%vol_Thick% c%vol_barColour% Background%vol_barBGColour% -E0x200, %vol_Master% 
	
	;// Progress bar borders ?
	if (!barBorder)
		Control ExStyle, -0x20000, , ahk_id %MyProgressHwnd%
	
	Gui, 1:Show, Hide Center
	WinSet, Transparent, %vol_TransValue%, ahk_id %guiID%
Return


;/**
; * Skin sub-menu inside the tray menu
; */
SkinSelected:
	Menu, SkinSubMenu, UnCheck, %skinName%
	skinName := A_ThisMenuItem
	Menu, SkinSubMenu, Check, %skinName%
	GoSub, ReadSkinInfos
	Gosub, DestroyGUI
	Gosub, CreateGUI
	
	;// Update INI
	GoSub, WriteIni
Return


;/**
; * Destroy the GUI
; */
DestroyGUI:
	Gui, 1:Destroy
Return


;/**
; * Read the INI file.
; * If the file doesn't exist it will create it with default values.
; * If some keys are missings, they'll be replaced by default values too.
; */
ReadIni:
	; [Volume]
	IniRead, vol_Step, %IniPath%, Volume, Step, *
	if vol_Step = *
		vol_Step	:=	DEFAULT_VOLUME_STEP
	
	IniRead, vol_DisplayTime, %IniPath%, Volume, DisplayTime, *
	if vol_DisplayTime = *
		vol_DisplayTime	:=	DEFAULT_VOLUME_DISPLAY_TIME
	
	; [Skin]
	IniRead, skinName, %IniPath%, Skin, Name, *
	if skinName = *
		skinName	:=	DEFAULT_SKIN_NAME
		
	Gosub, WriteIni
Return


;/**
; * Write the INI file.
; * Takes the current values and writes them.
; */
WriteIni:
	; [Volume]
	IniWrite, %vol_Step%, %IniPath%, Volume, Step
	IniWrite, %vol_DisplayTime%, %IniPath%, Volume, DisplayTime
	
	; [Skin]
	IniWrite, %skinName%, %IniPath%, Skin, Name
Return


;/**
; * Read the skin INI file.
; */
ReadSkinInfos:
	IniSkinPath := A_ScriptDir . "\skin\" . skinName . "\skin.ini"
	IfNotExist, %IniSkinPath%
	{
		MsgBox, 16, Skin not found!, Skin not found:`n%IniSkinPath%
		ExitApp, 1
	}
	
	; [Panel]
	IniRead, bgImage, %IniSkinPath%, Panel, Image, *
	bgImage := A_ScriptDir . "\skin\" . skinName . "\" . bgImage
	IfNotExist, %bgImage%
	{
		MsgBox, 16, Skin image not found!, Image not found:`n%bgImage%
		ExitApp, 2
	}
	IniRead, useShadow, %IniSkinPath%, Panel, WindowShadow, *
	IniRead, vol_TransValue, %IniSkinPath%, Panel, Opacity, *
	
	; [Text]
	IniRead, text, %IniSkinPath%, Text, Text, *
	IniRead, textMuted, %IniSkinPath%, Text, TextMuted, *
	IniRead, fontName, %IniSkinPath%, Text, TextFont, *
	IniRead, fontStyle, %IniSkinPath%, Text, TextStyle, *
	IniRead, fontSize, %IniSkinPath%, Text, TextSize, *
	IniRead, fontColor, %IniSkinPath%, Text, TextColor, *
	IniRead, textY, %IniSkinPath%, Text, MarginY, *

	; [Bar]
	IniRead, vol_barColour, %IniSkinPath%, Bar, Color, *
	IniRead, vol_barBGColour, %IniSkinPath%, Bar, BGColor, *
	IniRead, barX, %IniSkinPath%, Bar, MarginX
	IniRead, barY, %IniSkinPath%, Bar, MarginY
	IniRead, vol_Thick, %IniSkinPath%, Bar, Height
	IniRead, barBorder, %IniSkinPath%, Bar, Border
	
	; [Animation]
	IniRead, showAnimation, %IniSkinPath%, Animation, Show, *
	IniRead, hideAnimation, %IniSkinPath%, Animation, Hide, *
	IniRead, durationAnimation, %IniSkinPath%, Animation, Duration, *
	
	; [Misc]
	IniRead, opacityFix, %IniSkinPath%, Misc, OpacityFix, *
	
	if (opacityFix)
		DetectHiddenWindows, On
	else
		DetectHiddenWindows, Off
		
	barMarginRight := 2*barX
Return


;/**
; * Quit
; */
&Exit:
	GoSub, DestroyGUI
	ExitApp, 0
Return


;// ================================================[ FUNCTIONS ]================================================


;/**
; * Returns the master volume
; */
getMasterVolume() {
	Global xp
	if (xp)
		SoundGet, volume
	else
		volume := VA_GetMasterVolume()
	return volume
}


;/**
; * Sets the master volume
; */
setMasterVolume(value) {
	Global xp
	if (xp)
		SoundSet %value%
	else {
		;VA_SetMasterVolume(value)
		;Doesn't seem to work correcty.
		;The balance is screwed up when I am on around 9 and want to go to 15.
		;When I put 11, it does increase on the left but not on the right.
		;There seems to be a shift around the 9 value.
		
		VA_SetMasterVolume(value, 1) ; increse on the left
		VA_SetMasterVolume(value, 2) ; increse on the right
	}
}


;/**
; * Returns True if the master volume is muted
; */
getMasterMute() {
	Global xp
	if (xp)
	{
		SoundGet, mute, Master, Mute
		if mute=On
			mute := 1
		else
			mute := 0
	}
	else {
		mute := VA_GetMasterMute()
	}
	return mute
}


;/**
; * Set wheter the master volume is muted or not
; */
setMasterMute(state) {
	Global xp
	if (xp)
	{
		if (!getMasterMute() && state)
			SoundSet, -1,, mute
		else if (getMasterMute() && !state)
			SoundSet, -1,, mute
	}
	else {
		VA_SetMute(state)
	}
	
	;// I dunno exactly, if I dont do that, 
	;// sometimes when I increase the volume from 0 (muted)
	;// to something higher (unmuted) the text still says that its muted.
	;// But thats freaking wrong since the volume is > 0 so it is unmuted.
	;// This seems to make the text refresh and probably prevents
	;// that kinda graphical glitch.
	;Sleep, 1
}


;/**
; * If the OS is Windows XP or below it will return True
; */
IsWinXPOrBelow() {
	If A_OSVersion in WIN_2003,WIN_XP,WIN_2000,WIN_NT4,WIN_95,WIN_98,WIN_ME
		Return 1
	Return 0
}


;/**
; * http://www.autohotkey.com/forum/viewtopic.php?p=65596#65596
; */
AnimateWindow(hWnd, Duration, Flag) {
	Return DllCall("AnimateWindow", "UInt", hWnd, "Int", Duration, "Int", Flag) 
}

Download: (src + bin)
https://ahknet.autoh...lumeOSD_1001.7z

More details here:
https://ahknet.autoh...adow/VolumeOSD/

Enjoy :D

Bigrob55
  • Members
  • 41 posts
  • Last active: Sep 27 2013 06:42 PM
  • Joined: 24 Sep 2007
Oooooh This is PERDY! :-D

Awesome job!!!

codybear
  • Members
  • 600 posts
  • Last active: Feb 09 2015 12:41 PM
  • Joined: 15 Sep 2009
This is nice. thanks for sharing.

giant
  • Members
  • 5 posts
  • Last active: May 14 2014 09:54 AM
  • Joined: 19 Feb 2011
Hey RedShadow,

It is a brilliant script!!!!

Thanks for your sharing.

Best :D

kireta
  • Members
  • 25 posts
  • Last active: Oct 11 2015 02:53 PM
  • Joined: 01 Jan 2007
I echo last comment, this is a great solution that runs on XP and Win 7

Ability to modify script, as explained in link in original post is also wonderful.

Kudos.....

Bob1nz
  • Members
  • 1 posts
  • Last active: Apr 17 2011 12:34 PM
  • Joined: 15 Apr 2011
Fantastic just what I'm looking for

Is there a way to change the position on the screen?
I'm looking to use this instead of Media Portals default one and would like to have it up in the top right of the screen (similar to windows 7 media center)

I have spent hours looking around trying to figure out how to do it but as I'm not that flash at programming or scripting I haven't been able to figure it out.