Problem is solved with that fix:
http://support.microsoft.com/kb/2752274/en-us
WM_MOUSEWHEEL only works in one direction on Windows 7 / 64bits
-
01-12-2021 - |
Question
I made this code for 3D Effect in a Game, this code help change Possition and Zoom In + Out the screen!
But if I run it on win 7 64 bits, when scroll the mouse wheel, both forward and backward, it Zoom In only but it works correctly when run on Windows 7 32 bits!
How can I fix it for any win?
Thanks for any help!!!!
LRESULT CALLBACK MouseProc(int code, WPARAM wParam, LPARAM lParam)
{
MOUSEHOOKSTRUCTEX* mhs = (MOUSEHOOKSTRUCTEX*)lParam;
HWND MuWnd = FindWindow(TEXT("MU"), NULL);
if(UseCamera)
{
if(GetForegroundWindow() == MuWnd)
{
if(InitCamera)
{
Camera.ClipX = *Camera_ClipX;
Camera.ClipY = *Camera_ClipY;
Camera.GlClip = *Camera_GlClip;
Camera.PosZ = *Camera_PosZ;
Camera.RotY = *Camera_RotY;
Camera.RotZ = -45;
Camera.Zoom = *Camera_Zoom;
InitCamera = false;
}
else if(wParam == WM_MBUTTONDOWN)
{
MouseX = mhs->pt.x;
MouseY = mhs->pt.y;
MoveCamera = true;
}
else if(wParam == WM_MBUTTONUP)
{
MoveCamera = false;
}
else if(wParam == WM_MOUSEWHEEL)
{
int direction = mhs->mouseData;
if(direction < 0)
{
if(*Camera_Zoom < 60)
{
*Camera_Zoom += 2;
}
*Camera_ClipX = 1190 + (abs(*Camera_PosZ - 150) * 3) + 4000;
*Camera_ClipY = 2400 + (abs(*Camera_PosZ - 150) * 3) + 4000;
*Camera_GlClip = 2300 + (abs(*Camera_PosZ - 150) * 3) + 4000;
}
else if(direction > 0)
{
if(*Camera_Zoom > 12)
{
*Camera_Zoom -= 2;
}
*Camera_ClipX = 1190 + (abs(*Camera_PosZ - 150) * 3) + 4000;
*Camera_ClipY = 2400 + (abs(*Camera_PosZ - 150) * 3) + 4000;
*Camera_GlClip = 2300 + (abs(*Camera_PosZ - 150) * 3) + 4000;
}
}
else if(wParam == WM_MOUSEMOVE)
{
if(MoveCamera)
{
if(MouseX < mhs->pt.x)
{
*Camera_RotZ += 8;
if (*Camera_RotZ > 315) *Camera_RotZ = -45;
}
else if(MouseX > mhs->pt.x)
{
*Camera_RotZ -= 8;
if (*Camera_RotZ < -405) *Camera_RotZ = -45;
}
if(MouseY < mhs->pt.y)
{
if(*Camera_RotY < -45)
{
*Camera_PosZ -= 44;
*Camera_RotY += (double)2.42;
}
}
else if(MouseY > mhs->pt.y)
{
if(*Camera_RotY > -90)
{
*Camera_PosZ += 44;
*Camera_RotY -= (double)2.42;
}
}
MouseX = mhs->pt.x;
MouseY = mhs->pt.y;
*Camera_ClipX = 1190 + (abs(*Camera_PosZ - 150) * 3) + 4000;
*Camera_ClipY = 2400 + (abs(*Camera_PosZ - 150) * 3) + 4000;
*Camera_GlClip = 2300 + (abs(*Camera_PosZ - 150) * 3) + 4000;
}
}
}
}
return CallNextHookEx(MouseHook, code, wParam, lParam);
}
Solution
OTHER TIPS
From documentation you can read:
mouseData Type: DWORD If the message is WM_MOUSEWHEEL, the HIWORD of this member is the wheel delta. The LOWORD is undefined and reserved. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
So I guess that if you use HIWORD(mhs->mouseData) it could be better. Also note that the result is unsigned.
I solved this problem by testing in the WM_MOUSEWHEEL event by testing for non-zero... And then testing if-either '120' or not...
WM_MOUSEWHEEL:
if(HIWORD(wParam) == 120)
{
//Do Code for forward
}
else
{
//Do Code for reverse
}