?
Solved

API - Get WM_KEYDOWN message from edit control

Posted on 2003-03-24
5
Medium Priority
?
1,354 Views
Last Modified: 2013-12-03
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
Comment
Question by:eamarks
[X]
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
  • 3
  • 2
5 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 8198150
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
 

Author Comment

by:eamarks
ID: 8198401
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 8198762
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
 

Author Comment

by:eamarks
ID: 8199262
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
 
LVL 49

Accepted Solution

by:
DanRollins earned 120 total points
ID: 8199544
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

764 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