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.
This commit is contained in:
Robin 2015-09-18 13:33:10 +01:00
parent 6d794dcb52
commit 71105b8e77
5 changed files with 1249 additions and 0 deletions

View File

@ -124,9 +124,12 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>TreeViewIcons.resx</DependentUpon> <DependentUpon>TreeViewIcons.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Win32\ControlScrollFilter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderers\DarkMenuRenderer.cs" /> <Compile Include="Renderers\DarkMenuRenderer.cs" />
<Compile Include="Renderers\DarkToolStripRenderer.cs" /> <Compile Include="Renderers\DarkToolStripRenderer.cs" />
<Compile Include="Win32\Native.cs" />
<Compile Include="Win32\WindowsMessages.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Forms\DarkDialog.resx"> <EmbeddedResource Include="Forms\DarkDialog.resx">

View File

@ -0,0 +1,27 @@
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;
}
}
}

15
DarkUI/Win32/Native.cs Normal file
View File

@ -0,0 +1,15 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace DarkUI
{
public sealed class Native
{
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(Point point);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
using DarkUI; using DarkUI;
using System.Windows.Forms;
namespace Example namespace Example
{ {
@ -8,6 +9,10 @@ namespace Example
{ {
InitializeComponent(); InitializeComponent();
// Add the control scroll message filter to re-route all mousewheel events
// to the control the user is currently hovering over with their cursor.
Application.AddMessageFilter(new ControlScrollFilter());
// Build dummy list data // Build dummy list data
for (var i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {