diff --git a/UserInterface/ShellContextMenu.cs b/UserInterface/ShellContextMenu.cs
index 097cf47..d6d5631 100644
--- a/UserInterface/ShellContextMenu.cs
+++ b/UserInterface/ShellContextMenu.cs
@@ -11,7 +11,7 @@ namespace SystemTrayMenu.UserInterface
using System.Text;
using System.Windows;
using System.Windows.Input;
- using static SystemTrayMenu.Utilities.FormsExtensions;
+ using System.Windows.Interop;
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1124:Do not use regions", Justification = "Mark SystemTrayMenu modifications made to original source.")]
@@ -43,7 +43,7 @@ namespace SystemTrayMenu.UserInterface
/// files[0] = new FileInfo(@"c:\windows\notepad.exe");
/// scm.ShowContextMenu(this.Handle, files, Cursor.Position);.
///
- public class ShellContextMenu : NativeWindow
+ public class ShellContextMenu : HwndSource
{
private const int MaxPath = 260;
private const uint CmdFirst = 1;
@@ -58,6 +58,8 @@ namespace SystemTrayMenu.UserInterface
private static Guid iidIContextMenu2 = new("{000214f4-0000-0000-c000-000000000046}");
private static Guid iidIContextMenu3 = new("{bcfce0a0-ec17-11d0-8d10-00a0c90f2719}");
+ private readonly HwndSourceHook hook;
+
private IContextMenu? oContextMenu;
private IContextMenu2? oContextMenu2;
private IContextMenu3? oContextMenu3;
@@ -66,12 +68,20 @@ namespace SystemTrayMenu.UserInterface
private IntPtr[]? arrPIDLs;
private string? strParentFolder;
+ public ShellContextMenu()
+ : base(new())
+ {
+ hook = new HwndSourceHook(WndProc);
+ AddHook(hook);
+ }
+
///
/// Finalizes an instance of the class.
///
~ShellContextMenu()
{
ReleaseAll();
+ RemoveHook(hook);
}
// Defines the values used with the IShellFolder::GetDisplayNameOf and IShellFolder::SetNameOf
@@ -872,7 +882,7 @@ namespace SystemTrayMenu.UserInterface
/// Set the value to true if the message was handled; otherwise, false.
/// The appropriate return value depends on the particular message.
/// See the message documentation details for the Win32 message being handled.
- protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
+ protected IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (oContextMenu2 != null &&
(msg == (int)WM.INITMENUPOPUP ||
diff --git a/Utilities/FormsExtensions.cs b/Utilities/FormsExtensions.cs
deleted file mode 100644
index b6ff289..0000000
--- a/Utilities/FormsExtensions.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// Copyright (c) PlaceholderCompany. All rights reserved.
-//
-
-namespace SystemTrayMenu.Utilities
-{
- using System;
- using System.Windows.Interop;
-
- public static class FormsExtensions
- {
- public class NativeWindow : HwndSource
- {
- private readonly HwndSourceHook hook;
-
- public NativeWindow()
- : base(new())
- {
- hook = new HwndSourceHook(WndProc);
- AddHook(hook);
- }
-
- ~NativeWindow()
- {
- RemoveHook(hook);
- }
-
- protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
- {
- throw new NotImplementedException();
- }
- }
- }
-}