Click here to Skip to main content
6,635,160 members and growing! (15,750 online)
Email Password   helpLost your password?
General Reading » Hardware & System » General     Intermediate

SoundAlert

By Soundman32.2

Create your own sound alerts to be accessed from the Control Panel, and played by your own program.
VC6WinXP, Dev
Posted:16 May 2004
Views:24,420
Bookmarked:17 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
6 votes for this article.
Popularity: 3.70 Rating: 4.75 out of 5
1 vote, 16.7%
1

2

3

4
5 votes, 83.3%
5

SoundApplet Image

Introduction

Have you ever wondered how to add your own sound events to the Sounds section of the Control Panel? Of course, nothing is mentioned in the MSDN on how to do it - probably some undocumented API somewhere - so all the hard work discovering what to do had to be fathomed out empirically.

This article was inspired by another on CodeProject which outlines what needs to be done, but doesn't actually present any code.

The following addresses this problem and also provides a method of playing the sound events, which has proven problematic to some people.

Public Interface

The interface to this class is very simple, only providing 7 functions, but that's all you need :-)

As an example of the simplicity of this class, here is the test program I used whilst writing the class...

int main(int argc, char* argv[])
{
    CSoundAlert sa;

    sa.CreateGroup(_T("SoundApp"), _T("Sound Scheme Application"));

    sa.Create(_T("Start"), _T("Start Sound"), _T("%systemRoot%\\media\\ding.wav"));

    sa.Play(_T("Start"));

    sa.Delete(_T("Start"));

    sa.DeleteGroup();

    return 0;
}

This program creates a sound group, creates a single sound event, plays it, then deletes everything from the registry. Obviously, the deleting part should be done when uninstalling your application, but the creation should really be done when the program is run for the first time (for each user) as the registry settings are per user rather than system wide, and you don't want some people to miss out on the aural masterpiece your application will produce, do you.

Group Functions

bool CreateGroup(LPCTSTR szGroupName, LPCTSTR szTitle);
bool OpenGroup(LPCTSTR szGroupName);
bool DeleteGroup(LPCTSTR szGroupName);
bool DeleteGroup();

Alert Functions

bool Create(LPCTSTR szName, LPCTSTR szTitle, LPCTSTR szWavPath);
bool Delete(LPCTSTR szName);

Play sound function

bool Play(LPCTSTR szName, DWORD dwOptions=0);

Group Functions

A sound group is basically a place to store the sound alerts associated with your application. You can create as many groups as you like (but you also have to keep track of them !). To access a group, you need to either create it, or open it.

  • CreateGroup(LPCTSTR szGroupName, LPCTSTR szTitle)
    • szGroupName - the name to store your group under
    • szTitle - the text actually shown in the Control Panel. This allows the text to be internationalized without affecting the code.
  • OpenGroup(LPCTSTR szGroupName)
    • szGroupName - the name of the group to open.
  • DeleteGroup(LPCTSTR szGroupName)
    • szGroupName - the name of the group to delete. This doesn't need to be the current group.
  • DeleteGroup()

    Delete the current group.

Event functions

  • Create(LPCTSTR szName, LPCTSTR szTitle, LPCTSTR szWavPath)
    • szName - Name of the event
    • szTitle - Name of the event shown in the Control Panel
    • szWavPath - Path of the sound file to play. This can be a fully qualified path or just a filename (if the file is stored in the %systemRoot%\media directory, or specified using one of the environment variables (%windir%\my app)).
  • Delete(LPCTSTR szName)
    • szName - Name of the event to delete

Play Sound

  • Play(LPCTSTR szName, DWORD dwOptions=0)
    • szName - the name of the event to play
    • dwOptions - any of the standard PlaySound options

Conclusion

Hopefully, this article will allow you to add all important sound events to your otherwise quiet application - with a simple and effective class.

No MFC was harmed in the making of this class - and boy, was it hard not to :-)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Soundman32.2


Member

Occupation: Software Developer (Senior)
Location: United Kingdom United Kingdom

Other popular Hardware & System articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralYet ANOTHER Fix: DeleteGroup() doesn't work unless the group is already empty PinmemberJ Wofford9:20 28 Jan '05  
GeneralRe: Yet ANOTHER Fix: DeleteGroup() doesn't work unless the group is already empty PinmemberNeil_Scales9:55 28 Jan '05  
GeneralAnother Fix: Delete function doesn't delete anything PinmemberJ Wofford9:15 28 Jan '05  
GeneralAnother Fix: .exe name must match group name PinmemberJ Wofford9:01 28 Jan '05  
GeneralMinor fix in calls to RegSetValueEx() PinmemberUkkie91:33 1 Nov '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 May 2004
Editor: Smitha Vijayan
Copyright 2004 by Soundman32.2
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project