Hi ,
I have been trying to get the location of the WPF window when the "Show window content while dragging" is turned off as shown below. The LocationChanged event gets invoked only when the mouse is up after stopped dragging the window.
So I have used the IntPtr solution to get the LocationChange method on dragging the WPF window with the following code, but the location of window does not update while dragging. Please provide a suitable solution for this query.
public partial class CustomWindow : Window
{
private const int WM_MOVING = 0x0216;
private HwndSource _hwndSrc;
private HwndSourceHook _hwndSrcHook;
private IntPtr hWnd;
public CustomWindow()
{
InitializeComponent();
this.Loaded += CustomWindow_Loaded;
this.Unloaded += CustomWindow_Unloaded;
this.LocationChanged += CustomWindow_LocationChanged;
}
private void CustomWindow_Unloaded(object sender, RoutedEventArgs e)
{
_hwndSrc.RemoveHook(_hwndSrcHook);
_hwndSrc.Dispose();
_hwndSrc = null;
}
private void CustomWindow_Loaded(object sender, RoutedEventArgs e)
{
_hwndSrc = HwndSource.FromDependencyObject(this) as HwndSource;
_hwndSrcHook = FilterMessage;
_hwndSrc.AddHook(_hwndSrcHook);
hWnd = new WindowInteropHelper(this).Handle;
}
private IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WM_MOVING:
OnLocationChange();
break;
}
return IntPtr.Zero;
}
private void OnLocationChange()
{
Rect windowRect = new Rect(this.Left, this.Top, this.Width, this.Height);
}
private void CustomWindow_LocationChanged(object sender, EventArgs e)
{
}
}