I am attempting to implement support for the horizontal scroll wheel in various of my own custom VCL controls, but it seems to be tricky, at least if you are using the Logitech MX Master mouse.
To be concrete, let's drop an ordinary TScrollBox
on a form and add a few child controls:
Without adding any code, I am not able to scroll it vertically using the primary mouse wheel. Scrolling the wheel, nothing happens, as expected.
However, if I resize the form to make the horizontal scroll bar appear and use the thumb wheel on my MX Master mouse to scroll horizontally, a strange thing happens: the horizontal scroll bar becomes unthemed and moves according to the wheel, but the client area isn't scrolled:
That's odd, isn't it?
Well, by implementing an OnMouseWheel
handler, it is trivial to make the main scroll wheel scroll vertically:
procedure TForm1.ScrollBox1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - WheelDelta;
Handled := True
end;
To get the secondary scroll wheel to do horizontal scrolling, I try
procedure TScrollBox.WndProc(var Message: TMessage);
begin
case Message.Msg of
WM_MOUSEHWHEEL:
begin
HorzScrollBar.Position := HorzScrollBar.Position + TWMMouseWheel(Message).WheelDelta;
Message.Result := 0;
end;
else
inherited;
end;
end;
to no avail.
However, if I change Message.Result
to 1
(ignoring the documentation which states otherwise), it works as expected as long as the mouse is not above any windowed child control.
I seem to recall that my old Microsoft Touch Mouse was able to scroll horizontally without any issues. Also, Google suggests that many end users have issues with horizontal scrolling using the MX Master. Still, I am able to use my MX Master to scroll horizontally in web browsers, Microsoft Office, Notepad, and Paint.
What is the correct way to implement support for horizontal scrolling? And, if the correct approach is incompatible with the MX Master, is there any way to work around this incompatibility? After all, it is a common pointing device from a major manufacturer.