Hello
my first post, i am new to PowerToys purchased today, i am going through the samples and converting from C# to VB.NET, i have a project i have been working on for 3- 4 years and it is in VB.NET unfortunately i am not good with C#.
I have converted most of a sample i am interested in but having an issue with this class:
i have tried to convert it to VB but it does not work :( can anyone point me in the right direction this is what i have:
my first post, i am new to PowerToys purchased today, i am going through the samples and converting from C# to VB.NET, i have a project i have been working on for 3- 4 years and it is in VB.NET unfortunately i am not good with C#.
I have converted most of a sample i am interested in but having an issue with this class:
Code:
public class MouseWheelMessageFilter : IMessageFilter
{
private const int WM_MOUSEWHEEL = 0x020A;
private FrameworkElement _element;
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
public static void RegisterMouseWheelHandling(FrameworkElement element)
{
var mouseWheelMessageFilter = new MouseWheelMessageFilter(element);
}
private MouseWheelMessageFilter(FrameworkElement element)
{
_element = element;
_element.Loaded += delegate(object sender, RoutedEventArgs args)
{
System.Windows.Forms.Application.AddMessageFilter(this);
};
_element.Unloaded += delegate(object sender, RoutedEventArgs args)
{
System.Windows.Forms.Application.RemoveMessageFilter(this);
};
}
public bool PreFilterMessage(ref Message m)
{
if (!_element.IsVisible)
return false;
if (m.Msg == WM_MOUSEWHEEL)
{
Rect rect = new Rect(0, 0, _element.ActualWidth, _element.ActualHeight);
System.Windows.Point pt = Mouse.GetPosition(_element);
if (rect.Contains(pt))
{
HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(_element);
SendMessage(hwndSource.Handle, m.Msg, m.WParam, m.LParam);
return true;
}
}
return false;
}
}i have tried to convert it to VB but it does not work :( can anyone point me in the right direction this is what i have:
Code:
Public Class MouseWheelMessageFilter
Inherits IMessageFilter
Private Const WM_MOUSEWHEEL As Integer = &H20A
Private _element As FrameworkElement
<DllImport("user32.dll")>
Public Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
End Function
Public Sub New(ByVal element As FrameworkElement)
_element = element
End Sub
Public Function PreFilterMessage(ByRef m As Message) As Boolean
If m.Msg = WM_MOUSEWHEEL Then
Dim rect As Rect = New Rect(0, 0, _element.ActualWidth, _element.ActualHeight)
Dim pt As Point = Mouse.GetPosition(_element)
If rect.Contains(pt) Then
Dim hwndSource As HwndSource = CType(hwndSource.FromVisual(_element), HwndSource)
SendMessage(hwndSource.Handle, m.Msg, m.WParam, m.LParam)
Return True
End If
End If
Return False
End Function
End Class
Kevan Hampson

