Thread: inserting text into edit control

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    inserting text into edit control

    is there any efficient way to insert a string into an edit control without simulating the key presses through messages like WM_KEYDOWN? i mean, insert a string wherever the cursor is, even if its in the middle of a document?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    SendMessage(hwnd, WM_SETTEXT, 0, (long)actText);

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    If there is no text selected, you can send an EM_REPLACESEL message. If nothing is selected, the default action is to insert the text at the cursor position. You could use EM_SETSEL to set a zero length select range at the cursor position if you want to be sure nothing else is selected.

    *** EDIT ***

    >>> SendMessage(hwnd, WM_SETTEXT, 0, (long)actText);

    That won't work, that would replace the existing text, not insert after the cursor. You could use GetWindowText() to get the current text into a buffer then modify the buffer to your liking and send it back with SetWindowText() if you wanted to.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    cheers adrian. thanks anyway for trying knutso. the best way to learn is to make mistakes.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Oops! I should look more carefully at who the poster is before answering, hell, it was early in the day and I just read the question, sorry Ben!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Controlling edit control input
    By Gerread in forum Windows Programming
    Replies: 6
    Last Post: 05-03-2007, 08:56 PM
  2. Problems with my edit control...
    By tyouk in forum Windows Programming
    Replies: 19
    Last Post: 10-19-2003, 12:36 AM
  3. adding a line of text to a readonly edit control?
    By Kibble in forum Windows Programming
    Replies: 2
    Last Post: 11-25-2002, 09:04 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM