Edit control help

This is a discussion on Edit control help within the Windows Programming forums, part of the Platform Specific Boards category; hi im trying to append text to and edit box that already have some text, i use EM_SETSEL but the ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    113

    Edit control help

    hi im trying to append text to and edit box that already have some text, i use EM_SETSEL but the new text allways replace the old one i created a edit box like:
    Code:
    EditB = CreateWindowEx(NULL,"EDIT","",
    			WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
                ES_LEFT | ES_MULTILINE | ES_NOHIDESEL 
    			| ES_AUTOHSCROLL | ES_AUTOVSCROLL,0,0,528,482,
    				hwnd,(HMENU)ID_EDIT,GetModuleHandle(NULL),NULL);
    and the:

    Code:
    int tamanio = 0;
    //...a loop starts here
    ...new string linea here(reading from file)
    SetDlgItemText(hwnd,ID_EDIT,linea);
    tamanio=GetWindowTextLength(EditB)
    SendMessage(EditB,EM_SETSEL,tamanio,tamanio);
    //...here a loop returns
    i think the SetDlgItemText function is the problem, is there another way to append text to an editbox, or what im doing wrong?

    thanks for any help
    Last edited by terracota; 12-01-2004 at 03:36 PM.

  2. #2
    Registered User
    Join Date
    Nov 2004
    Posts
    11
    Why dont you store the old text and use strcat to append your text, then send the new text to the control

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    Quote Originally Posted by paul_uk
    Why dont you store the old text and use strcat to append your text, then send the new text to the control
    ok good idea, but what im trying to do is to load a text file into the edit box, and what happens if the text file is too big? will this be efficient? i mean the "string" will too big.

    thanks for reply

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,255
    Make the edit box multi-lined, and give it a vertical scroll bar. Then the string can never be too big.

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    good thanks for help,
    but:
    if im reading from a file what could be best, read char by char or read a whole line? why i ask this?
    because if im trying to read a text file that haves only 1 line of text but that line of text haves 1000 chars? and i declared my string to hold that text with ie. [80]?

    and am i using the wrigth function to append text to an editbox? SetDlgItemText()

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    SetDlgItemText will set the text for a control. To replace the selection only use EM_REPLACESEL.

    Append edit text

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    thanks for help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I send a text string to an edit control
    By marc74 in forum Windows Programming
    Replies: 5
    Last Post: 01-06-2005, 10:14 PM
  2. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 10:52 PM
  3. Restricting input to an edit control
    By bennyandthejets in forum Windows Programming
    Replies: 7
    Last Post: 10-05-2003, 02:10 AM
  4. endless edit control
    By ZerOrDie in forum Windows Programming
    Replies: 3
    Last Post: 03-21-2003, 02:51 AM
  5. Keeping focus on an edit control ...
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 02-19-2002, 02:12 AM

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