2017-07-14 33 views
2

如果在按下Shift鍵時使用鼠標滾輪,我想實現水平滾動。但我並不在此情況下得到任何WM_MOUSEWHEEL消息:按下Shift鍵處理鼠標滾輪事件

procedure WMMouseWheel(var Msg: TMessage); message WM_MOUSEWHEEL; // is not called 

按照documentation,應該有一個WM_MOUSEWHEEL消息MK_SHIFT WPARAM。

任何想法?

+1

有很多信息:[如何指導鼠標滾輪輸入控制光標而不是聚焦?](https://stackoverflow.com/a/34386680/757830)和[如何添加鼠標滾輪是否支持TGraphicControl後續組件?](https://stackoverflow.com/a/34463279/757830)。 – NGLN

回答

5

我在代碼庫中找到這段代碼:

procedure TMyScrollBox.WndProc(var Message: TMessage); 
begin 
    if Message.Msg=WM_MOUSEHWHEEL then begin 
    (* For some reason using a message handler for WM_MOUSEHWHEEL doesn't work. 
     The messages don't always arrive. It seems to occur when both scroll bars 
     are active. Strangely, if we handle the message here, then the messages 
     all get through. Go figure! *) 
    if TWMMouseWheel(Message).Keys=0 then begin 
     HorzScrollBar.Position := HorzScrollBar.Position + TWMMouseWheel(Message).WheelDelta; 
     Message.Result := 0; 
    end else begin 
     Message.Result := 1; 
    end; 
    end else begin 
    inherited; 
    end; 
end; 

所以,你有它。我不明白爲什麼會出現這種情況,但您應該可以像我這樣做,並覆蓋WndProc來處理此消息。

+1

[鼠標滾輪的奧德賽](https://stackoverflow.com/a/34386680/757830) – NGLN