Private Declare PtrSafe Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Long
'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebeep
Private Declare PtrSafe Function MessageBeep& Lib "user32.dll" (ByVal dwFlags As Long)
Sub a()
PlaySound "C:\Windows\Media\Windows Critical Stop.wav", ByVal 0&, &H20001
End Sub
Sub b()
MessageBeep &HFFFFFFFF
'MessageBeep vbOK
'MessageBeep vbError
'MessageBeep vbCritical
'MessageBeep vbExclamation
'MessageBeep vbInformation
End Sub
Sub d()
Beep
End Sub
bonsoir
et bien d'autres possibilités encore
par exemple faire son propre beep composé
VB:
Declare PtrSafe Function ApiBeep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Sub jouerbeepperso() 'joue 4 notes differentes d'une durée de 50 millisecondes
ApiBeep 1000, 50: ApiBeep 800, 50: ApiBeep 500, 50: ApiBeep 200, 50
End Sub
ou bien jouer un des son window avec sapi.voice
Code:
Sub joueSonWindowSapiVoice()
Const wavFile = "C:\Windows\Media\Windows Exclamation.wav"
Dim oVoice: Set oVoice = CreateObject("SAPI.SpVoice")
Dim oSpFileStream: Set oSpFileStream = CreateObject("SAPI.SpFileStream")
oSpFileStream.Open wavFile
oVoice.SpeakStream oSpFileStream
oSpFileStream.Close
End Sub
Private Declare PtrSafe Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As LongPtr, ByVal dwFlags As Long) As Long
'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebeep
Private Declare PtrSafe Function MessageBeep& Lib "user32.dll" (ByVal dwFlags As Long)
Sub a()
PlaySound "C:\Windows\Media\Windows Critical Stop.wav", ByVal 0&, &H20001
End Sub
Sub b()
MessageBeep &HFFFFFFFF
'MessageBeep vbOK
'MessageBeep vbError
'MessageBeep vbCritical
'MessageBeep vbExclamation
'MessageBeep vbInformation
End Sub
Sub d()
Beep
End Sub