[DllImport ("winmm. DLL ",
EntryPoint = "PlaySound ",
SetLastError = true,
CharSet = CharSet. Unicode,
ThrowOnUnmappableChar = true)]
Private static extern bool PlaySound (string szSound, System. IntPtr hMod,
PlaySoundFlags flags );
[System. Flags]
Public enum PlaySoundFlags: int
{
SND_SYNC = 0x0000, // synchronous playback sound. The PlaySound function is returned after playback.
SND_ASYNC = 0x0001, // play the sound asynchronously. The PlaySound function returns immediately after playing the video.
SND_NODEFAULT = 0x0002, // do not play the default sound. If this flag is not displayed, PlaySound will play the default sound when no sound is found.
SND_LOOP = 0x0008, // replaying sound, must be used with the SND_ASYNC flag
SND_NOSTOP = 0x0010, // PlaySound does not interrupt the original sound broadcast and returns FALSE immediately
SND_NOWAIT = 0x00002000, // if the driver is busy, the function does not play the sound and returns immediately
SND_FILENAME = 0x00020000, // The pszSound parameter specifies the WAVE file name.
SND_RESOURCE = 0x00040004 // The pszSound parameter is the identifier of the WAVE resource. In this case, the hmod parameter is used.
}
Public void runSound ()
{
PlaySound (@ "E: \ alarm sound \ ALARM1.WAV", IntPtr. Zero,
SND_ASYNC | SND_FileNAME | SND_LOOP );
}
Private void button#click (object sender, EventArgs e)
{
PlaySound (null, IntPtr. Zero, SND_ASYNC );
}
Private void button2_Click (object sender, EventArgs e)
{
New Thread (new ThreadStart (runSound). Start ();
}