Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Music in windows forms

I’m using Windows Forms application:
I have a ‘wax’ song-file and I want that when my form shows up the song will be playing.
Any idea how to do that?
thanks

bh
Monday, June 28, 2004

Right now you need Managed DirectX 9.0.  In .NET 2.0 you should be able to playe WAVs and the like without DirectX.

Chris Nahr
Tuesday, June 29, 2004

You can use PlaySound() from the winmm.dll.

[System.Runtime.InteropServices.DllImport("winmm.dll", EntryPoint="PlaySound", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern int PlaySound(String pszSound, int hmod, int flags);

private enum SND
{
                /// <summary>
    /// play synchronously (default)
    /// </summary>
    SND_SYNC            = 0x0000 ,
    /// <summary>
    ///  play asynchronously
    /// </summary>
    SND_ASYNC          = 0x0001 ,
    SND_NODEFAULT      = 0x0002 , /* silence (!default) if sound not found */
    SND_MEMORY          = 0x0004 , /* pszSound points to a memory file */
    SND_LOOP            = 0x0008 , /* loop the sound until next sndPlaySound */
    SND_NOSTOP          = 0x0010 , /* don't stop any currently playing sound */
    /// <summary>
    /// Don't wait if the driver is busy
    /// </summary>
    SND_NOWAIT    = 0x00002000, /* don't wait if the driver is busy */
    SND_ALIAS              = 0x00010000 ,/* name is a registry alias */
    SND_ALIAS_ID    = 0x00110000, /* alias is a pre d ID */
    SND_FILENAME    = 0x00020000, /* name is file name */
    SND_RESOURCE    = 0x00040004, /* name is resource name or atom */
    SND_PURGE          = 0x0040,  /* purge non-static events for task */
    SND_APPLICATION    = 0x0080  /* look for application specific association */
}


...
PlaySound(fileName, 0 ,(int) (SND.SND_ASYNC | SND.SND_FILENAME | SND.SND_NOWAIT));
...

John Lemberger
Tuesday, June 29, 2004

Oops.  Mis-read your original question, that's an 'x' not a 'v'.

(Joel, feel free to edit/remove.)

John Lemberger
Tuesday, June 29, 2004

any idea why cant i find winmm.dll?

bh
Thursday, July 01, 2004

It's just that easy.

WhoDoesntLikeMusic?
Wednesday, July 21, 2004

Why, that is stolen code.
You're in deep, deep shit, mister.
Have a good time in jail.
I know all about it, don't worry.
Ditto head.

Master of the universe
Thursday, August 12, 2004

hey microsloser:

System.object.form.boxoflosers.color=yellow.moron::onNiggerDataTransferWithNoDotOnHead(
whay.don't.you.just.keep.adding.usless.after.useles.object.
becuase.jimihendirx.told.you.to.I'm.the.only.one.who .sees.wht.ajoke.you.are.in.whtever.is.left.of.your.buisness.)

Master of the universe
Thursday, August 12, 2004

*  Recent Topics

*  Fog Creek Home