• Welcome to Valhalla Legends Archive.
 

Simple Converting Help

Started by Spilled, June 14, 2005, 12:40 PM

Previous topic - Next topic

Spilled

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*)'

UserLoser.

Tried?

SetWindowText(TextBox, strString.c_str());

Spilled

#2

        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.

DarkMinion

#3

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


Much, much simpler.

OnlyMeat

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.

DarkMinion

He probably wants the title of the window to change as the text is typed...as in NBBot.

Arta

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().

Kp

strtol(3) and strtoul(3) are far superior to atoi! ;)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

K

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 or the boost::lexical_cast operator.

Kp

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!