2009-03-29 12 views
4

Wie kann ich die "Neue Mail" Sound-System in C# zu spielen? Dies wird auch als "Benachrichtigen" -Sound bezeichnet.Wie spiele ich den "New Mail" -System-Sound in .Net?

In Win32, das wäre so etwas wie

sndPlaySound('Notify', (SND_ALIAS or SND_ASYNC)); 

So wie tun Sie, dass in .net? Ich weiß, dass Sie

System.Media.SystemSounds.Asterisk.Play(); 

tun können, aber es ist eine sehr begrenzte Anzahl von fünf Tönen dort - ohne was auch immer die der Benutzer als neuen Mail-Ton gesetzt hat.

ich herausfinden kann, welche .wav wird Datei abgespielt wird, wenn ich neue E-Mails erhalten und diese Datei spielen, aber das wird nicht aktualisiert, wenn das Soundschema des Benutzers geändert wird.


Was ich tat schließlich:

Statt ein System Sound zu spielen, habe ich eine WAV-Datei in die Anwendung als Ressource eingebettet, und spielte sie mit System.Media.SoundPlayer

Antwort

5

Eine Option ist nur PInvoke direkt in die SndSound API. Hier ist die PInvoke-Definition für diese Methode

public partial class NativeMethods { 

    /// Return Type: BOOL->int 
    ///pszSound: LPCWSTR->WCHAR* 
    ///fuSound: UINT->unsigned int 
    [System.Runtime.InteropServices.DllImportAttribute("winmm.dll", EntryPoint="sndPlaySoundW")] 
    [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] 
public static extern bool sndPlaySoundW([System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] string pszSound, uint fuSound) ; 

    /// SND_APPLICATION -> 0x0080 
    public const int SND_APPLICATION = 128; 

    /// SND_ALIAS_START -> 0 
    public const int SND_ALIAS_START = 0; 

    /// SND_RESOURCE -> 0x00040004L 
    public const int SND_RESOURCE = 262148; 

    /// SND_FILENAME -> 0x00020000L 
    public const int SND_FILENAME = 131072; 

    /// SND_ALIAS_ID -> 0x00110000L 
    public const int SND_ALIAS_ID = 1114112; 

    /// SND_NOWAIT -> 0x00002000L 
    public const int SND_NOWAIT = 8192; 

    /// SND_NOSTOP -> 0x0010 
    public const int SND_NOSTOP = 16; 

    /// SND_MEMORY -> 0x0004 
    public const int SND_MEMORY = 4; 

    /// SND_PURGE -> 0x0040 
    public const int SND_PURGE = 64; 

    /// SND_ASYNC -> 0x0001 
    public const int SND_ASYNC = 1; 

    /// SND_ALIAS -> 0x00010000L 
    public const int SND_ALIAS = 65536; 

    /// SND_SYNC -> 0x0000 
    public const int SND_SYNC = 0; 

    /// SND_LOOP -> 0x0008 
    public const int SND_LOOP = 8; 

    /// SND_NODEFAULT -> 0x0002 
    public const int SND_NODEFAULT = 2; 
} 
3

Tatsächlich ist der neue E-Mail-Sound die "MailBeep" alias ist, nicht die "Notify" alias.

Sie möchten also PlaySound aufrufen (L "MailBeep", NULL, SND_SYSTEM | SND_NODEFAULT | SND_ALIAS);

Und P/Invoke ist auf jeden Fall die Möglichkeit, hier zu gehen.

Don't forget to specify SND_NODEFAULT or your app will make dings even if the user disables the new mail sound in the control panel.

SND_SYSTEM ist neu für Windows Vista und bewirkt, dass der Ton gespielt werden als „Windows Sound“ - es ist an Ihnen, wenn, dass die Erfahrung ist Sie haben wollen.

+0

Was ist der Wert von SND_SYSTEM? – Pedro77