Funktionreferenz


_WinAPI_PlaySound


Plays a sound specified by the given file name, resource, or system event

#include <WinAPIMisc.au3>
_WinAPI_PlaySound ( $sSound [, $iFlags = $SND_SYSTEM_NOSTOP [, $hInstance = 0]] )

Parameter

$sSound The string that specifies the sound to play. The maximum length is 255 characters. If $sSound is
empty, any currently playing waveform sound is stopped.
$iFlags [optional] The flags for sound playing. This parameter can be one or more of the following values.
$SND_APPLICATION
$SND_ALIAS
$SND_ALIAS_ID
$SND_ASYNC
$SND_FILENAME
$SND_LOOP
$SND_MEMORY
$SND_NODEFAULT
$SND_NOSTOP
$SND_NOWAIT
$SND_PURGE
$SND_RESOURCE
$SND_SYNC

Windows Vista or later
$SND_SENTRY
$SND_SYSTEM

Three flags ($SND_ALIAS, $SND_FILENAME, and $SND_RESOURCE) determine whether the name is interpreted
as an alias for a system event, a file name, or a resource identifier. If none of these flags are
specified, _WinAPI_PlaySound() searches the registry or the WIN.INI file for an association with
the specified sound name. If an association is found, the sound event is played. If no association
is found in the registry, the name is interpreted as a file name.

If the $SND_ALIAS_ID flag is specified in $iFlags, the $sSound parameter must be one of the
$SND_ALIAS_* values.
(See MSDN for more information)
$hInstance [optional] Handle to the executable file that contains the resource to be loaded. If $iFlags does not
contain the $SND_RESOURCE, this parameter will be ignored.

Rückgabewert

Success: True
Failure: False

Bemerkungen

None.

Siehe auch

Suche nach PlaySound in der MSDN Bibliothek.

Beispiel

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIMisc.au3>

_Example()

Func _Example()
    Local Const $sWav = @ScriptDir & '\Extras\Airplane.wav'

    ; Read Airplane.wav to memory
    Local $dWav = FileRead($sWav)
    If @error Then
        MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Unable to read "' & $sWav & '"')
        Exit
    EndIf
    Local $tWav = DllStructCreate('byte[' & BinaryLen($dWav) & ']')
    DllStructSetData($tWav, 1, $dWav)
    Local $pWav = DllStructGetPtr($tWav)

    ; Create GUI
    Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 200, 200)
    #forceref $hForm
    Local $idButton = GUICtrlCreateButton('Play', 70, 70, 60, 60)
    GUISetState(@SW_SHOW)

    Local $bPlay = False
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idButton
                $bPlay = Not $bPlay
                If $bPlay Then
                    _WinAPI_PlaySound($pWav, BitOR($SND_ASYNC, $SND_LOOP, $SND_MEMORY))
;~                  _WinAPI_PlaySound($sWav, BitOR($SND_ASYNC, $SND_LOOP))
                    GUICtrlSetData($idButton, 'Stop')
                Else
                    _WinAPI_PlaySound('')
                    GUICtrlSetData($idButton, 'Play')
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_Example