Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: Spilled on June 14, 2005, 12:40 PM

Title: Simple Converting Help
Post by: Spilled on June 14, 2005, 12:40 PM
I'm having a hard time setting my text to my chat window. I've tried plenty of things but cant get it to work. Always get this error saying i cannot convert. Any help is appreciated thanks all. No Flaming please simple question.


       int wtl;
       wtl = GetWindowTextLength(SendBar);
       char wt[wtl];
       std::string strString;
       strString = GetWindowText(SendBar, wt, wtl);
       SetWindowText(TextBox, strString);


Error: cannot convert `std::string' to `const CHAR*' for argument `2' to `BOOL SetWindowTextA(HWND__*, const CHAR*)'
Title: Re: Simple Converting Help
Post by: UserLoser. on June 14, 2005, 01:05 PM
Tried?

SetWindowText(TextBox, strString.c_str());
Title: Re: Simple Converting Help
Post by: Spilled on June 14, 2005, 02:48 PM

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
               case Send_Bar:
                    switch(wParam / 0x10000)
                    {
                    case EN_CHANGE:
                         int wtl;
                         wtl = GetWindowTextLength(SendBar);
                         char wt[wtl];
                         std::string strString;
                         strString = GetWindowText(SendBar, wt, wtl);
                         SetWindowText(TextBox, strString.c_str());
                    break;
                    }


With this i enter anything in the send bar and it closes, ideas?

Edit:
Also how would i go about converting a string into an integer? Thanks again.
Title: Re: Simple Converting Help
Post by: DarkMinion on June 14, 2005, 03:45 PM

                    case EN_CHANGE:
                         int wtl = GetWindowTextLength(SendBar);
                         char wt[wtl + 1];
                         GetWindowText(SendBar, wt, sizeof(wt));
                         SetWindowText(TextBox, wt);


Much, much simpler.
Title: Re: Simple Converting Help
Post by: OnlyMeat on June 14, 2005, 04:48 PM
A couple of points to the original poster. Firstly EN_CHANGE message can be extracted by using the HIWORD macro, there is no need to do this:


wParam / 0x10000


Use this instead:-

HIWORD(wParam)


Secondly, you do realize that a EN_CHANGE is sent to you for every change, ie. when a single character is typed. It might be more appropriate to copy the text when the user presses a button or something and do it in one go.
Title: Re: Simple Converting Help
Post by: DarkMinion on June 14, 2005, 05:08 PM
He probably wants the title of the window to change as the text is typed...as in NBBot.
Title: Re: Simple Converting Help
Post by: Arta on June 14, 2005, 05:56 PM
Quote from: Spilled[DW] on June 14, 2005, 02:48 PM
Also how would i go about converting a string into an integer? Thanks again.

See atoi() (http://www.cplusplus.com/ref/cstdlib/atoi.html).
Title: Re: Simple Converting Help
Post by: Kp on June 14, 2005, 09:29 PM
strtol(3) and strtoul(3) are far superior to atoi! ;)
Title: Re: Simple Converting Help
Post by: K on June 15, 2005, 12:16 PM
Quote from: Kp on June 14, 2005, 09:29 PM
strtol(3) and strtoul(3) are far superior to atoi! ;)

While we're listing our favorites, you could also use a std::stringstream (http://www.cplusplus.com/ref/iostream/stringstream/) or the boost::lexical_cast (http://www.boost.org/libs/conversion/lexical_cast.htm) operator.
Title: Re: Simple Converting Help
Post by: Kp on June 15, 2005, 10:11 PM
It doesn't matter for this particular poster, but it's worth pointing out that both my suggestion and Arta's work in a pure C environment, whereas K's do not.