Solved

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

Posted on 2007-12-06
4
1,509 Views
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!
0
Comment
Question by:Mobinex
4 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20420613
0
 
LVL 3

Expert Comment

by:Dimkov
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

Dimkov
0
 
LVL 30

Accepted Solution

by:
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 ):
                  {
                        break;
                  }
            default:
                  {
                        return TRUE;
                  }
            }
      }
      else if ( pMsg->message == WM_SYSKEYDOWN || pMsg->message == WM_SYSKEYUP )
      {
            switch ( pMsg->wParam )
            {
            case( 'S' ):
            case( 'T' ):
                  {
                        break;
                  }
            default:
                  {
                        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,

ZOPPO
0
 
LVL 1

Author Comment

by:Mobinex
ID: 20424956
yah,
Thank Zoppo, it worked.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now