2

I want to implement horizontal scrolling if the mouse wheel is used while the Shiftkey is pressed. But I do not get any WM_MOUSEWHEEL messages in this case:

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

According to the documentation, there should be a WM_MOUSEWHEEL message with MK_SHIFT WPARAM.

Any ideas?

jpfollenius
  • 16,456
  • 10
  • 90
  • 156
  • 1
    There is a lot of information at: [How to direct the mouse wheel input to control under cursor instead of focused?](https://stackoverflow.com/a/34386680/757830) and [How to add mouse wheel support to a component descended from TGraphicControl?](https://stackoverflow.com/a/34463279/757830). – NGLN Jul 14 '17 at 12:13

1 Answers1

6

Edit: the following code uses WM_MOUSEHWHEEL, not WM_MOUSEWHEEL to handle horizontal scrolling.

I find this code in my code base:

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;

So, there you have it. I don't understand why this is so, but you should be able to do the same as I do, and override WndProc to process this message.

Karsten
  • 2,772
  • 17
  • 22
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490