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*)'
Tried?
SetWindowText(TextBox, strString.c_str());
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.
case EN_CHANGE:
int wtl = GetWindowTextLength(SendBar);
char wt[wtl + 1];
GetWindowText(SendBar, wt, sizeof(wt));
SetWindowText(TextBox, wt);
Much, much simpler.
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.
He probably wants the title of the window to change as the text is typed...as in NBBot.
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).
strtol(3) and strtoul(3) are far superior to atoi! ;)
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.
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.