win32 WM_SETTEXT not working
win32 WM_SETTEXT not working
我做了一个像这样的小文本框
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);
一切正常但是当我尝试像这样改变里面的文本时,我遇到了一些问题
SendMessage(EBX, WM_SETTEXT, 0, (LPARAM)"12"); // working
int a = 40;
SendMessage(EBX, WM_SETTEXT, 0, (LPARAM)a); // not working
你知道怎么回事吗?
40不是字符串,"40"是。如果要将数字转换为字符串,必须使用sprintf
等函数。
。
int a = 40;
char str[20];
StringCchPrintf(str, _countof(str), "%ld", a);
SendMessage(EBX, WM_SETTEXT, 0, (LPARAM)str);
不能盲目地将int类型转换为char*,使用sprintf、stringstream或std::to_string创建包含int值的文字表示形式的字符串。
或者,如果你想输出值为40的字符,你需要传递指针到null终止字符数组。像
char str[2];
str[0]=40;
str[1]=0;
将40转换为c-string并在sendmessage函数中使用
char buffer [33];
int i =40;
itoa (i,buffer,10);
SendMessage(EBX, WM_SETTEXT, 0, (LPARAM)buffer);
相关文章:
- GDB - strcmp not working: __strcmp_sse2_unaligned
- QT qScriptConnect is not working
- QDesktopServices::openUrl() not working Qt
- C++ std::set ordering not working with customer class*
- C++ SetWindowText not working
- visual studio 2012 c++ hello world - iostream not working
- getGravity not working?
- Opencv findcontours CV_RETR_EXTERNAL not working
- c++ srand() not working
- std::queue::empty() not working?
- BCB swprintf not working
- 将类型作为指向另一个类的对象的指针的泛型类-NOT WORKING
- LoadLibrary is not working
- gluUnProject not working
- C++ catch bad_alloc not working
- updatelayeredwindow not working
- OpenMP set_num_threads() is not working
- glOrtho not working
- Cuda atomicInc not working
- WinAPI DestroyWindow not working