Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically hinder Windows from playing "Default Beep" sound when user clicks on disabled window (disabled via EnableWindow(hwnd, FALSE))?

When a window is disabled via EnableWindow(hwnd, FALSE), and the user clicks on it, then the "Default Beep" sound gets played. I don't want this to happen. How can I disable this behavior programatically for the current Process in C/C++ with Win32 code?

like image 648
user3756504 Avatar asked Dec 06 '25 06:12

user3756504


1 Answers

The beep is generated by the default window processing of the WM_SETCURSOR message.

From docs for WM_SETCURSOR:

If the low-order word of the lParam parameter is HTERROR and the high-order word of lParam specifies that one of the mouse buttons is pressed, DefWindowProc calls the MessageBeep function.

To prevent the beep, your window procedure should handle WM_SETCURSOR and not call DefWindowProc under those conditions.

like image 140
Jonathan Potter Avatar answered Dec 07 '25 18:12

Jonathan Potter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!