Send identify message with a timeout

This commit is contained in:
2026-03-02 18:01:06 -05:00
parent de3f6c2e98
commit 96efc06ba9

View File

@@ -15,6 +15,16 @@ public static partial class WindowManager
Allow = 1
}
[Flags]
private enum SendMessageTimeoutFlags : uint
{
Normal = 0x0,
Block = 0x1,
AbortIfHung = 0x2,
NoTimeoutIfNotHung = 0x8,
ErrorOnExit = 0x20
}
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial void EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
@@ -31,6 +41,17 @@ public static partial class WindowManager
[LibraryImport("user32.dll", EntryPoint = "SendMessageW", SetLastError = true)]
private static partial IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[LibraryImport("user32.dll", EntryPoint = "SendMessageTimeoutW", SetLastError = true)]
private static partial IntPtr SendMessageTimeout(
IntPtr windowHandle,
int msg,
IntPtr wParam,
IntPtr lParam,
SendMessageTimeoutFlags flags,
uint timeout,
out IntPtr result);
[LibraryImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial void ChangeWindowMessageFilterEx(IntPtr hWnd, int msg, ChangeWindowMessageFilterExAction action, IntPtr changeInfo);
@@ -101,7 +122,7 @@ public static partial class WindowManager
if (hWnd == _excludeHandle)
return true;
var identifyResult = SendMessage(hWnd, IdentifyMessage, IntPtr.Zero, IntPtr.Zero);
SendMessageTimeout(hWnd, IdentifyMessage, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.Normal, 100, out var identifyResult);
if (identifyResult == IdentifyMessage)
{