diff --git a/Notepad.Extensions.Logging/NotepadLogger.cs b/Notepad.Extensions.Logging/NotepadLogger.cs index f365058..2636b13 100644 --- a/Notepad.Extensions.Logging/NotepadLogger.cs +++ b/Notepad.Extensions.Logging/NotepadLogger.cs @@ -84,10 +84,29 @@ namespace Microsoft.Extensions.Logging static void WriteToNotepad(string message) { - IntPtr hwnd = NativeMethods.FindWindow(null, "Untitled - Notepad"); + IntPtr hwnd = FindNotepadWindow(); IntPtr edit = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null); NativeMethods.SendMessage(edit, NativeMethods.EM_REPLACESEL, (IntPtr)1, message); } + + static IntPtr FindNotepadWindow() + { + IntPtr hwnd; + + hwnd = NativeMethods.FindWindow(null, "Untitled - Notepad"); + if (hwnd != IntPtr.Zero) + { + return hwnd; + } + + hwnd = NativeMethods.FindWindow(null, "*Untitled - Notepad"); + if (hwnd != IntPtr.Zero) + { + return hwnd; + } + + return IntPtr.Zero; + } } static class NativeMethods