Jump to content

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

Vista Volume control OSD


  • Please log in to reply
4 replies to this topic
hjbotha
  • Members
  • 4 posts
  • Last active: Dec 09 2013 05:36 PM
  • Joined: 04 Apr 2008
Hi guys,

Thanks (really - thank you!) to Lexikos' Vista Audio Control functions @ <!-- m -->http://www.autohotke...topic23792.html<!-- m --> I've managed to adapt Volume On-Screen-Display (OSD) by Rajat for Vista.

I have just a few questions to try and refine it. Here's my code:

; Make customisation only in this area or hotkey area only!! 

; The percentage by which to raise or lower the volume each time:
vol_Step = 4

; How long to display the volume level bar graphs:
vol_DisplayTime = 2000

; Master Volume Bar color (see the help file to use more
; precise shades):
vol_CBM = Lime

; Background color; for transparent, set to 111111
vol_CW = 111111

; Bar's screen position.  Use -1 to center the bar in that dimension:
vol_PosX = -1
vol_PosY = 600
vol_Width = 1024  ; width of bar
vol_Thick = 50   ; thickness of bar

; If your keyboard has multimedia buttons for Volume, you can
; try changing the below hotkeys to use them by specifying
; Volume_Up, ^Volume_Up, Volume_Down, and ^Volume_Down:
HotKey, Volume_Up, vol_MasterUp
HotKey, Volume_Down, vol_MasterDown


;___________________________________________ 
;_____Auto Execute Section__________________ 

; DON'T CHANGE ANYTHING HERE (unless you know what you're doing).

COM_Init()

vol_BarOptionsMaster = 1 ZH%vol_Thick% ZX0 ZY0 W%vol_Width% CB%vol_CBM% CW%vol_CW%
;vol_BarOptionsMaster = 1 ZH%vol_Thick% ZX0 ZY0 W%vol_Width%

; If the X position has been specified, add it to the options.
; Otherwise, omit it to center the bar horizontally:
if vol_PosX >= 0
{
    vol_BarOptionsMaster = %vol_BarOptionsMaster% X%vol_PosX%
}

; If the Y position has been specified, add it to the options.
; Otherwise, omit it to have it calculated later:
if vol_PosY >= 0
{
    vol_BarOptionsMaster = %vol_BarOptionsMaster% Y%vol_PosY%
}

#SingleInstance
SetBatchLines, 10ms
Return


;___________________________________________ 

vol_MasterUp:
vol_tmp := VA_GetMasterVolume()
vol_Master := (vol_tmp + vol_Step)
VA_SetMasterVolume(vol_Master)
Gosub, vol_ShowBars
return

vol_MasterDown:
vol_tmp := VA_GetMasterVolume()
vol_Master := (vol_tmp - vol_Step)
VA_SetMasterVolume(vol_Master)
Gosub, vol_ShowBars
return

vol_ShowBars:
; To prevent the "flashing" effect, only create the bar window if it
; doesn't already exist:
IfWinNotExist, vol_Progress
{
    ; Calculate position here in case screen resolution changes while
    ; the script is running:
         Progress, %vol_BarOptionsMaster%, , , vol_Progress
         WinSet, TransColor, 111111, vol_Progress
;         WinSetTitle, vol_Progress,,Volume
;         WinSet, Style, -0xC00000, vol_Progress
}
; Get the volume in case the user or an external program changed them:
Progress, 1:%vol_Master%
SetTimer, vol_BarOff, %vol_DisplayTime%
return

vol_BarOff:
SetTimer, vol_BarOff, off
Progress, 1:Off
return

My questions concern the following bits:

vol_BarOptionsMaster = 1 ZH%vol_Thick% ZX0 ZY0 W%vol_Width% CB%vol_CBM% CW%vol_CW%
;vol_BarOptionsMaster = 1 ZH%vol_Thick% ZX0 ZY0 W%vol_Width%

Here I have removed the colour settings for the bar and the background so that Vista will display the progress bar in its own style. It works, but Vista insists on making the bar move slowly, which means that it lags slightly behind where the volume level is actually at.

Is there a way of getting rid of the lag that anybody knows about?

;         WinSetTitle, vol_Progress,,Volume
;         WinSet, Style, -0xC00000, vol_Progress

I'd like to do one or both of these.

I like the border that appears around a regular window, but I want the title bar to either say "Volume" or not be there at all.

Currently when I disable the title bar most of the border disappears as well. I'm familiar with the B2 option for progress, but I want the proper Vista glass border.

If I change the window title from vol_Progress to Volume, I have to change it everywhere, and Volume ends up not being very unique - for example, things break if the windows Volume Mixer is open.

Is there,
a) an alternative way to reference the window, or
B) A way to change the displayed window title but leave the reference intact?

Thanks guys!

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

It works, but Vista insists on making the bar move slowly,

It seems to be a feature of progress bars in Vista: the progress bar smooths out change rather than snapping to the current value.

Try this:
; In the configuration section:
vol_Title = Volume

; In the auto-execute section:
Process, Exist
vol_Window = %vol_Title% ahk_class AutoHotkey2 ahk_pid %ErrorLevel%

; Replace vol_ShowBars with:
vol_ShowBars:
IfWinNotExist, %vol_Window%
{
    Progress, %vol_BarOptionsMaster% P%vol_Master%, , , %vol_Title%
    WinExist(vol_Window) ; Set Last Found Window.
    WinSet, Style, -0xC00000 ; -WS_CAPTION
    WinSet, Style, +0x40000 ; +WS_THICKFRAME
    ; Get window info, including the size of the window border.
    VarSetCapacity(wi, 60), NumPut(60, wi)
    DllCall("GetWindowInfo","uint",WinExist(),"uint",&wi)
    ; Size the window to the progress bar + the height of the top and bottom border.
    WinMove,,,,, vol_Width, vol_Thick + NumGet(wi,52)*2
}
Progress, 1:100 ; This seems to remove the lag except when vol_Master=100.
Progress, 1:%vol_Master%
SetTimer, vol_BarOff, %vol_DisplayTime%
return
Strangely, if the progress window is shown when vol_Master=100, it starts out empty and animates back up to 100.

hjbotha
  • Members
  • 4 posts
  • Last active: Dec 09 2013 05:36 PM
  • Joined: 04 Apr 2008
Thanks for that, the window is perfect now. When I disabled the title using -WS_CAPTION I ended up with a space below the progress bar, so instead I set vol_BarOptionsMaster to B for no title/border, then apply the thick border using +WS_THICKFRAME.

Strangely, if the progress window is shown when vol_Master=100, it starts out empty and animates back up to 100.


Yeah, it would, cos when it gets set to a lower value it snaps to it, even if it's not yet reached the value it was going for. When you specify 100, it doesn't have anything to snap back to.

I tried making it snap to 100, 99 and then the vol_Master, but that's even more inconsistent.

I'm looking now into using a meter, as at <!-- m -->http://msdn2.microso... ... us,MSDN.10<!-- m -->).png
But I'm having trouble finding how to implement it and I'm not even sure it won't fill in the same way.

Will post back here if I find something.

hjbotha
  • Members
  • 4 posts
  • Last active: Dec 09 2013 05:36 PM
  • Joined: 04 Apr 2008
Well I haven't made any progress with figuring out how to make the meters out of progress bars, but I've started experimenting with using a slider instead of a progress bar. But it doesn't work and I can't figure out why.

; Make customisation only in this area or hotkey area only!! 

vol_Title = Volume

; The percentage by which to raise or lower the volume each time:
vol_Step = 5

; How long to display the volume level bar graphs:
vol_DisplayTime = 2000

; Master Volume Bar color (see the help file to use more
; precise shades):
vol_CBM = Lime

; Background color; for transparent, set to 111111
vol_CW = 111111

; Bar's screen position.  Use -1 to center the bar in that dimension:
vol_PosX = -1
vol_PosY = 600
vol_Width = 300  ; width of bar
vol_Thick = 32   ; thickness of bar

; If your keyboard has multimedia buttons for Volume, you can
; try changing the below hotkeys to use them by specifying
; Volume_Up, ^Volume_Up, Volume_Down, and ^Volume_Down:
HotKey, Volume_Up, vol_MasterUp
HotKey, Volume_Down, vol_MasterDown


;___________________________________________ 
;_____Auto Execute Section__________________ 

; DON'T CHANGE ANYTHING HERE (unless you know what you're doing).

COM_Init()

Process, Exist
vol_Window = %vol_Title% ahk_class AutoHotkey2 ahk_pid %ErrorLevel%

;vol_BarOptionsMaster = 1:B ZH%vol_Thick% ZX0 ZY0 W%vol_Width% CB%vol_CBM% CW%vol_CW%
vol_BarOptionsMaster = 1:B Vertical ZH%vol_Thick% ZX0 ZY0 W%vol_Width%

; If the X position has been specified, add it to the options.
; Otherwise, omit it to center the bar horizontally:
if vol_PosX >= 0
{
    vol_BarOptionsMaster = %vol_BarOptionsMaster% X%vol_PosX%
}

; If the Y position has been specified, add it to the options.
; Otherwise, omit it to have it calculated later:
if vol_PosY >= 0
{
    vol_BarOptionsMaster = %vol_BarOptionsMaster% Y%vol_PosY%
}

#SingleInstance
SetBatchLines, 10ms
Return


;___________________________________________ 

vol_MasterUp:
vol_tmp := VA_GetMasterVolume()
vol_tmp := (vol_tmp + vol_Step)
Transform, vol_Master, Round, %vol_tmp%
if vol_Master > 100
{
  vol_Master = 100
}
VA_SetMasterVolume(vol_Master)
Gosub, vol_ShowBars
return

vol_MasterDown:
vol_tmp := VA_GetMasterVolume()
vol_tmp := (vol_tmp - vol_Step)
Transform, vol_Master, Round, %vol_tmp%
if vol_Master < 0.1
{
  vol_Master = 0
  VA_SetMasterVolume(0.01)
}
else
  VA_SetMasterVolume(vol_Master)
Gosub, vol_ShowBars
return

vol_ShowBars:
IfWinNotExist, %vol_Window%
{
    Progress, %vol_BarOptionsMaster% P%vol_Master%, , , %vol_Title%
    WinExist(vol_Window) ; Set Last Found Window.
    Gui, Add, Slider, vol_Slider, 50
    WinSet, Style, +0x40000 ; +WS_THICKFRAME
    WinSet, TransColor, 111111
}
Progress, 1:%vol_Master%
SetTimer, vol_BarOff, %vol_DisplayTime%
return

vol_BarOff:
SetTimer, vol_BarOff, off
WinExist(vol_Window)
WinClose,,
Progress, 1:Off
return

As far as I can tell,
Gui, Add, Slider, vol_Slider, 50
should create a window and put the slider inside it, but nothing seems to happen. However, I suspect it's getting created but not in %vol_Window%, because when %vol_Window% gets closed and relaunched, I get an error saying %vol_Slider% already exists.

I can't find any examples of Add, Slider being used just on its own, so can someone tell me what I'm missing?

Thanks

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
"Gui, Add" adds a control to a GUI. The GUI is not shown until you use "Gui, Show".