WM_MOUSEWHEEL仅在Windows 7/64位上以一个方向工作

时间:2012-11-22 08:18:20

标签: visual-c++ windows-7-x64 mousewheel mouse-hook

我在游戏中为3D效果制作了此代码,此代码有助于更改Possition和放大+屏幕!

但是如果我在win 7 64位上运行它,当向前和向后滚动鼠标滚轮时,它只放大但在Windows 7 32位运行时它可以正常工作!

如何解决任何胜利? 谢谢你的帮助!!!!

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);
}

3 个答案:

答案 0 :(得分:3)

通过该修复解决了问题:
http://support.microsoft.com/kb/2752274/en-us

答案 1 :(得分:1)

您可以阅读文档:

mouseData 键入:DWORD 如果消息是WM_MOUSEWHEEL,则该成员的HIWORD是轮子增量。 LOWORD未定义并保留。正值表示车轮向前旋转,远离用户;负值表示车轮向后旋转,朝向用户。单轮定位被定义为WHEEL_DELTA,即120。

所以我想如果你使用HIWORD(mhs-> mouseData),那可能会更好。另请注意,结果是无符号的。

答案 2 :(得分:0)

我通过在 WM_MOUSEWHEEL 事件中测试非零来解决这个问题... 然后测试是否为“120”...

WM_MOUSEWHEEL:
if(HIWORD(wParam) == 120)
{
//Do Code for forward
}
else
{ 
//Do Code for reverse
}