是否正在拖动外部窗口?

发布于 2024-09-10 03:11:10 字数 260 浏览 10 评论 0原文

我有一个程序可以使窗口卡入指定位置和大小的插槽中。您可以拖动一个窗口,完成拖动后它将捕捉到最近的插槽。我想添加的是当拖动发生时窗口将移动到的插槽的覆盖层。

捕捉和覆盖效果很好。我的问题是我需要一种更好的方法来知道窗口是否被拖动。我防止窗口在拖动时捕捉到插槽的方法是在单击鼠标时不执行任何操作。单击鼠标时绘制覆盖层是可行的,但会导致只要单击鼠标,即使正在拖动窗口,也会显示覆盖层。

有没有一种方法可以接受 hwnd 并告诉我该窗口是否被拖动?或者有更好的方法来完成这个过程吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦等七年七年为一梦 2024-09-17 03:11:10

由于我找不到任何东西,也没有人提出任何建议,所以我最终写了一些近似的东西。 Win32 是我的静态类,它处理所有 DllImport 和 struct 定义以与 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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文