views:

11

answers:

1

I have a program that causes windows to snap into slots that specify a location and size. You can drag a window and then it will snap to the closest slot when you finish the drag. What I want to add is an overlay of the slot that the window will be moved to as the drag is happening.

The snapping and the overlay work fine. My problem is that I need a better way to know if the window is being dragged. The way I was preventing a window from snapping to slot while a drag was happening is by just not doing anything while the mouse was clicked. Drawing the overlay while the mouse is clicked works, but causes the overlay to show up anytime the mouse is clicked even if a window is being dragged.

Is there a method that will take a hwnd and tell me if that window is being dragged? Or is there a better way go about this process?

A: 

Since I couldn't find anything and nobody came up with any suggestions, I ended up writing something that approximates it. Win32 is my static class that handles all the DllImports and struct definition to interact with user32.dll.

private bool isWindowDragging(IntPtr hWND, Win32.RECT rect)
{
  Point pos = Control.MousePosition;
  return Control.MouseButtons.Equals(MouseButtons.Left) && hWND.Equals(Win32.GetForegroundWindow()) &&
  pos.X >= rect.Left && pos.X <= rect.Right && pos.Y >= rect.Top && pos.Y <= rect.Top+40;
}
unholysampler