Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WMMouseWheel not working in Delphi

Tags:

delphi

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!

like image 889
Javid Avatar asked Dec 03 '22 10:12

Javid


1 Answers

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;
like image 113
Andreas Hausladen Avatar answered Dec 21 '22 16:12

Andreas Hausladen