Use this class to expose all the sounds stored in a DLL's resource file through a simple interface. Using this strategy, you can update or replace your application's sounds by recompiling and redistributing this single DLL file, rather than the entire application. Option Explicit ' *** flag values for uFlags parameter *** ' play synchronously (default) Private Const SND_SYNC = &H0 ' play asynchronously Private Const SND_ASYNC = &H1 ' silence not default, if sound not found Private Const SND_NODEFAULT = &H2 ' name is a resource name or atom Private Const SND_RESOURCE = &H40004 ' loop the sound until next sndPlaySound Private Const SND_LOOP = &H8 ' don't stop any currently playing sound Private Const SND_NOSTOP = &H10 ' purge non-static events for task Private Const SND_PURGE = &H40 Private Declare Function PlaySound _ Lib "winmm.dll" Alias "PlaySoundA" _ (ByVal lpszName As String, _ ByVal hModule As Long, ByVal dwFlags _ As Long) As Long Private Declare Function PlaySoundData _ Lib "winmm.dll" Alias "PlaySoundA" _ (lpData As Any, ByVal hModule As Long, _ ByVal dwFlags As Long) As Long Public Enum ThemeSounds [SoundFirst] = 101 Asterisk = 101 Beep = 102 CriticalStop = 103 DefaultSound = 104 EmptyRecycleBin = 105 Exclamation = 106 ExitWindows = 107 Maximize = 108 MenuCommand = 109 MenuPopup = 110 Minimize = 111 ProgramError = 112 Question = 113 RestoreDown = 114 RestoreUp = 115 StartUp = 116 [SoundLast] = 116 End Enum Private Const defAsync As Boolean = True Private Const defRepeat As Boolean = False Private Const defYield As Boolean = False Private m_Async As Boolean Private m_Repeat As Boolean Private m_Yield As Boolean ' *********************************************** ' Initialization ' *********************************************** Private Sub Class_Initialize() m_Async = defAsync m_Repeat = defRepeat m_Yield = defYield End Sub ' *********************************************** ' Public Properties ' *********************************************** Public Property Let Async(ByVal NewVal As Boolean) m_Async = NewVal End Property Public Property Get Async() As Boolean Async = m_Async End Property Public Property Let Repeat(ByVal NewVal _ As Boolean) m_Repeat = NewVal End Property Public Property Get Repeat() As Boolean Repeat = m_Repeat End Property Public Property Let Yield(ByVal NewVal As Boolean) m_Yield = NewVal End Property Public Property Get Yield() As Boolean Yield = m_Yield End Property ' *********************************************** ' Public Methods ' *********************************************** Public Function PlayResource(ByVal SndID _ As ThemeSounds) As Boolean Dim Flags As Long Flags = SND_RESOURCE Or SND_NODEFAULT If m_Async Then Flags = Flags Or SND_ASYNC If m_Repeat Then Flags = Flags Or SND_LOOP If m_Yield Then Flags = Flags Or SND_NOSTOP PlayResource = PlaySound(CStr("#" & SndID), _ App.hInstance, Flags) End Function Public Function StopPlaying() As Boolean Const Flags As Long = SND_PURGE StopPlaying = PlaySound(vbNullString, _ App.hInstance, Flags) End FunctionHTH,
"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams