win32 窗口过程函数中获取详细的鼠标消息
[編輯] [转简体] (简体译文)
|
作者:huidong
| 分類:【編程】Win32
[
24 瀏覽
0 評論
11 贊
10 踩
]
概要
正文
关于这个内容,我参考了一篇文章:https://blog.csdn.net/bimabushihaodongxi/article/details/70942975
2022.07.29 更新
WM_MOUSEWHEEL 消息特殊处理:http://huidong.xyz/index.php?mode=2&id=448
总结一下吧,在窗口过程函数中把鼠标消息整合成一个 EasyX 的 ExMessage,就像下面这样,很浓缩了。
// 消息记录 switch (msg) { // EM_MOUSE case WM_MOUSEMOVE: case WM_MOUSEWHEEL: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MBUTTONDBLCLK: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_RBUTTONDBLCLK: { ExMessage msgMouse = {}; msgMouse.message = msg; msgMouse.x = GET_X_LPARAM(lParam); msgMouse.y = GET_Y_LPARAM(lParam); msgMouse.wheel = GET_WHEEL_DELTA_WPARAM(wParam); msgMouse.shift = LOWORD(wParam) & 0x04 ? true : false; msgMouse.ctrl = LOWORD(wParam) & 0x08 ? true : false; msgMouse.lbutton = LOWORD(wParam) & 0x01 ? true : false; msgMouse.mbutton = LOWORD(wParam) & 0x10 ? true : false; msgMouse.rbutton = LOWORD(wParam) & 0x02 ? true : false; // 有滚轮消息时,得到的坐标是屏幕坐标,需要转换 if (msgMouse.wheel) { POINT p = { msgMouse.x ,msgMouse.y }; ScreenToClient(g_vecWindows[indexWnd].hWnd, &p); msgMouse.x = (short)p.x; msgMouse.y = (short)p.y; } g_vecWindows[indexWnd].vecMessage.push_back(msgMouse); } break;