Displaying strings in text boxes

This is a discussion on Displaying strings in text boxes within the Windows Programming forums, part of the Platform Specific Boards category; Hi everyone, I am trying to use a Win32 textbox (EDITTEXT) to display certain words when you press certain buttons. ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    128

    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,185
    So, do you know anything about what printf is? Maybe you should read the manual.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    128
    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
    Registered User
    Join Date
    Feb 2010
    Posts
    128
    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,185
    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, 04: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, 11:18 AM
  4. Text Boxes
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 04-21-2002, 04:16 PM
  5. Text Boxes
    By gnu-ehacks in forum Windows Programming
    Replies: 1
    Last Post: 11-22-2001, 02:37 PM

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