GET_WHEEL_DELTA_WPARAM永远不会返回负数

时间:2013-03-20 16:04:43

标签: c++ winapi

我只看到从GET_WHEEL_DELTA_WPARAM返回的正数,即使它应该是负数,因为我向我滚动鼠标滚轮。

case WM_MOUSEWHEEL:
            short wheel_delta = 0;
            wheel_delta = GET_WHEEL_DELTA_WPARAM(Addtl_Info_L);

此外,此页面here表示滚动向前滚轮给出正数而向后滚动为负数,而此页面here表示它是向左和向右而不是向前和向后。

这是完整的消息处理程序:

            LRESULT CALLBACK Message_Handler(HWND App_Handle, UINT Message_Type, WPARAM Addtl_Info_W, LPARAM Addtl_Info_L) {
                short wheel_delta(0);
                switch(Message_Type) {
                case WM_MOUSEWHEEL:
                    wheel_delta = GET_WHEEL_DELTA_WPARAM(Addtl_Info_L);
                    if (wheel_delta > 0) {
                        std::wostringstream outs;  
                        outs << "Wheel delta is positive" << std::endl;
                        OutputDebugString(outs.str().c_str());
                        graphics_manager.camera_tilt = graphics_manager.camera_tilt + 0.1f;
                    } else if (wheel_delta < 0) {
                        std::wostringstream outs;  
                        outs << "Wheel delta is negative" << std::endl;
                        OutputDebugString(outs.str().c_str());
                        graphics_manager.camera_tilt = graphics_manager.camera_tilt - 0.1f;
                    }
                    return 0;
                }
                return DefWindowProc(App_Handle, Message_Type, Addtl_Info_W, Addtl_Info_L);
            }

2 个答案:

答案 0 :(得分:2)

您正在将LPARAM传递给GET_WHEEL_DELTA_WPARAM。您应该传递WPARAMAddtl_Info_W,而不是Addtl_Info_L)。

答案 1 :(得分:1)

您应该显示整个消息循环,或者至少在定义“Addtl_Info_L”的地方,因为它应该是wParam“win32msg-&gt; wParam”。

#define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam)) 

也许您将短值转换为unsigned int或在测试中使用无符号格式字符串输出short值?您可以使用条件来检查否定结果。

if(wheel_delta < 0) { /* do something */ }