1

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);
}
  • 1
    possible duplicate of [About WM\_MOUSEWHEEL! can not catch direction of mouse wheel](http://stackoverflow.com/questions/13505257/about-wm-mousewheel-can-not-catch-direction-of-mouse-wheel) – Michael Burr Nov 22 '12 at 09:41

3 Answers3

3

Problem is solved with that fix:
http://support.microsoft.com/kb/2752274/en-us

  • 1
    Link's dead. Also, please refrain from posting "link only" solutions for the exact same reason. Could you please provide details as an edit to your original answer? – Julian Kirsch Jun 06 '20 at 21:07
1

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.

pagra
  • 665
  • 4
  • 11
  • Thanks! But if the result is unsigned, What can i do with "direction" variable? in order to detect when mouse wheel was rotated forward or backward? I tried "unsigned int direction = HIWORD(mhs->mouseData);" And tried export the result to output.txt, and although I rotate the mouse wheel forward or backward, the result is alway is 30378! – Công Quyền Knight Nov 22 '12 at 09:28
  • 1
    To test the sign just cast it to short before: (short)HIWORD(mhs->mouseData) – pagra Nov 22 '12 at 09:49
  • I tried ` ofstream myfile; myfile.open("output.txt",fstream::in | fstream::out | fstream::app); myfile<< (short)HIWORD(mhs->mouseData) << '\n'; myfile.close();` But the result is alway same 30278 or another possitive value (it change only when i restart the application) – Công Quyền Knight Nov 22 '12 at 10:11
  • Could you please help me more? :( Thanks you – Công Quyền Knight Nov 22 '12 at 10:54
0

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
}