Thread: Escape sequences in VC++

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    14

    Question Escape sequences in VC++

    How do you get Microsoft Visual C++ to put carriage returns into strings and use them in list boxes? It just puts a small line in whenever I try using the old \n. I need to have carriage returns in the strings.

  2. #2

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    14
    I've tried \r\n as well, and it didn't work. None of the escape sequences do.

    I'm trying to add the text from a text box because it's the only way I can get the data to transfer from another dialog box. This is the text string:

    CEdit* pTxtBurgers = (CEdit*)GetDlgItem(IDC_TXTBURGERS);
    pTxtBurgers->SetWindowText(Cheese + Lettuce +
    Ketchup + Mustard + Onions + Pickles +
    Tomato + Cooked + Bun);

    The third line is where it adds the text string.

    CBurgers dlgBurgers;
    dlgBurgers.DoModal();
    m_Orders.AddString(dlgBurgers.m_TxtBurgers);

    It does add the text, but you can't read the whole line because it goes off the edge and I can't figure out how to even get the list box to scroll. I set the scroll properties to yes but it doesn't scroll.
    I really don't want to add a text box for every variable in the other dialogue, since they are set up as checkboxes anyway. This is how the example in my text book adds the string, so it's what I'm doing for now. I'm not a programming newbie but I am a VC++ newbie, and the book for my class is not the most helpful. Neither is Microsoft's help.

  4. #4
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > Neither is Microsoft's help.

    Which is odd, because that's all I use.

    You're trying to get a list box to do something it can't do. List boxes do not have horizontal scrollbars, and they don't accept line breaks in text. If you want to do this, you must make an owner-draw list box.

    Why are you trying to do this? If something is outside the realms of the standard controls, often it's because your interface could be done better in another way.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    14
    The project required that each item be added to a list box on the main dialogue screen. I can live without the extra formatting, but it would have been nice.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Statics text controls accept /r and /n but if you need listboxes this won't help.

  7. #7
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    >>The project required that each item be added to a list box on the main dialogue screen

    MSVC 6.0 + MFC
    To add items to a list box you have to InsertString() in order to add things to your list box.

    First create a member variable in class wizard for the drop box.
    I use something like m_drItems.
    Then using this member variable InsertString().

    Code:
    m_drItems.InsertString(0,"Item1");
    m_drItems.InsertString(1,"Item2");
    //Updatedata
    UpdateData(FALSE);
    Now you should beable to see items added to your drop box.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  8. #8
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Also if you do not want to have the items in order, you can leave the 0 or 1 off and it will sort them alphabeticaly.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LoadFromFile() from a txt
    By Snoopy104 in forum C++ Programming
    Replies: 6
    Last Post: 03-14-2006, 10:05 AM
  2. Interpreting literal escape sequences from a file...
    By Sebastiani in forum C++ Programming
    Replies: 1
    Last Post: 07-08-2003, 02:00 PM
  3. Using escape sequences as user inputs
    By musayume in forum C Programming
    Replies: 4
    Last Post: 12-11-2001, 09:35 AM
  4. ANSI Escape Sequences OR Scan of keyboard
    By Samppa in forum Linux Programming
    Replies: 3
    Last Post: 10-24-2001, 12:15 PM
  5. Escape Sequences
    By Me-Again-Again in forum C Programming
    Replies: 3
    Last Post: 09-05-2001, 06:24 AM