Introduction
I wanted to register my own and new sound events in shell (see Control Panel, Sounds) for my new application, and I found out there is no API for this. At least, I did not find it. So, I had to discover what should be modified in registry.
Using the code
The code is rather clear, and I used it with success. Works for Unicode too! The idea is that there exists a single class which creates valid entries in registry. Also, this class associates given entry with some unique identifier, and allows to play desired sound on event.
First, valid entries in registry must be created. TSystemSoundMgr::CreateEntriesInRegistry()
is used for this. Once registered, we should call TSystemSoundMgr::PlaySoundOnEvent(UINT)
and pass event identification.
This class will not play sounds by itself. So, it is up to the programmer to call PlaySoundOnEvent
method.
TSystemSoundMgr
uses also CRegistryTools
. Now I have to apologize, because for sure this class comes from CodeTools, and I do not remember who is the author. It is also probable that I have made some changes to this code (probably about Unicode compilation).
History
It is possible to write more objective code, by using for example map of ID to string, so that in TSystemSoundMgr
we would not have to switch by ID, but only search for ID in map. Also method implementation is not consistent, because in one place, I use CRegistryTools
, and in the second, I use RegistryAPI
directly. Anyway, this is the first version, and I am waiting for comments :)