DarkUI.Net5/DarkUI/Win32/ControlScrollFilter.cs
Robin 71105b8e77 Added ControlScrollFilter
ControlScrollFilter can be added to the application's message filter
list to re-route all mousewheel events to the control the user is
current hovering over with their cursor.
2015-09-18 13:33:10 +01:00

28 lines
810 B
C#

using System.Drawing;
using System.Windows.Forms;
namespace DarkUI
{
public class ControlScrollFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
case (int)WM.MOUSEWHEEL:
case (int)WM.MOUSEHWHEEL:
var hControlUnderMouse = Native.WindowFromPoint(new Point((int)m.LParam));
if (hControlUnderMouse == m.HWnd)
return false; // Already headed for the right control.
// Redirect the message to the control under the mouse.
Native.SendMessage(hControlUnderMouse, (uint)m.Msg, m.WParam, m.LParam);
return true;
}
return false;
}
}
}