[DUG] Override MouseWheelHandler

Ross Levis ross at stationplaylist.com
Thu Jan 13 18:50:22 NZDT 2011


I found this procedure to scroll the control the mouse is over when using
the mouse wheel, not just the focused control.

 

procedure TMainForm.MouseWheelHandler(var Message: TMessage);

var

  Control: TWinControl;

begin

  Control := FindVCLWindow(Mouse.CursorPos);

  if Assigned(Control) and (Control <> ActiveControl) then

  with Message do

  begin

    Result := Control.Perform(CM_MOUSEWHEEL, WParam, LParam);

    if Result = 0 then Control.DefaultHandler(Message)

  end

  else inherited MouseWheelHandler(Message);

end;

 

This works well when the mouse is over a control that supports scrolling,
but crashes in the TWinControl.DefaultHandler procedure at CallWindowProc,
when over other controls.  I'm not sure how to prevent this error.  Even a
try/except to ignore the error doesn't work.  Any ideas?

 

Cheers,
Ross.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20110113/6b8918db/attachment.html 


More information about the Delphi mailing list