How can I send a text string to an edit control

This is a discussion on How can I send a text string to an edit control within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm trying to use an Edit control to output data from my program to a log window (with vertical ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    11

    How can I send a text string to an edit control

    Hi,

    I'm trying to use an Edit control to output data from my program to a log window (with vertical scroll bar).

    Firstly, I'm not sure if using an Edit control is the best option - if I set it to READONLY, can I still output text to it without the user being able to edit the text ?

    Secondly, I can't figure out what message to send to actually add a new line of text to the Edit control.

    Can anyone point me in the right direction ?

    Thanks,
    Marc

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> if I set it to READONLY, can I still output text to it without the user being able to edit the text ? <<

    Yes.

    >> Secondly, I can't figure out what message to send to actually add a new line of text to the Edit control. <<

    Append text to edit control

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    11
    Hi,

    I can't seem to get my new text strings I add to my edit control to appear at the end of the control. Instead they always seem to be added first.

    eg I get
    "string2"
    "string1"

    whereas I want
    "string1"
    "string2"

    Here's how I'm sending the text string to the edit control
    SendMessage ( hwndEdit, EM_SETSEL, 0, (LPARAM) &count );
    SendMessage ( hwndEdit, EM_SETSEL, 0, count );
    SendMessage ( hwndEdit, EM_REPLACESEL, FALSE, (LPARAM)str );

    Any ideas ?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    12
    Try following:

    Code:
    AppendText(hwndEdit, "\r\nThe text to add");
    The following is the code for AppendText:

    Code:
    void AppendText(HWND hwndEdit, char* TXT)
    {
    
    	/* Move selection to end of text */
    	SendMessage(hwndEdit, EM_SETSEL,
    		GetWindowTextLength(hwndEdit),
    		GetWindowTextLength(hwndEdit));
    
    	/* Add the text line and scroll it into view */
    	SendMessage(hwndEdit, EM_REPLACESEL, FALSE, (LPARAM) TXT);
    	SendMessage(hwndEdit, EM_SCROLLCARET, 0, 0);
    }

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,659
    Quote Originally Posted by anonytmouse
    >> if I set it to READONLY, can I still output text to it without the user being able to edit the text ? <<

    Yes.

    >> Secondly, I can't figure out what message to send to actually add a new line of text to the Edit control. <<

    Append text to edit control
    Does everyone know that the big text is a clickable link with answers?

    gg

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Anyways since reading links by anonytmouse is not important.
    heres what i use to append text to an edit control
    Code:
    #include <itotallymadethisup.h>
    
    appendTextToAnEditControl("Text");
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. Struggling to read text from Edit Control (box)
    By csonx_p in forum Windows Programming
    Replies: 6
    Last Post: 05-13-2008, 04:55 AM
  3. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 06:58 AM
  4. adding text to an edit control
    By steve_i83 in forum Windows Programming
    Replies: 2
    Last Post: 10-26-2001, 06:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21