[英]win32 WM_SETTEXT not working
i made a small textbox like this 我做了一个像这样的小文本框
EBX = CreateWindow(TEXT("EDIT"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_NUMBER | WS_BORDER,
client.right - offset[1] - 200, client.top + offset[2] - 27,
45, 25, hwnd, (HMENU)ID_EDIT_SPEED, NULL, NULL);
everything is fine there but when i try to change the text inside like this i got some problems 一切都很好,但当我试图改变这里面的文字时,我遇到了一些问题
SendMessage(EBX, WM_SETTEXT, 0, (LPARAM)"12"); // working
int a = 40;
SendMessage(EBX, WM_SETTEXT, 0, (LPARAM)a); // not working
any idea what is wrong ? 知道什么是错的吗?
You cannot, blindly typecast int to char*, use sprintf, stringstream or std::to_string to create string that holds literal representation of int value. 你不能盲目地将int转换为char *,使用sprintf,stringstream或std :: to_string来创建保存int值的文字表示的字符串。
Or if you want to otput char with value 40 you need to pass pointer to null terminate array of chars. 或者,如果要使用值40输出char,则需要将指针传递给null终止字符数组。 Like 喜欢
char str[2];
str[0]=40;
str[1]=0;
40 is not a string, "40" is. 40不是字符串,“40”是。 If you want to convert a number to a string you must use a function like sprintf
, etc. 如果要将数字转换为字符串,则必须使用sprintf
等函数。
Eg 例如
int a = 40;
char str[20];
StringCchPrintf(str, _countof(str), "%ld", a);
SendMessage(EBX, WM_SETTEXT, 0, (LPARAM)str);
convert 40 to c-string and use it in sendmessage function 将40转换为c-string并在sendmessage函数中使用它
char buffer [33];
int i =40;
itoa (i,buffer,10);
SendMessage(EBX, WM_SETTEXT, 0, (LPARAM)buffer);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.