I wrote the following code:
procedure MouseWheel(var Msg:TWMMouseWheel);message WM_MOUSEHWHEEL;
I used it for a component based on TPanel (TMyP=class(TPanel))
(Notice that I don't want to use TCustomPanel due to my own reasons)
But anyway the event is not called when I use mouse wheel on the panel. Please Help me!
The mouse wheel messages are sent to the control with the focus. And panels usually aren't focusable.
I use this TApplicationEvents.OnMessage handler in my applications to send the mouse wheel message to the window under the mouse cursor instead of the focused control.
procedure TMainDataModule.ApplicationEventsMessage(var Msg: tagMSG; var Handled: Boolean);
var
  Wnd: HWND;
begin
  if Msg.message = WM_MOUSEWHEEL then
  begin
    Wnd := WindowFromPoint(Msg.pt);
    // It must be a VCL control otherwise we could get access violations
    if IsVCLControl(Wnd) then
      Msg.hwnd := Wnd; // change the message receiver to the control under the cursor
  end;
end;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With