Mousewheel handling

Giganews Newsgroups
Subject: Mousewheel handling
Posted by:  Christian Kaufmann (christian.kaufma…@gmx.net)
Date: Tue, 30 Aug 2011

Hi,

I did the following change in my TForm subclass to have a different
mousewheel behaviour:

procedure TBSForm.MouseWheelHandler(var Message: TMessage);
var
  ctrl: TControl;
begin
  // MouseWheel should be handled by control at CursorPos
  // and not by FocusedControl
  ctrl := FindVCLWindow(Mouse.CursorPos);
  if Assigned(ctrl) and (ctrl <> ActiveControl)  then begin
    Message.Result := ctrl.Perform(CM_MOUSEWHEEL, Message.WParam,
Message.LParam);
    if Message.Result = 0 then
      ctrl.DefaultHandler(Message);
  end
  else
    inherited MouseWheelHandler(Message);
end;

The problem is, that if somebody uses the mousewheel on a button
directly on the form, this ends in a recursion.

What is wrong with my method?

cu Christian

Replies