gpt4 book ai didi

c++ - RAWINPUT - 如何获取鼠标滚轮数据

转载 作者:搜寻专家 更新时间:2023-10-31 00:18:57 26 4
gpt4 key购买 nike

我将 rawinput 与 directx 一起使用...我正在尝试在使用鼠标滚轮时使用相机进行缩放...当我使用以下代码运行程序时,我从 usbuttondata 的 rawinput 获取的数据会出现当我向前插入鼠标滚轮时到 120...然后它失去控制...高达 65000...我认为数据应该是 1 或 -1 或 0...rawinput 作为鼠标发送什么车轮数据?

代码:

LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
{
RAWINPUTDEVICE Rid[2];
// Keyboard
Rid[0].usUsagePage = 1;
Rid[0].usUsage = 6;
Rid[0].dwFlags = 0;
Rid[0].hwndTarget=Inst.Wnd.hWnd;

// Mouse
Rid[1].usUsagePage = 1;
Rid[1].usUsage = 2;
Rid[1].dwFlags = 0;
Rid[1].hwndTarget=Inst.Wnd.hWnd;
if (!RegisterRawInputDevices(Rid,2,sizeof(RAWINPUTDEVICE)))
{
MessageBox(NULL, L"Failed to Register Input Devices!", L"ALERT", MB_OK);
exit(1);
}
return 0;
}
case WM_INPUT:
{
// Determine how big the buffer should be
UINT iBuffer;

GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &iBuffer,
sizeof(RAWINPUTHEADER));
LPBYTE lpb = new BYTE[iBuffer];
if (lpb == NULL)
{
return 0;
}

UINT readSize = GetRawInputData( (HRAWINPUT)lParam, RID_INPUT, lpb, &iBuffer, sizeof(RAWINPUTHEADER) ) ;

if( readSize != iBuffer )
puts( "ERROR: GetRawInputData didn't return correct size!" ) ;
RAWINPUT *raw = (RAWINPUT*) lpb;

if (raw->header.dwType== RIM_TYPEMOUSE)
{
riProcessMouseMessage(&raw->data.mouse);
}
if (raw->header.dwType== RIM_TYPEKEYBOARD)
{
//riProcessKeyboardMessage(&raw->data.keyboard);
}
}
return 0;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_FILE_NEW:
{
// Create the game object
pGame = new CGame(dxMgr.getD3DDevice());

// Initialize the game object
if (!pGame->init(Inst.Wnd.hWnd))
return 0;
break;
}
case IDM_FILE_OPEN:
pGame->m_animCollection->LoadXFile("oxana.x", 0);
//objects.CreateNewObject(1, L"oxana.x", NULL);
break;

case IDM_FILE_SAVE:

break;

case IDM_FILE_SAVEAS:
break;

case IDM_FILE_EXIT:
PostQuitMessage(WM_QUIT);
break;
}
return 0;

case WM_DESTROY:
PostQuitMessage(WM_QUIT);
return 0;

default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return TRUE;
}

void riProcessMouseMessage( const RAWMOUSE* rmouse )
{
if(pGame != NULL)
{
//MessageBox(NULL, L"Game Found", L"SUCCESS", MB_OK);
if ( MOUSE_MOVE_RELATIVE == rmouse->usFlags )
{
riMgr.mxr = &rmouse->lLastX;
riMgr.myr = &rmouse->lLastY;
}
riMgr.mzr = (RI_MOUSE_WHEEL & rmouse->usButtonFlags) ? &rmouse->usButtonData : 0;
}
}

最佳答案

我怀疑它与 WM_MOUSEWHEEL 相同:

高位字表示轮子旋转的距离,用WHEEL_DELTA的倍数或除数表示,即120。正值表示轮子向前旋转,远离用户;负值表示滚轮向后旋转,朝向用户。低位字表示各个虚拟键是否按下。

因此需要提取高阶词。您需要注意正确处理负值。您可能不会这样做,因为您会获得很大的值(value)。

如果您愿意,可以为此使用以下宏:GET_WHEEL_DELTA_WPARAM(wParam)

关于c++ - RAWINPUT - 如何获取鼠标滚轮数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9245303/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com