Allow our messages from non-elevated processes

This commit is contained in:
2025-07-01 12:38:22 -04:00
parent 5849525029
commit 72ddd0ad88
3 changed files with 26 additions and 2 deletions

View File

@@ -1,5 +1,4 @@
using ChrisKaczor.Wpf.Windows;
using System;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
@@ -10,6 +9,11 @@ public static partial class WindowManager
{
private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
private enum ChangeWindowMessageFilterExAction : uint
{
Allow = 1
}
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial void EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
@@ -26,6 +30,10 @@ public static partial class WindowManager
[LibraryImport("user32.dll", EntryPoint = "SendMessageW")]
private static partial void SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
[LibraryImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial void ChangeWindowMessageFilterEx(IntPtr hWnd, uint msg, ChangeWindowMessageFilterExAction action, IntPtr changeInfo);
private const string WindowMessageSetLock = "FloatingStatusWindowLibrary_SetLock";
private const string WindowMessageClose = "FloatingStatusWindowLibrary_Close";
@@ -43,6 +51,12 @@ public static partial class WindowManager
private static List<WindowInformation> _windowList;
private static IntPtr _excludeHandle;
public static void AllowMessagesThroughFilter(IntPtr hWnd)
{
ChangeWindowMessageFilterEx(hWnd, SetLockMessage, ChangeWindowMessageFilterExAction.Allow, IntPtr.Zero);
ChangeWindowMessageFilterEx(hWnd, CloseMessage, ChangeWindowMessageFilterExAction.Allow, IntPtr.Zero);
}
public static List<WindowInformation> GetWindowList()
{
lock (WindowLocker)