Thread: edit controls

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    254

    edit controls

    well i have been reading msdn and some previous posts on the topic here...

    from what i have read you cannot continuously add text to an edit control? is this correct? from what i have gathered i would have to keep adding my text into a large buffer and sending it to the edit control every time i wanted to modify the contents of the edit control... is this correct or is there a way to add text to currently present text in my edit control?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is to link a CString object to the edit box. Call UpdateData(FALSE) after you append characters to the CString object.

    Kuphryn

  3. #3
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    Use editbox message. there are lots of them;

    SendMessage(hedit, EM_SETSEL, (WPARAM) begpos,(LPARAM)endpos)

    you can use this to manupulate any part of the text in editbox.

    there are a whole range of them in MSDN you can use.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    254
    hmmm ill look into those... anyone perchance know how to add carriage returns in edit controls? adding "\n" to a string does not seem to have any effect

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    You need to use a '\r' as well.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    254
    heh having a little trouble

    http://support.microsoft.com/default...;en-us;Q109550

    my edit controls are set ES_READONLY by the way
    Code:
    hwndDisplayBox = CreateWindow("EDIT",
    			NULL,
    			WS_CHILD | WS_VISIBLE | WS_VSCROLL | 
    			ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER | ES_READONLY, 
    			0, 0, 0, 0,
    			hwnd,
    			(HMENU) ID_DISPLAYBOX, 
    			(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), 
    			NULL);
    
    //lower down in another function :p
    CHAR szBuffer []= "Connecting to server";
    	
    	HWND hEdit = GetDlgItem (hwndDisplayBox, ID_DISPLAYBOX);
    	int ndx = GetWindowTextLength (hEdit);	
    	SendMessage (hEdit, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
    	SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) ((LPSTR) szBuffer));
    unfortunatly im not getting any text showing up from the above...

    i removed the setfocus as it seemed redundant according to msdn since im not allowing the user to input anything...

    well im puzzled

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Is GetDlgItem() returning the handle or NULL? It looks like you are creating your editbox handle over the dialogbox handle, or you are using the editbox handle where you should be using the dialogbox handle in the call, without seeing more of course, it's hard to be sure.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>HWND hEdit = GetDlgItem (hwndDisplayBox, ID_DISPLAYBOX);


    Adrian has it.
    'using the editbox handle (hwndDisplayBox) where you should be using the dialogbox handle (hwnd) in the call'

    This should be using the HWND of the parent (from the CreateWindow() HWNDPARENT param) not the edit control.

    In fact you do not need to call this function if you already have the edits HWND (hwndDisplayBox and you have made it a global)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> (hwndDisplayBox and you have made it a global)

    Or static.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    HWND hEdit = GetDlgItem (hwndDisplayBox, ID_DISPLAYBOX);
    SendMessage (hEdit, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);


    and check this two;

    your index for (WPARAM) should be the beg position.
    you are actually doing nothing with this .because
    endpos = beg pos = 0;


    it should be as follows:

    SendMessage (hEdit, EM_SETSEL, (WPARAM) 0, (LPARAM)ndx);

    i think

  11. #11
    Bleh
    Guest
    how about this:

    SendMessage(TextBoxHwnd, EM_SETSEL, -1, -1);
    SendMessage(TextBoxHwnd, EM_REPLACESEL, FALSE, (LPARAM) "text");


    maybe?

  12. #12
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Please don't bump old threads, (post to treads after they have been inactive for more than a week or so. They simply clutter the bard, and if the original poster hasn't asked any followups, he's either happy or left.
    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. Creating an Edit Box (Subclassing)
    By csonx_p in forum Windows Programming
    Replies: 9
    Last Post: 05-05-2008, 06:36 AM
  2. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 07:15 PM
  3. Subclassing controls
    By filler_bunny in forum Windows Programming
    Replies: 3
    Last Post: 04-28-2004, 05:43 PM
  4. Dialog Edit Control and Enter Key
    By Quantrizi in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2004, 07:59 AM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM