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
  • 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.

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

624 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