Joue un son spécifié par un nom de fichier, une ressource ou un événement système
#include <WinAPIMisc.au3>
_WinAPI_PlaySound ( $sSound [, $iFlags = $SND_SYSTEM_NOSTOP [, $hInstance = 0]] )
$sSound | La chaîne qui spécifie le son à jouer. La longueur maximale est de 255 caractères. Si $sSound est vide, toute forme d'onde sonore en cours de lecture est stoppée. |
$iFlags |
[optionnel] Les flags relatifs au son à jouer. Ce paramètre peut prendre une ou plusieurs des valeurs suivantes: $SND_APPLICATION $SND_ALIAS $SND_ALIAS_ID $SND_ASYNC $SND_FILENAME $SND_LOOP $SND_M EMORY $SND_NODEFAULT $SND_NOSTOP $SND_NOWAIT $SND_PURGE $SND_RESOURCE $SND_SYNC Windows Vista ou une version ultérieure $SND_SENTRY $SND_SYSTEM Les trois flags ($SND_ALIAS, $SND_FILENAME, et $SND_RESOURCE) détermine si le nom est interprété comme un alias pour un événement système, un nom de fichier, ou un identifiant de ressource. Si aucun de ces flags n'est spécifié, _WinAPI_PlaySound() recherche dans le registre ou dans le fichier Win.ini une association avec le nom du son spécifié. Si une association est trouvée, l'événement son est joué. Si aucune association se trouve dans le registre, le nom est interprété comme un nom de fichier. Si le flag $SND_ALIAS_ID est spécifié dans $iFlags, le paramètre $sSound doit avoir l'une des valeurs $SND_ALIAS_*. (Voir MSDN pour plus d'informations) |
$hInstance | [optionnel] Handle du fichier exécutable qui contient la ressource à charger. Si $iFlags ne contient pas $SND_RESOURCE, ce paramètre sera ignoré. |
Succès: | Retourne True |
Échec: | Retourne False |
Consultez PlaySound dans la librairie MSDN.
#include <APIMiscConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPIMisc.au3> Local Const $sWav = @ScriptDir & '\Extras\Airplane.wav' ; Copie Airplane.wav dans la mémoire Local $dWav = FileRead($sWav) If @error Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Erreur', 'Lecture impossible "'& $sWav & '"') Exit EndIf Local $tWav = DllStructCreate('byte['& BinaryLen($dWav) & ']') DllStructSetData($tWav, 1, $dWav) Local $pWav = DllStructGetPtr($tWav) ; Crée une GUI Local $hForm = GUICreate('Test '& StringReplace(@ScriptName, '.au3', '()'), 200, 200) Local $idButton = GUICtrlCreateButton('Play', 70, 70, 60, 60) GUISetState(@SW_SHOW) Local $bPlay = False, $iMsg = GUIGetMsg() While $iMsg <> $GUI_EVENT_CLOSE If $iMsg = $idButton Then $bPlay = Not $bPlay If $bPlay Then _WinAPI_PlaySound($pWav, BitOR($SND_ASYNC, $SND_LOOP, $SND_MEMORY)) GUICtrlSetData($idButton, 'Stop') Else _WinAPI_PlaySound('') GUICtrlSetData($idButton, 'Play') EndIf EndIf $iMsg = GUIGetMsg() WEnd