7

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.

kaykun
  • 2,247
  • 2
  • 24
  • 37

2 Answers2

9

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
  • 38,334
  • 13
  • 112
  • 177
1

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
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 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 Sep 07 '10 at 20:19
  • 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 Sep 07 '10 at 20:28
  • 1
    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 Sep 07 '10 at 20:29
  • 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 Sep 07 '10 at 20:36
  • What's the significance of Alt+Enter? What kind of window has the focus when it beeps? – Hans Passant Sep 07 '10 at 20:46
  • 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 Sep 07 '10 at 21:05