Source Code
Geschrieben mit PureBasic
Lizenz: Public Domain / CC0
; ------------------------------------------------------------
;
; PureBasic - AudioSwitcher
;
; by wondr
;
; ------------------------------------------------------------
;
; Adds a shortcut icon to switch the Default-Sound-Device.on Windows
; Needs nircmdc.exe in same folder.
;
Global ButtonImage_0, ButtonImage_1, ButtonImage_2
Global Img_0, Img_1, Img_2
Procedure LoadConfig()
config.s = "audioswitcher.conf";
If ReadFile(0, config) ; if the file could be read, we continue...
Global Buttons.a = Val(ReadString(0))
Global DefaultDevice.a = Val(ReadString(0))
Global Dim Icons.s(Buttons)
Global Dim Device.s(Buttons)
For x = 0 To Buttons-1
Device(x) = ReadString(0)
Icons(x) = ReadString(0)
Next
CloseFile(0) ; close the previously opened file
Else
MessageRequester("Information","Kein Konfig-File gefunden!"+ Chr(10) + Chr(13) + Chr(10) + Chr(13) + "audioswitcher.conf"+ Chr(10) + Chr(13) + Chr(10) + Chr(13) + "1. Zeile: Zahl, Anzahl der Buttons"+ Chr(10) + Chr(13) + "2. Zeile: Zahl, Standardgerät"+ Chr(10) + Chr(13) + "3. Zeile: Gerätename"+ Chr(10) + Chr(13) + "4. Zeile: Icon-File .ico 64x64 Pixel"+ Chr(10) + Chr(13) + "...")
End
EndIf
EndProcedure
LoadConfig()
ExamineDesktops()
; Load Icons
Dim Imgg(Buttons)
For k=0 To Buttons-1
Imgg(k) = LoadImage(#PB_Any,Icons(k))
Next
; Setting the Default-Sound-Device
RunProgram("nircmdc.exe", "setdefaultsounddevice " + #DQUOTE$ + Device(DefaultDevice-1) + #DQUOTE$ + "","",#PB_Program_Hide )
width.l = 22+Buttons*89 ; Calculating the window-size
; Create the Window
If OpenWindow(0, (DesktopWidth(0)-width-20), (DesktopHeight(0)-180), width, 96, "AudioSwitcher", #PB_Window_SystemMenu | #PB_Window_Invisible)
; Create the Buttons
Dim ButtonImage(Buttons)
For k=0 To Buttons-1
ButtonImage(k) = ButtonImageGadget(#PB_Any, (10+k*90), 10, 88, 78, ImageID(Imgg(k)))
Next
; Create the SysTrayIcons
AddSysTrayIcon(1, WindowID(0), LoadImage(0, Icons(DefaultDevice-1)))
SysTrayIconToolTip(1, "AudioSwitcher 1.1")
; Event
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
For i = 0 To Buttons-1
If EventGadget() = ButtonImage(i)
RunProgram("nircmdc.exe", "setdefaultsounddevice " + #DQUOTE$ + Device(i) + #DQUOTE$ + "","",#PB_Program_Hide )
ChangeSysTrayIcon (1, LoadImage(1, Icons(i)))
StickyWindow(0, 0)
HideWindow(0,1)
Break ; Cancel
EndIf
Next
Case #PB_Event_SysTray
If EventType() = #PB_EventType_LeftClick
HideWindow(0, #False)
StickyWindow(0, 1)
EndIf
Case #PB_Event_CloseWindow
Result = MessageRequester("AudioSwitch","Wirklich beenden?",#PB_MessageRequester_YesNo)
If Result = #PB_MessageRequester_Yes
End
Else
StickyWindow(0, 0)
HideWindow(0, #True)
EndIf
EndSelect
Until 1=0
EndIf