Thread: sending enter key message to window

  1. #1
    Registered User
    Join Date
    Sep 2003

    sending enter key message to window

    I have the handle names of a edit box which is a child of a combo box. these two controls are in another application.


    SendMessage(txtBox, WM_SETTEXT, NULL, (LPARAM)(LPCTSTR)response);
    I can place text in the edit box. Now i need to send the enter key message to the edit box, I have tried:
    SendMessage(txtBox, WM_KEYDOWN, VK_RETURN, 0);
    SendMessage(txtBox, WM_KEYUP,  VK_RETURN, 0);
    PostMessage(txtBox, WM_CHAR, VK_RETURN, 0);
    SendMessage(txtBox, WM_CHAR, VK_RETURN, 0);
    PostMessage(txtBox, WM_KEYDOWN, VK_RETURN, 0);
    PostMessage(txtBox, WM_KEYUP, VK_RETURN, 0);
    keybd_event(VK_RETURN, 0,0,0);
    keybd_event(13, 0,KEYEVENTF_KEYUP,0);
    None of which worked. I use Borland C++ 3, Win 2000

    Any ideas?

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    1. Just a tip, it's probably better to prefix handle names with 'h'. It just allows you to tell that it's a handle straight away.

    2. I think you may have to send the enter message to a different part of the control. Normally, single-line edit controls don't receive enter key messages, they're redirected elsewhere. Try sending it to the overall control.
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ

  3. #3 JasonD's Avatar
    Join Date
    Mar 2003
    You should understand the difference between notifications and actual events. Most of the messages you are attempting to send to the control are notifications. These are messages that are sent to windows after something has happened. It notifies them, in case they wish to do something in response to it. They do not emulate the event which has happened.

    As an example, the SetFocus() function changes the focus, whereas WM_KILLFOCUS is simply a notification to tell that window that the focus has been lost. It cannot be sent to force it to lose focus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Window message loop (Keys)
    By Blackroot in forum Windows Programming
    Replies: 3
    Last Post: 09-12-2006, 05:15 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Making dialog box the only window
    By PJYelton in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2005, 12:02 PM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM