tags:

views:

37

answers:

2

Simple problem, normally a program will produce a MessageBeep if the user presses Alt+Whatever and there's no hotkey associated with it. What API functions can I call to avoid this?

Handling WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, and WM_SYSKEYUP all with return 0; on my main WndProc does not work.

+1  A: 

I think this is a system setting. Control Panel + Sounds + Sounds tab. Not sure which one does it, I have a lot of them turned off. Maybe "Program Error".

Hans Passant
That is a Global Solution to a Local Problem. Is there any way to disable a program from emitting the message that causes the program error sound to play?
Scott Chamberlain
Yes, I can see how the first sentence can be a bit misleading, but I want to disable this MessageBeep programmatically within my own program.
kaykun
No, programs are *not* supposed to override the user preferences. Or to put it more bluntly, a programmer is not supposed to force his personal preferences on the user. Same thing goes for stuff like caption sizes, fonts, colors, taskbar, screen resolution, etc. If somebody has that beep turned on, it is usually for a good reason. Some kind of disability, perhaps. Why did you turn it on?
Hans Passant
I don't recall ever turning anything like that on. I know of programs that can handle Alt+Enter without ever calling MessageBeep, so I know it's possible.
kaykun
What's the significance of Alt+Enter? What kind of window has the focus when it beeps?
Hans Passant
Alt+Enter is used in some programs to toggle Fullscreen/Windowed mode, which is also what I want to do. For my test program I literally used the default example program that comes when creating a new Win32 application project in VC++.
kaykun
+2  A: 

WM_MENUCHAR should be what your looking for. MSDN search is you friend (>message beep shortcut< or >message beep accelerator<).

http://msdn.microsoft.com/en-us/library/ms646349(VS.85).aspx

Edit: seems to be only for active menus.
Edit 2: works like a charm. note MSDN:

An application that processes this message should return one of the following values in the high-order word of the return value.

I've used MNC_CLOSE << 16.

DyP
Perfect. Thanks a lot; I probably wouldn't have ever gotten that otherwise.
kaykun