Advertisement
Guest User

Volume Changer

a guest
Sep 18th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Windows 8 inspired GDIP volume OSD
  2. ;   http://www.autohotkey.com/board/topic/94248-windows-8-inspired-gdip-volume-osd/
  3. ;Made by Rijul Ahuja
  4. ;       rijul13.wordpress.com
  5. ;Thanks to tic (Tariq Porter) for his GDI+ Library and rseding91 for making it all compatible
  6. ;   http://www.autohotkey.com/forum/viewtopic.php?t=32238
  7. ;Get the GDIP_all.ahk from here and place it in <location of Autohotkey.exe>\lib\GDIP.ahk
  8. ;   http://www.autohotkey.net/~Rseding91/Gdip%20All/Gdip_All.ahk
  9. ;Uncomment if GDIP.ahk is not in your library, put it in the script directory.
  10. ;#Include GDIP.ahk
  11. ;===========================Configuration=========================================
  12. #Include E:\AutoHotkey\Lib\GDIP.ahk
  13.  
  14. ;Leave any hotkey blank if you like
  15. VolUpHotkey:="!e"
  16. VolDownHotkey:="!q"
  17. VolMuteHotkey:="!w"
  18.  
  19. ;Position of OSD
  20. PosOSD:="BottomLeft"  ;TopLeft / TopRight / TopCenter / BottomLeft / BottomCenter / BottomRight
  21.                     ;case insensitive, Center can be written as centre
  22.  
  23. ;Change volume display font
  24. Font:="Arial"
  25.  
  26. ;Change colour of volume level (ARGB)
  27. VolColour:="0xFF00FF00"
  28.  
  29. ;Should OSD animate on leave? (experimental)
  30. AnimateWindow:=true
  31.  
  32. ;Set to true if OSD should not disappear when mouse is over it.
  33. ShouldMouse:=true
  34.  
  35. ;==========================Config complete========================================
  36. ;Do not edit anything below this unless you know what you are doing
  37.  
  38. #SingleInstance Force
  39. #NoEnv
  40. GetPos(PosOSD)
  41. SetWorkingDir, % A_ScriptDir
  42. SetHotkeys()
  43. If !pToken := Gdip_Startup()
  44. {
  45.     MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have GDI+ on your system.
  46.     ExitApp
  47. }
  48. If !Gdip_FontFamilyCreate(Font)
  49. {
  50.    MsgBox, 48, Font error!, The font you have specified does not exist on the system
  51.    ExitApp
  52. }
  53. Gui, VolOSD: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  54. Gui, VolOSD: Show, NA Center Hide, % SubStr(A_ScriptName,1,-4)
  55. OnExit, Exit
  56. OnMessage(0x201,"WM_LButtonDown")
  57. ;The smallest auto exec of my scripts is complete!
  58. return
  59.  
  60. WM_LButtonDown(wParam,lParam)
  61. {
  62.     X := lParam & 0xFFFF, Y := lParam >> 16
  63.     If ((X<19) or (X>29)) and (Y<15)
  64.         {}
  65.     else if (Y<115)
  66.         {
  67.         While(GetKeyState("LButton","P"))
  68.             {
  69.             MouseGetPos, , Y
  70.             Volume:=115-Y
  71.             SoundSet, % Volume
  72.             StartOSD()
  73.             }
  74.         }
  75.     else if (Y>=125) and (Y<=140) and (X>=18) and (X<=32)
  76.         {
  77.         SoundSet, +1, , Mute
  78.         StartOSD()
  79.         }
  80.     return 0
  81. }
  82.  
  83. SetHotkeys()
  84. {
  85.     global VolUpHotkey, VolDownHotkey, VolMuteHotkey
  86.     If VolUpHotkey
  87.         Hotkey, % VolUpHotkey, VolUpLabel
  88.     If VolDownHotkey
  89.         Hotkey, % VolDownHotkey, VolDownLabel
  90.     If VolMuteHotkey
  91.         Hotkey, % VolMuteHotkey, VolMuteLabel
  92.  
  93.     Hotkey, If, MouseIsOver("ahk_class Shell_TrayWnd")
  94.    
  95.     Hotkey, WheelUp, VolUpLabel
  96.     Hotkey, WheelDown, VolDownLabel
  97.     Hotkey, If
  98.    
  99.     Hotkey, $Volume_Up, VolUpLabel
  100.     Hotkey, $Volume_Down, VolDownLabel
  101.     Hotkey, $Volume_Mute, VolMuteLabel
  102. }
  103.  
  104. #If MouseIsOver("ahk_class Shell_TrayWnd")
  105. #If
  106.  
  107. Exit:
  108. Gdip_Shutdown(pToken)
  109. ExitApp
  110.  
  111. VolDownLabel:
  112. VolMuteLabel:
  113. VolUpLabel:
  114. ToSend:=(A_ThisLabel="VolDownLabel") ? "{Volume_Down}" : ( (A_ThisLabel="VolMuteLabel") ? "{Volume_Mute}" : "{Volume_Up}" )
  115. Send % ToSend
  116. StartOSD()
  117. VarSetCapacity(ToSend,0)
  118. return
  119.  
  120. StartOSD()
  121. {
  122.     SoundGet, Volume
  123.     SoundGet, Muted, Master, Mute
  124.     Muted:=(Muted="On") ? 1 : 0
  125.     MakeSlider(round(Volume),Muted)
  126.     SetTimer, KillVolOSD, -2500
  127. }
  128.  
  129. KillVolOSD:
  130. Gui, VolOSD:+Lastfound
  131. If ShouldMouse
  132. {
  133.     SetTimer, KillVolOSD, Off
  134.     MouseGetPos,,,hwndM
  135.     If (hwndM=WinExist())
  136.     {
  137.         SetTimer, KillVolOSD, 100
  138.         return
  139.     }
  140.     VarSetCapacity(hwndM,0)
  141. }
  142. If AnimateWindow
  143.     AnimateWindow(WinExist(),300,0x90000)
  144. Gui, VolOSD:+E0x80000
  145. Gui, VolOSD:Submit
  146. return
  147.  
  148. AnimateWindow(hWnd,Duration,Flag)
  149.     {
  150.     Return DllCall("AnimateWindow","UInt",hWnd,"Int",Duration,"UInt",Flag)
  151.     }
  152.  
  153. MakeSlider(Volume,Muted)
  154. {
  155.     static hwnd1
  156.     global XPos,YPos,Font,VolColour
  157.     If !hwnd1
  158.         {
  159.         Gui, VolOSD:+Lastfound
  160.         hwnd1:=WinExist()
  161.         }    
  162.     hbm := CreateDIBSection(50,150)
  163.     hdc := CreateCompatibleDC()
  164.     obm := SelectObject(hdc, hbm)
  165.     G := Gdip_GraphicsFromHDC(hdc)
  166.     Gdip_SetSmoothingMode(G, 4)
  167.     pBrush := Gdip_BrushCreateSolid(0xD2000000)          ;background part
  168.     Gdip_FillRectangle(G, pBrush, 0, 0, 50, 150)
  169.     Gdip_DeleteBrush(pBrush)
  170.     If !Muted
  171.         pBrush := Gdip_BrushCreateSolid(VolColour)      ;Volume Level
  172.     else
  173.         pBrush:=Gdip_BrushCreateSolid(0xFF808080)
  174.     Gdip_FillRectangle(G, pBrush, 19, 15, 10, 100)
  175.     Gdip_DeleteBrush(pBrush)
  176.     pBrush := Gdip_BrushCreateSolid(0xFF606060)            ;slider background colour
  177.     Gdip_FillRectangle(G, pBrush, 19, 15, 10, 100-Volume)
  178.     Gdip_DeleteBrush(pBrush)
  179.     If !Mutedq
  180.         pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
  181.     else
  182.         pBrush := Gdip_BrushCreateSolid(0xFFd3d3d3)
  183.     Gdip_FillRectangle(G,pBrush,19,110-(19*Volume)/20,10,5)
  184.     Gdip_DeleteBrush(pBrush)
  185.     If !Muted
  186.         GDIP_TextToGraphics(G,Volume,"x25 y125 cffffffff r4 s14 Center",Font)    ;volume text
  187.     else
  188.         GDIP_TextToGraphics(G,"X","x25 y125 cffffffff r4 s14 Bold Center",Font)    ;volume text
  189.     UpdateLayeredWindow(hwnd1, hdc, XPos, YPos,50,150)
  190.     Gui, VolOSD:Show, NA
  191.     SelectObject(hdc, obm)
  192.     DeleteObject(hbm)
  193.     DeleteDC(hdc)
  194.     Gdip_DeleteGraphics(G)
  195. }
  196.  
  197. MouseIsOver(WinTitle)
  198.     {
  199.         MouseGetPos,,, Win
  200.         return WinExist(WinTitle . " ahk_id " . Win)
  201.     }
  202.    
  203. GetPos(ByRef Var)
  204. {
  205.     Global XPos,YPos
  206.     Found:=false
  207.     HayStack:="topleft,topcenter,topright,bottomleft,bottomright,bottomcenter"
  208.     ;Ensure position is correct.
  209.     Loop, Parse, HayStack, `,
  210.         If (RegExMatch(Var,"i)" . A_LoopField)=1)
  211.         {
  212.             Found:=true
  213.             break
  214.         }
  215.     If !Found
  216.     {
  217.         MsgBox, 8208, % SubStr(A_ScriptName,1,-4), Error! Incorrect position of OSD.
  218.         ExitApp
  219.     }
  220.    
  221.     If Instr(Var,"Top")
  222.         YPos:=70
  223.     else
  224.         YPos:=A_ScreenHeight-455
  225.    
  226.     If InStr(Var,"Left")
  227.         XPos:=1930
  228.     else if InStr(Var,"Center") or InStr(Var,"Centre")
  229.         XPos:=(A_ScreenWidth/2)-55
  230.     else
  231.         XPos:=A_ScreenWidth-55
  232.     VarSetCapacity(Var,0)       ;free memory
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement