Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1421
  • Last Modified:

API - Get WM_KEYDOWN message from edit control

I have a child window which acts in the way that a dialog box would.  It contains edit controls and combobox controls.  How can I get it to send the WM_KEYDOWN message to the Window Proc of the child window?

If you need a more specific description, let me know.

Thanks,
Evan
0
eamarks
Asked:
eamarks
  • 3
  • 2
1 Solution
 
DanRollinsCommented:
The SendMessage and PostMessage APIs are commonly used for sending messages.  You can also send keystrokes to the active (focus) window by using the SendInput API.

And yes, the description of your problem is too thin.  Beef it up with specific details if you want specific details in the answers.

-- Dan
0
 
eamarksAuthor Commented:
Dan,

I understand how to send messages to a control - I need to somehow handle a keypress if the edit control has the focus.  More specifically I want to make the tab key switch to the next edit box.
0
 
DanRollinsCommented:
You can detect the WM_CHAR message in your event loop.   It is possible that if you give the EditBoxes the WS_TABSTOP style, they will handle this themselves (I'm not certain).

I know that in normal dialogbox handling, the tab key event never makes it to the edit control.  The parent window sees it and takes action -- it normally uses ::GetNextDlgTabItem() and sets that child window as the focus window via ::SetFocus()

Do you know what an event loop is and how to have it check for specific messages and take specific actions?  The procedure varies depending upon if you are writing raw Win32 code or using MFC or some other agent.

-- Dan
0
 
eamarksAuthor Commented:
Dan,

I am writing in pure win32 code, no MFC.   I have an Window Procedure for the child window that contains the edit boxes and I am currently checking it for the WM_KEYDOWN message.  It works fine when the window opens, but when I give an edit control the focus it does not receive the message.  Also, you mentioned dialog boxes - this isn't a dialog box - it is simply a child window that programmatically handles all of its own messages.

As a last resort, if I can't figure this out, then I will probably have to use a dialog box, but I would rather not because I would have to change a lot of code.

I will try WM_CHAR and get back to you, but if you have anymore ideas based on this message, feel free to post them.

Thanks,

Evan
0
 
DanRollinsCommented:
THe window that contains the edit boxes will *not* receive the WM_CHAR messages when an edit box has the focus (this is your main problem).  

That is why i asked about your event loop.  Somewhere in your program, see if you can find some code that looks like this:

     while (GetMessage(&msg, NULL, 0, 0))      {
          if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))           {
               TranslateMessage(&msg);
               DispatchMessage(&msg);
          }
     }
 
You can intercept any message (such as WM_CHAR) before it gets to the EditBox by placing it before the TranslateMessage() line.  eg.

      if( msg.message==WM_CHAR ) {
            if ( msg.wParam == 0x09 ) { // tab
               ..... etc ...

Another way to handle this:  The window proc that you mention (the parent of the editboxes) will get an EN_CHANGE and an EN_UPDATE notification with each new input into any of the text boxes.  You can see these in your WM_COMMAND handler (wParam will be EN_Xxxxx and lParam will be an HWND).  When you get that notif, I suppose you could check to see if there is a tab character in the text... I have not tried this.

-- Dan
0

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now