当正在移动的WPF窗口确定 [英] Determining when a WPF window is being moved

查看:251
本文介绍了当正在移动的WPF窗口确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作从行为与调用的应用程序的工具栏窗口中的WPF 窗口类派生的类 AppBarWindow 。我已经能够找到各种各样的WinForms实现,但没有WPF的实现。

I'm working on a class derived from the WPF Window class that behaves as an application toolbar window called AppBarWindow. I have been able to find various WinForms implementations, but no WPF implementations.

我已经得到了很多工作的代码,但我需要知道用户启动时拖动窗口在屏幕上,当他们停下来,作为窗口的行为会有所不同。默认的WPF的处理是不完全正确的,所以我已经实现了我自己的窗口过程,并使用 HwndSource 对象安装。

I've got a lot of the code working, but I need to know when the user starts dragging the window around the screen and when they stop, as the window's behavior will differ. The default WPF handling isn't quite right, so I've implemented my own Window Procedure and installed it using an HwndSource object.

我得在工作中应用这个工作,不具有非客户区。在这种情况下,有一个 LeftMouseButtonDown 事件处理程序,设置一个标志为true,则调用该拖动的 DragMove 方法窗口里。当该方法返回,我的标志设置为false。一切正常。

I've got this working in an application at work that does not have a non-client area. In that case, there's a LeftMouseButtonDown event handler that sets a flag to true, then calls the DragMove method which drags the window around. When that method returns, I set the flag to false. Everything works.

但我的不会使用 DragMove 方法的通用类现在的工作。我可以添加其他 LeftMouseButtonDown 处理程序窗口,但我不相信,如果鼠标在非客户区,将被调用。

But I'm working now on a general class that won't use the DragMove method. I can add another LeftMouseButtonDown handler for the window, but I don't believe that will get called if the mouse is in the non-client area.

我怎么检测到用户拖动窗口时,他们已经停止了在这种情况下?

How am I going to detect that the user is dragging the window and when they've stopped in this case?

推荐答案

我发现我需要通过监控的同时拖动它的Win32发送到我的窗口的消息知道的。

I've found what I needed to know by monitoring the messages sent to my window from Win32 while dragging it.

总之,Windows发送当窗口开始移动了以下消息:

In short, Windows sends the following message when the window starts to move:

WM_ENTERSIZEMOVE

WM_ENTERSIZEMOVE

接下来,Windows发送以下信息到我的在序列窗口过程:

Next, Windows sends the following messages to my window procedure in sequence:

WM_MOVING
WM_WINDOWPOSCHANGING
WM_GETMINMAXINFO
WM_WINDOWPOSCAHANGED
WM_MOVE

WM_MOVING WM_WINDOWPOSCHANGING WM_GETMINMAXINFO WM_WINDOWPOSCAHANGED WM_MOVE

这些都是其次有其代码为0xc310的消息。这不是任何地方documentented,所以我猜这是由.NET / WPF内部使用。

These are followed with a message whose code is 0xc310. This is not documentented anywhere, so I'm guessing this is used internally by .NET / WPF.

这6个消息反复发送,鼠标移动和窗口如下。后

These 6 messages are sent repeatedly as the mouse moves and the window follows after it.

最后,当你松开鼠标左键时,Windows将:

Finally, when you release the left mouse button, Windows sends:

WM_EXITSIZEMOVE

WM_EXITSIZEMOVE

所以,我需要监听WM_ENTERSIZEMOVE和WM_EXITSIZEMOVE消息。

So I need to listen for the WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE messages.

这篇关于当正在移动的WPF窗口确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆