Placing Text in An Edit box

This is a discussion on Placing Text in An Edit box within the Windows Programming forums, part of the Platform Specific Boards category; How would I make my program make text appear in a read-only edit box?...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    920

    Placing Text in An Edit box

    How would I make my program make text appear in a read-only edit box?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    SetDlgItemText() will do that.
    "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

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    920
    Thanx. Now, how would I put it in the next line? Like in a chatroom.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235

    This is how

    Uses something similiar to:

    m_strString = "This is the First line \n\r This is the second";
    // or it may be just a "\n", i forget which;
    SetDlgItemText(IDC_EDIT1, m_strString);
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    920
    Thanks again. Now, how would I make it write it in the edit box, then later, write in something else on the next line. Like a chatroom.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  6. #6
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hi,

    Well in theory you would put your first line of text in, then get it into a varible then append that varible then display it in the control.

    Now heres some code, im used to using SetWindowText() it works but you can use SetDlgItemText() if you want...

    Code:
    char szNewBuffer[100];
    
    //make the first line you want to display
    char szBuffer[100] = "This Is The First Line\r\n"; 
    //now display it
    SetWindowText(hWndMyEdit, szBuffer);
    
    //now later in ur prog get the current text
    GetWindowText(hWndMyEdit, szNewBuffer, 100);
    
    //Now Append szNewBuffer onto the end of the first buffer
    //then display it
    strcat(szBuffer, szNewBuffer);
    SetWindowText(hWndMyEdit, szBuffer);

    Thats just off the top of my head, but you should be able to fiddle around with that and apply it to your program.

    Hope that helps.

    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  7. #7
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    920

    Red face uuhhh....

    Um, how do I put this...

    I don't get it.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  8. #8
    Unregistered
    Guest

    Arrow Ok i will try again...

    Hi,

    I will try to explain it a little simpler:

    Say you have a chat prog as you said and say your edit box looks like this:

    ##############
    # This Is Line 1 #
    # #
    # #
    ##############

    So you have one line of text in it, "This is line 1". And if i understand you correctly and sorry if i dont, you want to add another line of text to it. So it looks like this:

    ##############
    # This Is Line 1 #
    # This Is Line 2 #
    # #
    ##############

    Ok so to do this first once youve made your edit box you put in the first line like this:

    in the below code im asuming that you created your edit box using hWndEdit.

    Code:
    char szLine1[100] = "This Is Line 1";
    SetWindowText(hWndEdit, szLine1);

    Ok so you now have an edit box with "This is line 1" in it.
    Now at another point in your program you want to add another line to it, which i think is what your talking about.

    Code:
    char szLine2[100] = "\r\nThis Is Line 2";
    
    //now szLine2 needs to be added onto szLine1 then be displayed:
    
    strcat(szLine1, szLine2); //string.h
    
    //so now szLine1 contains:
    //ThisIsLine1
    //ThisisLine2
    
    //So now you have added another line we just need to update
    //the edit box:
    
    SetWindowText(hWndEdit, szLine2);

    Once Done your edit box will have both lines of text in this proccess can be adapted to add multiple lines of text.

    I think that is clearer than before, but sorry if i misunderstood your question.

    Cheers
    TNT

  9. #9
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    920

    Lightbulb "I can see clearly now the rain is gone..."

    Thank you. Your explanation is perfect.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Look into HDC's.
    If you are making a mainly chat app, you should use a Device Context to draw on. Rather than a large editbox. Will be easier in the long run.
    Can use scrolling functions, different colours, fonts ect.

    Use a Frame control and GetDC().
    See
    "Errors with resource bitmaps....HELP PLEASE"
    for code to create a HDC.
    "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

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I would also question the wisdom of using an edit box control for displaying this kind of output. I think I would be inclined to use a list box.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    920
    Yes, you're right. How do you display info in a list box?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  13. #13
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post You would...

    Just do this:

    SendMessage(handle_of_listbox, LB_ADDSTRING, (WPARAM)"String to add", (LPARAM)13);
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>SendMessage(handle_of_listbox, LB_ADDSTRING, (WPARAM)"String to add", (LPARAM)13);

    I think it is

    SendMessage(handle_of_listbox, LB_ADDSTRING, (WPARAM)0, (LPARAM)"String to add");
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-06-2010, 12:42 AM
  2. Retrieving the text from an edit box
    By chrishowarth in forum Windows Programming
    Replies: 13
    Last Post: 05-13-2007, 07:57 PM
  3. Capture Enter key press in EDIT Box
    By richiev in forum Windows Programming
    Replies: 4
    Last Post: 07-14-2005, 01:03 AM
  4. Edit Box Questions PT. II
    By Quantrizi in forum Windows Programming
    Replies: 16
    Last Post: 08-12-2003, 11:42 PM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 10:45 PM

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