Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Trap editbox keystrokes... Get beep??

Posted on 1999-07-15
Medium Priority
Last Modified: 2013-12-03
This relates to a question I asked previously:

I am not using MFC
I subclass an editbox control with the callback function at the end of this question.  When I hit the enter key, I get a beep as if a message box had been displayed, or clicked on an disabled part of a window. Any suggestions?

      switch (iMsg) {
            case WM_GETDLGCODE:
                  return DLGC_WANTALLKEYS;
      } // switch on message
      return (CallWindowProc((WNDPROC)GetWindowLong(hwnd,GWL_USERDATA),hwnd,iMsg,wParam,lParam));
} // MyEditBoxProc

Thank You
Question by:Ignatz
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
  • 5

Accepted Solution

Laminamia063099 earned 800 total points
ID: 1403048
You need to capture, in your edit control procedure, the WM_CHAR message and capture specifically the VK_RETURN and VK_TAB keys. Like this:
  switch (message)
            case WM_CHAR:
            switch (wParam)
                case VK_RETURN:
            case VK_TAB:
                  return 1;
    //other messages

Expert Comment

ID: 1403049
This is what happens in the default edit box control procedure on the WM_CHAR message.  Note the last sentence that says what happens on illegal characters, MessageBeep ()!  It thinks of return and tab as illegal characters in single line edit controls.  You can capture VK_TAB for tabbing through edit controls with the WM_KEYDOWN message, but you don't need it in the WM_CHAR message.  In fact, you'll almost never capture the WM_CHAR message, so it default processes your tabs and returns and, as illegal characters, it  produces a beep.

Online help, on Default Edit Control Message Processing:
   Writes a character to the single-line edit control and sends the EN_UPDATE and EN_CHANGE notification messages to the parent window. Writes a character to the multiline edit control. Handles the accelerator keys for standard functions, such as CTRL+C for copying and CTRL+V for pasting. In multiline edit controls, also processes TAB, and CTRL+TAB keystrokes to move among the controls in a dialog box and to insert tabs into multiline edit controls. Uses the MessageBeep function for illegal characters.

I had the same problem, and I just solved it  (as of today :)


Expert Comment

ID: 1403050
BTW, you don't get a beep on multi-line and scrolled edit controls when you hit TAB or RETURN because they aren't "illegal characters" in a multiline or scrolled edit control.

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.


Expert Comment

ID: 1403051
Note:  This is a lesson in the behind the scenes work in Windows.  When you hit a key, several messages more than the WM_CHAR or WM_KEYDOWN are sent.  If you hit the return key, the WM_KEYDOWN message is sent, and is translated by the TranslateMessage () fn in your WinMain.  This generates the WM_CHAR message.  After this, the WM_KEYUP message is sent when you are done hitting the return key.  

If you wanted to totally disable the keyboard, you must capture all of these messages, and a few more (WM_SYSKEYDOWN, etc.)

Laminamia :)

Author Comment

ID: 1403052
Outstanding answer!
Worked perfectly! Thank You - Ignatz

Expert Comment

ID: 1403053
No problem.  Thanks for asking.  I've had that problem with a GUI program I'm developing.  When i read your question, I decided to find out how to get around it and the answer was only a few minute search away.  In essence, by asking me a question, you gave me the answer I've been looking for as well.  You got me to look for it (The points were a small incentive as well :)


Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

670 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