Delphi 10.3 how messages routing in wincontrols work

144 Views Asked by At

I have this type of problem:

I need to be able to know when mouse cursor is inside my custom wincontrol that have other custom controls on it. Let me explain in a more graphical way:

my custom scroll box with buttons on it

component tree:
TForm
  |-- TMyCustomScrollBox
        |-- TMyCustomButton
        |-- TMyCustomButton
        |-- TMyCustomButton
        ...

TMyCustomButton controls are aligned alTop

Some explanation on what i do right now:

  • i have captured CMMouseEnter and CMMouseLeave and WMMouseMove events on TMyCustomButton,
  • and also am capturing CMMouseEnter and CMMouseLeave and WMMouseMove events on TMyCustomScrollBox,
  • now i want TMyCustomScrollBox to know that mouse is inside of TMyCustomButton,
  • i want to know when mouse leaves TMyCustomButton and if it is still inside TMyCustomScrollBox,
  • and if mouse leaves TMyCustomScrollBox, i need to be able to capture CMMouseLeave on it.

What should i do to correctly do this, how to push messages from TMyCustomButton to TMyCustomScrollBox, because now i'm calling inherited inside CMMouseEnter / CMMouseLeave / WMMouseMove events, like:

procedure TUItemButton.CMMouseEnter(var Msg: TMessage);
begin
  if Enabled then begin
    ButtonState := csHover;
  end;
  inherited;
end;

procedure TUItemButton.CMMouseLeave(var Msg: TMessage);
begin
  if Enabled then begin
    ButtonState := csNone;
  end;
  inherited;
end;

procedure TUItemButton.WMMouseMove(var Msg: TWMMouseMove);
begin
  if Enabled then
    Repaint;
  inherited;
end;

Does inherited means: push this events to they'r corresponding parent wincontrol ?

0

There are 0 best solutions below