QuietMessageBox

During the development of Drug Lord I ran across an annyoing feature of the Windows API MessageBox function; a noise is made whenever the message box pops up. While this is fine for normal alert-type messages, it is distracting when used frequently, such as occurs in the game. I was surprised to learn that there wasn't a flag that could be passed to the function that would shut off the beeping.

So, I decided to develop my own quiet version of MessageBox, and because I'm nice, I'm sharing this knowledge with everyone else. It's written in C, but can easily be converted to other languages.

What it does is temporarily assigns the event sound to be nothing. It then quietly pops up the MessageBox. After the user has dismissed the box, it restores the previous settings so that other applications won't be affected. There are a couple of gotchas here, however. First, if the message box is being displayed and the user manually changes the sound setting via the control panel or whatnot, the old sound will be restored when the box is dismissed. Second, if another application's message box pops up, it will also be quiet. I don't see either of these being too serious; they are both highly unlikely to occur, particularily the first. As for the second, it is doubtful the user would even notice the presence or absence of sound.

I suppose it would be possible to hook into the MessageBox function and restore the sound settings the moment the box was displayed, to ensure neither of the gotchas would occur, but I will leave that for someone else to do.