I just had to look up the WM_ representation for the mouse scroll, so that I can activate my game camera zoom, more freely, rather than using the arrow keys (which was fun at first)

So, I tried implementing the WM_MOUSEWHEEL into the message loop and created a switch statement for it, and then created an additional switch statement for GET_WHEEL_DELTA_WPARAM(wParam)
and then it hit me:
what does this function return, and how can I put it in a switch structure.

Now the MSDN documentation is fabulous, just great, except it lacks examples. All it mentioned was that if the mousewheel is scrolled away from the user, it returns a positive value and if it is scrolled towards the user it returns a negative value.

Huh, what value?

Constructive criticism, suggestions and anything of the kind is very welcome. (this code is altered, removed most unnecessary code)

LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    PAINTSTRUCT ps;
    HDC hdc;

    switch( message )
    {
	case WM_PAINT:
			{
            hdc = BeginPaint( hWnd, &ps );
            EndPaint( hWnd, &ps );
			}
            break;
		case WM_MOUSEMOVE:
			{
			}
			break;
		case WM_MOUSEWHEEL:
			{
				switch(GET_WHEEL_DELTA_WPARAM(wParam)){
					case 1: //Well, it clearly doesn't return a 1
						PostQuitMessage(0);
						break;
				}
			}
			break;
		case WM_KEYDOWN:
			{
				int virtual_key = (int)wParam;
				int key_bits = (int)lParam;
				switch(virtual_key){
				case VK_ESCAPE:
					PostQuitMessage( 0 );
					break;
				case VK_UP:{
					ZOOM += 0.5f;		   
							   }
					break;
				case VK_DOWN:{
					ZOOM -= 0.5f;		   
							   }
					break;
				case VK_LEFT:{
					LOOKAT -= 0.5f;		   
							   }
					break;
				case VK_RIGHT:{
					LOOKAT += 0.5f;		   
							   }
					break;
				default:
					break;
				}
			}
			break;
        case WM_DESTROY:
            PostQuitMessage( 0 );
            break;

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

    return 0;
}

Recommended Answers

All 3 Replies

I remember having problems with the wheel scroll, I think the return value is WHEEL_DELTA if the scroll is up, and -WHEEL_DELTA if the scroll is down.

Hope this helps.

Thanks!
After looking up what the WHEEL_DELTA was, I am ashamed to admit that MSDN did mention a return of 120 (WHEEL_DELTA = 120), although that section to me was a bit blurry.
Anyone care to further explain what they mean; why is it 120?

Anyway, thanks a bunch.

case WM_MOUSEWHEEL:
{  
    int delta = GET_WHEEL_DELTA_WPARAM(wparam);
    if(delta > 0)
    {
        //Mouse Wheel Up
    }
    else
    {
        //Mouse Wheel Down
    }

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.