Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Wpf.Ui/Controls/TitleBar/HwndProcEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

// ReSharper disable once CheckNamespace
namespace Wpf.Ui.Controls;

public class HwndProcEventArgs : EventArgs
{
public bool Handled { get; set; }

public IntPtr? ReturnValue { get; set; }

public bool IsMouseOverDetectedHeaderContent { get; }

public IntPtr HWND { get; }

public int Message { get; }

public IntPtr WParam { get; }

public IntPtr LParam { get; }

internal HwndProcEventArgs(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, bool isMouseOverDetectedHeaderContent)
{
HWND = hwnd;
Message = msg;
WParam = wParam;
LParam = lParam;
IsMouseOverDetectedHeaderContent = isMouseOverDetectedHeaderContent;
}
}
11 changes: 11 additions & 0 deletions src/Wpf.Ui/Controls/TitleBar/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl

private DependencyObject? _parentWindow;

public event EventHandler<HwndProcEventArgs>? WndProcInvoked;

/// <summary>Identifies the <see cref="ApplicationTheme"/> dependency property.</summary>
public static readonly DependencyProperty ApplicationThemeProperty = DependencyProperty.Register(
nameof(ApplicationTheme),
Expand Down Expand Up @@ -682,6 +684,15 @@ or User32.WM.NCLBUTTONUP
}
}

var e = new HwndProcEventArgs(hwnd, msg, wParam, lParam, isMouseOverHeaderContent);
WndProcInvoked?.Invoke(this, e);

if (e.ReturnValue != null)
{
handled = e.Handled;
return e.ReturnValue ?? IntPtr.Zero;
}

switch (message)
{
case User32.WM.NCHITTEST when CloseWindowByDoubleClickOnIcon && _icon.IsMouseOverElement(lParam):
Expand Down
Loading