Valhalla Legends Forums Archive | C/C++ Programming | Simple Converting Help

AuthorMessageTime
Spilled[DW]
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.

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

Error: cannot convert `std::string' to `const CHAR*' for argument `2' to `BOOL SetWindowTextA(HWND__*, const CHAR*)'
June 14, 2005, 5:40 PM
UserLoser.
Tried?
[code]
SetWindowText(TextBox, strString.c_str());
[/code]
June 14, 2005, 6:05 PM
Spilled[DW]
[code]
        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;
                    }
[/code]

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.
June 14, 2005, 7:48 PM
DarkMinion
[code]
                    case EN_CHANGE:
                         int wtl = GetWindowTextLength(SendBar);
                         char wt[wtl + 1];
                         GetWindowText(SendBar, wt, sizeof(wt));
                         SetWindowText(TextBox, wt);
[/code]

Much, much simpler.
June 14, 2005, 8:45 PM
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:

[code]
wParam / 0x10000
[/code]

Use this instead:-
[code]
HIWORD(wParam)
[/code]

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.
June 14, 2005, 9:48 PM
DarkMinion
He probably wants the title of the window to change as the text is typed...as in NBBot.
June 14, 2005, 10:08 PM
Arta
[quote author=Spilled[DW] link=topic=11827.msg115735#msg115735 date=1118778495]
Also how would i go about converting a string into an integer? Thanks again.
[/quote]

See atoi().
June 14, 2005, 10:56 PM
Kp
strtol(3) and strtoul(3) are far superior to atoi! ;)
June 15, 2005, 2:29 AM
K
[quote author=Kp link=topic=11827.msg115817#msg115817 date=1118802565]
strtol(3) and strtoul(3) are far superior to atoi! ;)
[/quote]

While we're listing our favorites, you could also use a std::stringstream or the boost::lexical_cast operator.
June 15, 2005, 5:16 PM
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.
June 16, 2005, 3:11 AM

Search