Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there a way to suppress default sounds when displaying a message box?

264 views
Skip to first unread message

john

unread,
Aug 5, 1999, 3:00:00 AM8/5/99
to
Hello,
I'm wondering if it's possible to display a message box,
without the dings and other sounds?

For example, this code always generates a 'ding':

MessageBox (hwnd, TEXT ("Wrong button"), TEXT ("Message"), MB_OK);

I've looked through the documentation for MessageBox, and it doesn't
discuss default sounds.

Thanks,

John

Thomas W. Brown

unread,
Aug 5, 1999, 3:00:00 AM8/5/99
to

It shouldn't at all, not at the API level!!! The MessageBeep(UINT type)
is responsible for making the sound. Making a MessageBox(...) call
without a previous MessageBeep() should result in a soundless message
box! I've done it all the time.

Perhaps you are using some "convenience" routine that is doing both a
MessageBeep and MessageBox?

-- Thomas Brown
tbr...@softbook.com

Matt A.

unread,
Aug 5, 1999, 3:00:00 AM8/5/99
to
Thomas W. Brown wrote in message <37AA0AE1...@softbook.com>...

>john wrote:
>>
>> Hello,
>> I'm wondering if it's possible to display a message box,
>> without the dings and other sounds?
>>
>> For example, this code always generates a 'ding':
>>
>> MessageBox (hwnd, TEXT ("Wrong button"), TEXT ("Message"), MB_OK);
>>
>> I've looked through the documentation for MessageBox, and it doesn't
>> discuss default sounds.

AFAIK, you can't turn off the sounds made by MessageBox() via a "simple"
API call.

One somewhat "complex" method I can think of, however, to possibly
accomplish this is to to temporarily alter the current Control Panel "sound
scheme" so that the "Asterisk" (MB_ICONINFORMATION), "Critical Stop"
(MB_ICONSTOP), "Exclamation" (MB_ICONEXCLAMATION), "Question"
(MB_ICONQUESTION) and "Deafult Sound" settings are disabled or invalid.
Then, you can call MessageBox(), after which you of course restore the old
settings. In fact it may be possible to effectively to this in one step by
simply switching to an empty or invalid scheme.

You can alter sound scheme settings programmatically by modifying entries
in the registry. However, I believe the format of the scheme entries
created by the "Sounds" Control Panel is not undocumented. So, if you
really want to take this approach, be forewarned that it might break in
future versions of Windows. You may be interested to know that there was a
"Windows Developer's Journal" article all about the sound scheme registry
entries a few months back -- it should give you all the information you'll
need (applicable to the *current* versions of Windows). Sorry, I can't
remember which issue.

Note that MessageBox() will *still* make a "blip" though the PC speaker
when no sound scheme setting is available. You can temporarily disable
this using SystemParametersInfo(SPI_SETBEEP).

>>
>
>It shouldn't at all, not at the API level!!!

It should, and does.

Which implementaiton of the Windows API are you referring to?

>The MessageBeep(UINT type)
>is responsible for making the sound. Making a MessageBox(...) call
>without a previous MessageBeep() should result in a soundless message
>box! I've done it all the time.

I admit I don't know about NT's MessageBox() behavior, but *just* calling
the plain MessageBox() API function indeed makes a sound *all by itself* on
Windows 95 and 98. MessageBox() even chooses the sound based on which
MB_ICONxxx flag you pass.

Perhaps you're thinking of Windows 3.x? In 3.x, MessageBox() did *not*
make sounds automatically. If you wanted to give the appearance that a
sound "belonged" to a message, you usually called MessageBeep() separately
(just before calling MessageBox()). Perhaps this behavior is also required
in version of Windows NT prior to 4.0?

MessageBox() definitely *does* make sounds. So, again, which
implementation of the Windows API are you referring to where it doesn't?


Best regards,

Matt Arnold
Professional Music Products
Mark of the Unicorn, Inc.
http://www.motu.com

In an attempt to foil spammers I use a "fake" e-mail address when posting
to newsgroups. Replace "biteme" with "motu" to obtain my actual address.

*-----------------------------------------------------------------------*
| N O T I C E T O S P A M M E R S |
| |
| Pursuant to US Code, Title 47, Chapter 5, Subchapter II, Sec. 227 any |
| and all unsolicited commercial e-mail sent to this address is subject |
| to a download and archival fee in the amount of US$500.00. E-MAILING |
| THIS ADDRESS DENOTES ACCEPTANCE OF THESE TERMS. For more information |
| go to http://thomas.loc.gov/cgi-bin/bdquery/z?d105:SN01618:@@@D. |
| |
*-----------------------------------------------------------------------*


Raymond Chen

unread,
Aug 6, 1999, 3:00:00 AM8/6/99
to
MessageBox() always plays the system messagebox sound, as
configured by the user in the Sounds control panel. If you don't
want a sound, use a custom dialog box.
--
(My return address is intentionally invalid; delete ".---" to get my real address.
My responses are not to be considered official technical support or advice.)

Thomas W. Brown

unread,
Aug 6, 1999, 3:00:00 AM8/6/99
to
Well, I stand corrected, I'll go stand in the corner now....!

I had the practice of coding separate calls to MessageBeep() and
MessageBox() so ingrained that I never realized that MessageBox() had
started playing the sound. A couple of curious points...

1. It would be @#$!%! nice if the documentation would reflect that
change in functionality!

2. Why do I not get two beeps when I still call MessageBeep()
immediately followed by MessageBox()??? I'm guessing that the second
attempt gets thrown on the floor since the first is still playing
asynchronously, but it's still kinda curious.

-- Thomas Brown
tbr...@softbook.com

Raymond Chen

unread,
Aug 6, 1999, 3:00:00 AM8/6/99
to
Don't mess with the user's sound settings! For example, one of
the things that'll go wrong is that until the user clicks OK to
your soundless messagebox, NONE of the messageboxes in the system
will play any sounds. And if the user Ctrl+alt+Del's your
application while your soundless message box is up, then all
sounds have been turned off permanently!

If you don't want default messagebox behavior, write your own
dialog box. It's not that hard, really.

Matt A.

unread,
Aug 6, 1999, 3:00:00 AM8/6/99
to

Thomas W. Brown wrote in message <37AB12A2...@softbook.com>...

>Well, I stand corrected, I'll go stand in the corner now....!
>
>I had the practice of coding separate calls to MessageBeep() and
>MessageBox() so ingrained that I never realized that MessageBox() had
>started playing the sound. A couple of curious points...
>
>1. It would be @#$!%! nice if the documentation would reflect that
>change in functionality!

Wouldn't it? ;-)

>
>2. Why do I not get two beeps when I still call MessageBeep()
>immediately followed by MessageBox()??? I'm guessing that the second
>attempt gets thrown on the floor since the first is still playing
>asynchronously, but it's still kinda curious.

Yes, MessageBeep() doesn't do anything if a sound is currently playing.
Therefore, in this case...

MessageBeep();
MessageBox();

...the sound made by MessageBox()'s call to MessageBeep() won't be heard
(because the sound made by the proceeding call to MessageBeep() will likely
still be playing).

[snip]

Best regards,

Matt Arnold
Professional Music Products
Mark of the Unicorn, Inc.
http://www.motu.com

In an attempt to foil spammers I use a "fake" e-mail address when posting

Matt A.

unread,
Aug 6, 1999, 3:00:00 AM8/6/99
to

Raymond Chen wrote in message <37ae1f9b.656365625@abject>...

>Don't mess with the user's sound settings! For example, one of
>the things that'll go wrong is that until the user clicks OK to
>your soundless messagebox, NONE of the messageboxes in the system
>will play any sounds. And if the user Ctrl+alt+Del's your
>application while your soundless message box is up, then all
>sounds have been turned off permanently!

Well, you *could* use a windows hook to revert the sound scheme after the
MessageBox() has processed WM_INITDIALOG. This would solve one of the
problems you mention.

However, you're right, if the system were to go down in flames somewhere
between calling MessageBox() and the hook's WM_INITDIALOG processing, the
sound scheme settings will be left in the "off" state.

>
>If you don't want default messagebox behavior, write your own
>dialog box. It's not that hard, really.

So, I guess we should take this as confirmation from a Microsoft insider
that there's no way to stop MessageBox() from making sounds?

john

unread,
Aug 6, 1999, 3:00:00 AM8/6/99
to
On Sat, 07 Aug 1999 00:16:35 GMT, raymon...@microsoft.com (Raymond
Chen) wrote:

>You can use MessageBoxIndirect and specify a custom icon with
>MB_USERICON, then the system won't play a sound since it doesn't
>know which sound to play.

I just wanted to say thanks to everyone for their help in clarifying
this for me. I really do appreciate the help of those more
knowledgeable than I.

John

Matt A.

unread,
Aug 6, 1999, 3:00:00 AM8/6/99
to

Raymond Chen wrote in message <37ab7904.679255453@abject>...

>You can use MessageBoxIndirect and specify a custom icon with
>MB_USERICON, then the system won't play a sound since it doesn't
>know which sound to play.

Ah, so we have (for John, the original poster)...


int QuietMessageBox(HWND hwnd, LPCTSTR msg, LPCTSTR cap, UINT flags)
{
MSGBOXPARAMS mbp = { sizeof(MSGBOXPARAMS) };

mbp.hwndOwner = hwnd;
mbp.lpszText = msg;
mbp.lpszCaption = cap;

switch (flags & MB_ICONMASK)
{
case MB_ICONQUESTION:
mbp.lpszIcon = MAKEINTRESOURCE(IDI_QUESTION); break;

case MB_ICONEXCLAMATION:
mbp.lpszIcon = MAKEINTRESOURCE(IDI_EXCLAMATION); break;

case MB_ICONSTOP:
mbp.lpszIcon = MAKEINTRESOURCE(IDI_HAND); break;

default:
mbp.lpszIcon = MAKEINTRESOURCE(IDI_ASTERISK); break;
}

mbp.dwStyle = (flags & ~MB_ICONMASK) | MB_USERICON;

return MessageBoxIndirect(&mbp);

Raymond Chen

unread,
Aug 7, 1999, 3:00:00 AM8/7/99
to
You can use MessageBoxIndirect and specify a custom icon with
MB_USERICON, then the system won't play a sound since it doesn't
know which sound to play.

Patan

unread,
Aug 9, 1999, 3:00:00 AM8/9/99
to
Raymond Chen wrote:
>
> MessageBox() always plays the system messagebox sound, as
> configured by the user in the Sounds control panel. If you don't
> want a sound, use a custom dialog box.

Or just change the Registry settings at HKEY_USERS/.../AppEvents/...
making the string values equal to NULL for the events you choose not to
play sounds at...Too bad it will affect every app messagebox in the
system...

0 new messages