Can we change the event routing strategy in Windows?

In .NET forms, a form has a collection of controls and internally they all simply wrap the windowing subsystem provided by Microsoft windows. Just like MFC, which is a small wrapper around the api window. Form / window controls create a tree structure, and events take leaf nodes, for example. The MouseMove event will receive a window / control directly under the mouse.

But in the presentation environment, microsoft provided a RoutedEvent , which may have one of the following strategies

  • Tunnel A routed event uses a tunneling strategy where an instance of an event moves down through a tree, from the root to the source element.
  • Bubble A routed event uses a bubbling strategy where an instance of the event is routed up the tree, from the source of the event to the root.
  • The direct routed event does not route through the element tree.

I assume that the presentation environment creates only one main window and itself draws a drawing for children to support event routing strategies.

Now I can change this strategy in my usual window form. I want a Tunnel or Bubble , and Direct is currently used in the window system . I want it to receive the MouseEnter / MouseLeave event, even if it has controls on it. One way is a global mouse / keyboard hook. But let me say that I want to avoid this.

+3
source share
1 answer

Windows is bubbling, but it is purely message based. MouseWheel letters, for example, but neither MouseEnter nor Leave do. Adding bubble behavior is technically possible, but very difficult to get right. Each window in the parent / child tree must interact and call bubbles for its parent explicitly.

. , , MouseLeave MouseEnter . , , . , , MouseEnter .

, Control.Capture. , , . , . , , , . , , MouseUp, , .

. , , - . 200 , , , . Tick Mouse.Position Control.PointToClient, , - .

+7

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


All Articles