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
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
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. |
| |
*-----------------------------------------------------------------------*
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
If you don't want default messagebox behavior, write your own
dialog box. It's not that hard, really.
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
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?
>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
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);
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...