From b23e186617a35faaa0b8f597c19bd79769ece6c0 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Thu, 21 May 2020 18:09:11 +1000 Subject: [PATCH] try notepad++ --- Notepad.Extensions.Logging/WindowFinder.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Notepad.Extensions.Logging/WindowFinder.cs b/Notepad.Extensions.Logging/WindowFinder.cs index 19faae1..8c9b084 100644 --- a/Notepad.Extensions.Logging/WindowFinder.cs +++ b/Notepad.Extensions.Logging/WindowFinder.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using System.Text; +using System.Text.RegularExpressions; namespace Microsoft.Extensions.Logging { @@ -13,13 +14,7 @@ namespace Microsoft.Extensions.Logging try { FindMainWindow(); - if (handle == IntPtr.Zero) - { - return handle; - } - - IntPtr edit = NativeMethods.FindWindowEx(handle, IntPtr.Zero, "EDIT", null); - return edit; + return handle; } finally { @@ -44,9 +39,10 @@ namespace Microsoft.Extensions.Logging throw new Win32Exception(result); } + WindowFinder.handle = hWnd; + if (IsKnownNotepadWindow(sb.ToString())) { - WindowFinder.handle = hWnd; return false; } return true; @@ -58,15 +54,24 @@ namespace Microsoft.Extensions.Logging [ThreadStatic] static StringBuilder sb; + static Regex notepadPlusPlusRegex = new Regex(@"^new \d+ - Notepad\+\+$", RegexOptions.Compiled); + static bool IsKnownNotepadWindow(string titleText) { switch (titleText) { case "Untitled - Notepad": case "*Untitled - Notepad": + handle = NativeMethods.FindWindowEx(handle, IntPtr.Zero, "EDIT", null); return true; } + if (notepadPlusPlusRegex.IsMatch(titleText)) + { + handle = NativeMethods.FindWindowEx(handle, IntPtr.Zero, "SysTabControl32", null); + return true; + } + return false; } }