How to disable beep sound when press key in MFC app?

Posted on 2007-12-06
Last Modified: 2008-02-01
HI Experst,
I have develop the MFC application that is not contains any editable control (it just contains frames/images/buttons control) so when I press any key it cause the sound as beep.

I need to disable this "BEEP" sound? how can I can do?
can we disable this? or can we add any "trick"  control to do this?
I have worked on this but I still can not find out how to disable
Pls give me your suggestion about how to disable this or give me some example for this.

Thank in advance!
Question by:Mobinex
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 20420625
What I would do is catch the button press event. I think it was OnButtonDown.
When you will create this event, you will see code that usses the message to call another function,
for ex:  mainwindow::OnButtonDown, which means it propagates the message to the higher levels. All you need to do is to erase that code.

So when you press a button, your application will catch it with the event funtion, but will not do anything with it (including the beep signal)

Hope this helps

LVL 31

Accepted Solution

Zoppo earned 500 total points
ID: 20420713
Hi Mobinex,

I guess it's a dialog-application - even if it's a formview it should be the same ...

Just override your dialog's PreTranslateMessage and implement it somehow like this:

BOOL CMytDlg::PreTranslateMessage(MSG* pMsg)
      if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP )
            switch ( pMsg->wParam )
            case( VK_RETURN ):
            case( VK_ESCAPE ):
            case( VK_SPACE ):
            case( VK_TAB ):
            case( VK_LEFT ):
            case( VK_RIGHT ):
            case( VK_UP ):
            case( VK_DOWN ):
                        return TRUE;
      else if ( pMsg->message == WM_SYSKEYDOWN || pMsg->message == WM_SYSKEYUP )
            switch ( pMsg->wParam )
            case( 'S' ):
            case( 'T' ):
                        return TRUE;

      return CDialog::PreTranslateMessage(pMsg);

This disables default handling of all keys except Space, Enter, ESC, TAB and the arrow keys ... in addition as a sample here all 'ALT+<key>' are blocked except for 'S' and 'T' - this should be done to avoid that pressing ALT-<key> beeps if it's not a shortcut in the dialog - for each shortcut in the dialog you need to add a 'case' in the 'else if' part ...

Hope that helps,


Author Comment

ID: 20424956
Thank Zoppo, it worked.

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question