无法输出游标位置到调试字符串(WIN32)
Cannot output cursor location to debug string (WIN32)
由于某些原因,当我试图使用以下代码在给定的WIN32窗口中输出鼠标光标的位置时:
//Global Variable
POINT cursorLocation;
// Win32 Windowing subsystem code redacted
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
cursorLocation.x = GET_X_LPARAM(lParam);
cursorLocation.y = GET_Y_LPARAM(lParam);
switch(message){
case WM_MOUSEMOVE:
// mouse movement handle
OutputDebugString(cursorLocation.x + "," + cursorLocation.y);
OutputDebugString("n");
// WM_MOUSEMOVE break
break;
}
}
现在,当我运行程序并移动鼠标时,以下文本被记录到控制台:
较小的数据类型导致数据丢失。
如果这是有意的,你应该用适当的位掩码来屏蔽转换的源。
例如:char c = (i &
0 xff);以这种方式更改代码不会影响最终优化代码的质量。
我甚至尝试将传递给OutputDebugString
的变量类型转换为LONG
,因为这是POINT
类中变量的类型,并且没有差异。
有人知道如何通过GET_X_LPARAM
和GET_Y_LPARAM
将值传递到调试控制台吗?谢谢。
这不是字符串连接,而是将.x
和.y
添加到指向","
的指针:
cursorLocation.x + "," + cursorLocation.y
例如:
char s[256];
sprintf_s(s, "%d,%d", cursorLocation.x, cursorLocation.y);
OutputDebugStringA(s); // added 'A' after @IInspectable's comment, but
// using UNICODE and wchar_t might be better indeed
字符串连接不适用于整数。尝试使用std::ostringstream
:
std::ostringstream out_stream;
out_stream << cursorLocation.x << ", " << cursorLocation.y;
OuputDebugString(out_stream.str().c_str());
相关文章:
- C++/Win32 构造函数不使用从对话框获取的字符串初始化变量
- 如何使用 Win32 WCHAR 执行字符串操作
- Win32中的任何易于使用的哈希功能都可以放置ASCII字符串
- Win32 API VS C++;要字符串的文本框内容
- wostringstream,Ascii,Unicode,Win32和整数连接到字符串
- 如何在 win32 或 MFC 中按名称获取字符串资源
- C++ Win32:基本字符串处理
- 旧版 Win32 DLL 中的空终止字符串 C++ - 有没有更好的方法
- 使用发送消息设置文本框文本 设置文本仅发送字符串 win32 c++ 的第一个字符
- c++win32 DLL-需要动态加载base64字符串(非常奇怪!)
- C++ Win32 是字符串问题
- win32 C++中的字符串比较
- 哪种类型的字符串最适合用于Win32和DirectX
- 无法输出游标位置到调试字符串(WIN32)
- 获取Win32系统日期格式字符串
- 关于将字符串传递给win32 api函数
- 在c++ (WIN32)中测试SQL连接字符串
- 是否有win32 API将字符串转换为字符数组?
- 当我使用 win32 发送消息发送和转换标准字符串时,我得到奇怪的字符
- 从Win32 RPC调用返回字符串