[Résolu] Jouer et Stopper le son dans un formulaire

Lone-wolf

XLDnaute Barbatruc
Bonjour à tous :)


J'ai une petite Api pour générer un son dans un formulaire, le problème c'est que je n'arrive pas à le stopper avec un boutton, contrairement au classeur(si cellule est vide).

Code:
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long


Dim Alarme As Boolean
Dim WavFile As String
Dim Son As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

 'Nom est une ComboBox
Private Sub Nom_Change()
On Error GoTo Fin
          Son = Me.Nom.Text       
   If Son = Me.Nom.Text Then
      WavFile = ThisWorkbook.Path & "\" & Son & ".wav"
Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
   Alarme = True
   Exit Sub
     Else
  Alarme = False
   End If
Fin:
Exit Sub


Merci d'avance.


A+ :cool:
 
Dernière édition:

Lone-wolf

XLDnaute Barbatruc
Re : Stopper le son dans un formulaire

Rebonjour,

j'ai trouvé, c'était simple mais il fallait y penser. Voici la solution.

Code:
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Dim Fichier, Son, WavFile As String

Private Sub Noms_Change()
Fichier = ThisWorkbook.Path & "\"
Son = Me.Nom.Text
WavFile = Fichier & Son & ".wav"

Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub
    
Private Sub CmdPlay_Click()
Fichier = ThisWorkbook.Path & "\"
Son = Me.Nom.Text
WavFile = Fichier & Son & ".wav"

Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub

Private Sub CmdOff_Click()
'ici fallait mettre &H1 
Call PlaySound(&H1, 0&, SND_ASYNC Or SND_FILENAME)
End Sub


Très bonne journée à tous :)


Lone-wolf :cool:
 

Discussions similaires

Statistiques des forums

Discussions
312 196
Messages
2 086 094
Membres
103 116
dernier inscrit
kutobi87