Delphi 7 - Handling MouseWheel events for inline frames in forms?

Hi I have a form with several frames inside.

For some frames, I want to scroll through the contents (or at least handle the mousewheel event).

I tried the following:

Just assign an OnMouseWheel event handler to each frame

Overriding the MouseWheel event for the parent form:

procedure TFmReview.MouseWheelHandler(var Message: TMessage); var Control: TControl; begin Control := ControlAtPos(ScreenToClient(SmallPointToPoint(TWMMouseWheel(Message).Pos)), False, True); if Assigned(Control) and (Control <> ActiveControl) then begin ShowMessage(Control.Name); Message.Result := Control.Perform(CM_MOUSEWHEEL, Message.WParam, Message.LParam); if Message.Result = 0 then Control.DefaultHandler(Message); end else inherited MouseWheelHandler(Message); end; 

Unfortunately, both do not work.

  • In case 1, the event never fires, but the parent forms the mouse wheel handler.
  • In case 2, the control that receives the focus is the panel in which the frame to which I want to send the mouse event is located.

So just tell me, how can I direct the mousewheel event to the topmost control that the mouse cursor has ended over (regardless of which frame / parent / form, etc. the cursor is on)?

+6
source share
1 answer

To postpone the processing of the mouse wheel until TWinControl , over which the mouse cursor is currently located, redefine the MouseWheelHandler form in its main frame using the following code:

 type TMainForm = class(TForm) private procedure MouseWheelHandler(var AMessage: TMessage); override; public { Public declarations } end; implementation procedure TMainForm.MouseWheelHandler(var AMessage: TMessage); var Control: TWinControl; begin Control := FindVCLWindow(SmallPointToPoint(TWMMouseWheel(AMessage).Pos)); if Assigned(Control) then begin AMessage.Result := Control.Perform(CM_MOUSEWHEEL, AMessage.WParam, AMessage.LParam); if AMessage.Result = 0 then Control.DefaultHandler(AMessage); end else inherited MouseWheelHandler(AMessage); end; 
+1
source

Source: https://habr.com/ru/post/901187/


All Articles