6

Windowと呼ばれるアプリケーション ツールバー ウィンドウとして動作するWPF クラスから派生したクラスに取り組んでいますAppBarWindow。さまざまな WinForms 実装を見つけることができましたが、WPF 実装は見つかりませんでした。

多くのコードが機能していますが、ウィンドウの動作が異なるため、ユーザーが画面上でウィンドウをドラッグし始めたときと停止したときを知る必要があります。デフォルトの WPF 処理は正しくないため、独自のウィンドウ プロシージャを実装し、HwndSourceオブジェクトを使用してインストールしました。

非クライアント領域を持たない職場のアプリケーションでこれを機能させました。その場合、フラグを true に設定し、ウィンドウをドラッグするメソッドをLeftMouseButtonDown呼び出すイベント ハンドラーがあります。DragMoveそのメソッドが戻ったら、フラグを false に設定します。すべてが機能します。

しかし、私は現在、DragMoveメソッドを使用しない一般的なクラスに取り組んでいます。ウィンドウに別のハンドラーを追加できLeftMouseButtonDownますが、マウスが非クライアント領域にある場合に呼び出されるとは思いません。

この場合、ユーザーがウィンドウをドラッグしていることと、停止したことをどのように検出しますか?

4

3 に答える 3

2

Tony が指摘しているように、ウィンドウのドラッグに関連するいくつかのウィンドウ メッセージがあります。役立つ列挙型を次に示します。

internal enum WindowsMessage
{
    /// <summary>Sent after a window has been moved.</summary>
    WM_MOVE = 0x0003,
    /// <summary>
    /// Sent to a window when the size or position of the window is about to change.
    /// An application can use this message to override the window's default maximized size and position,
    /// or its default minimum or maximum tracking size.
    /// </summary>
    WM_GETMINMAXINFO = 0x0024,
    /// <summary>
    /// Sent to a window whose size, position, or place in the Z order is about to change as a result
    /// of a call to the SetWindowPos function or another window-management function.
    /// </summary>
    WM_WINDOWPOSCHANGING = 0x0046,
    /// <summary>
    /// Sent to a window whose size, position, or place in the Z order has changed as a result of a
    /// call to the SetWindowPos function or another window-management function.
    /// </summary>
    WM_WINDOWPOSCHANGED = 0x0047,
    /// <summary>
    /// Sent to a window that the user is moving. By processing this message, an application can monitor
    /// the position of the drag rectangle and, if needed, change its position.
    /// </summary>
    WM_MOVING = 0x0216,
    /// <summary>
    /// Sent once to a window after it enters the moving or sizing modal loop. The window enters the
    /// moving or sizing modal loop when the user clicks the window's title bar or sizing border, or
    /// when the window passes the WM_SYSCOMMAND message to the DefWindowProc function and the wParam
    /// parameter of the message specifies the SC_MOVE or SC_SIZE value. The operation is complete
    /// when DefWindowProc returns.
    /// <para />
    /// The system sends the WM_ENTERSIZEMOVE message regardless of whether the dragging of full windows
    /// is enabled.
    /// </summary>
    WM_ENTERSIZEMOVE = 0x0231,
    /// <summary>
    /// Sent once to a window once it has exited moving or sizing modal loop. The window enters the
    /// moving or sizing modal loop when the user clicks the window's title bar or sizing border, or
    /// when the window passes the WM_SYSCOMMAND message to the DefWindowProc function and the
    /// wParam parameter of the message specifies the SC_MOVE or SC_SIZE value. The operation is
    /// complete when DefWindowProc returns.
    /// </summary>
    WM_EXITSIZEMOVE = 0x0232
}
于 2016-10-08T20:50:41.033 に答える