yesthatmcgurk
Fri Jun 08 16:28:30 CDT 2007
On Jun 8, 4:42 pm, AMercer <AMer...@discussions.microsoft.com> wrote:
> > The situation is that I'm zooming my form to fullscreen when I hit alt-
> > enter (kinda like media player behavior). Now my code to go to
> > fullscreen does not cause the windows "default beep" sound to play.
> > But when I hit alt-enter on the form that sound is played. And it
> > only plays when zooming to fullscreen; pressing alt-enter when in
> > fullscreen does not cause the sound to play.
>
> In some cases, windows will beep when an Alt+Key menu access fails. You
> want to handle Alt+Key inputs, but so does windows, and windows uses Alt to,
> for example, give focus to the menu bar. I don't know all the circumstances
> where this phenomenon shows up. To read more, search MS for WM_MENUCHAR and
> MNC_CLOSE.
>
> This may or may not be your problem. To determine if it is, I think you
> need to remove all menus (including system menu) and see if the beeps
> continue. If running without menus results in no beeps, then your problem is
> the windows beep from a failed menu access key. Note that in full screen
> where you don't get beeps, there are presumably no menus in view.
>
> FYI, in my apps, I have decided to live with the beeps rather than try to
> stop them. Solving the problem looked messy and like more trouble that it
> was worth in my case. If this is your problem and you solve it, please post
> back how you solved it.
K, thanks for the thoughts, I appreciate it. I was actually able to
track it down and stop it.
The beep was being played because the key combination (alt-enter) was
being interpreted as a mnemonic. Since there wasn't a valid control
for that mnemonic to activate, the windows beep sound was being played
to indicate this fact. I wasn't able to figure out exactly who was
playing the sound. It might have even been down in win32 somewhere.
But I did figure out how to stop it.
With the help of
http://blogs.msdn.com/jfoscoding/archive/2005/01/24/359334.aspx
I was able to identify a point at which the key combination was being
examined and prevent it from being identified as a mnemonic. The
following override on the form prevents the alt-enter key combination
from being identified as a mnemonic:
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == (Keys.Alt | Keys.Enter))
return true;
return base.ProcessDialogKey(keyData);
}
You can use this to prevent any mnemonic combination from beeping by
changing Keys.Enter to whatever other key.