Play sound for a custom dialog box

  • Thread starter Dennis C. Drumm
  • Start date
D

Dennis C. Drumm

I have a windows form configured as a fixed dialog I'm using as a custom
MessageBox (has some additional buttons). How do I get it to play the
standard windows sounds when envoked and can I insert the standard
MessageBox icons into this dialog?

Thanks,

Dennis
 
G

Greg Ewing [MVP]

Dennis, in the Load event for your win form just play your sound of choice
using DirectX 9 or P/Invoke and the Win API. As for the icon, yes you can,
just set the icon for your form to the system icon. The system icons are
found in shell32.dll.
 
I

Ignacio Machin

HI Dennis,


Another tip, you can find in the registry under
HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\SystemAsterisk\.Current
which is the file currently being used by the system.

Hope this help,
 
W

William Ryan

Dennis:

This is from my post above, for some reason it didn't show up here before.
Anyway, you can definitely run this without CE.NET...it'll work on the
desktop. Just for reference, running it on ce.net is very similar, but you
need to use core.dll vs. winnm.dll I've used this on many times and a
modified version on PPC so it'll definitely run for you.


[DllIMport("winnm.dll")]
public static extern bool PlaySound(string pszSound, int hmod, fdwSound);

public const int SND_FILENAME = 0x00020000;
public const it SND_ASYNC = 0x0001;


Then to call it
PlaySound("WavFileYouWantToPlay.wav", 0 , SND_FILENAME| SND_ASYNC);

Let me know if you have any troubles.

Bill

Check out the PlaySound API. When the form loads or closes you can just
fire it with whatever sound you want.
BTW, I got this from .NET Framework Solutions, In Search of the Lost Win32
API by John Paul Meuller. He's got some pretty cool stuff in many different
areas, but rolling custom messageboxes is particularly cool. He shows you
how to add help menus to them and a lot of other neat tricks.


Good Luck,

Bill
 
D

Dennis C. Drumm

I now see that sndPlaySound is also supported for Platform SDK. So, the only
question that comes to mind now is how to use the flags in C#?

Thanks,

Dennis
 
I

Ignacio Machin

Hi Dennis,

You have to search the include files (.h) of the platform SDK and see what
those values are, I just did that and I found it on the file MMSystem.h

this is the declaration:

#define SND_SYNC 0x0000 /* play synchronously (default) */
#define SND_ASYNC 0x0001 /* play asynchronously */
#define SND_NODEFAULT 0x0002 /* silence (!default) if sound not found
*/
#define SND_MEMORY 0x0004 /* pszSound points to a memory file */
#define SND_LOOP 0x0008 /* loop the sound until next
sndPlaySound */
#define SND_NOSTOP 0x0010 /* don't stop any currently playing
sound */

You can define a enum in C# with these values:
public enum SndValues {

SND_SYNC = 0x0000 , /* play synchronously (default) */

SND_ASYNC = 0x0001 , /* play asynchronously */

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 */

}


Hope this help,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top