Thread: Displaying strings in text boxes

  1. #1
    george7378
    Guest

    Displaying strings in text boxes

    Hi everyone,

    I am trying to use a Win32 textbox (EDITTEXT) to display certain words when you press certain buttons. I know how to use them to display numerical outputs, but I'm not sure how to display strings with them. I've given it a go anyhow, and I have the following:

    Code:
    case IDC_HELLOBUTTON:                       //Press this button to write 'Hello'.
    char strHi[100];                                   //A char to store the string contents.
    std::string outputstring;                        //A string to store 'Hello'.
    outputstring += "Hello";                         //Adding 'Hello' to the string.
    sprintf_s(strHi,"%0.0f",outputstring);       //Putting the string in the char array.
    SetDlgItemText(hwnd, IDC_OUTPUT, strHi);     //Writing the char's contents in the box.
    It isn't working at the moment (it just puts '0' in the box) so I was wondering if anyone could offer some tips?

    Thanks!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So, do you know anything about what printf is? Maybe you should read the manual.

  3. #3
    george7378
    Guest
    OK, I understand a bit more now - but I still don't get what I would do to allow it to write strings to the text box. Could you point me in the right direction with an example please?

    Thanks.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Hint : What does %0.0f mean in the sprintf?

  5. #5
    george7378
    Guest
    It's the number of decimal places that the answer is written to? I thought it may be something to do with the flag (I switched it to %s and the box said (null) instead of zero).

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Do you expect a string to have "decimal places"?

    And you need to print outputstring.c_str() in your sprintf call.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Report from Some Text Boxes ??
    By _root in forum C# Programming
    Replies: 1
    Last Post: 05-22-2009, 03:59 AM
  2. Displaying ascii boxes
    By rocketman03 in forum C Programming
    Replies: 8
    Last Post: 12-10-2008, 08:41 PM
  3. Text boxes?
    By Squamo in forum C Programming
    Replies: 1
    Last Post: 04-30-2002, 10:18 AM
  4. Text Boxes
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 04-21-2002, 03:16 PM
  5. Text Boxes
    By gnu-ehacks in forum Windows Programming
    Replies: 1
    Last Post: 11-22-2001, 02:37 PM