How to prevent focused control from scrolling when the mouse isn't over it?

梦想与她 提交于 2019-12-06 13:34:24

This code works fine for me.

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
  Control: TWinControl;
begin

  if Msg.message = WM_MOUSEWHEEL then
  begin
    // Find control at mouse cursor
    Control := FindVCLWindow(Msg.pt);

    if Assigned(Control) then
    begin
      // Try to scroll
      if Control.Perform(CM_MOUSEWHEEL, Msg.wParam, Msg.lParam) <> 0 then
        Handled := True
      else
      // If no scroll was performed by control,
      // then detrmine if message control is at mouse cursor.
      // If not, then supress message
      if Control.Handle <> Msg.hwnd then
        Handled := True;
    end;
  end;

end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!