diff --git a/Notepad.Extensions.Logging/NotepadLogger.cs b/Notepad.Extensions.Logging/NotepadLogger.cs index c4e37b1..754fd9b 100644 --- a/Notepad.Extensions.Logging/NotepadLogger.cs +++ b/Notepad.Extensions.Logging/NotepadLogger.cs @@ -85,8 +85,7 @@ namespace Microsoft.Extensions.Logging static void WriteToNotepad(string message) { IntPtr hwnd = WindowFinder.FindNotepadWindow(); - IntPtr edit = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null); - NativeMethods.SendMessage(edit, NativeMethods.EM_REPLACESEL, (IntPtr)1, message); + NativeMethods.SendMessage(hwnd, NativeMethods.EM_REPLACESEL, (IntPtr)1, message); } } } diff --git a/Notepad.Extensions.Logging/WindowFinder.cs b/Notepad.Extensions.Logging/WindowFinder.cs index 0027600..a033593 100644 --- a/Notepad.Extensions.Logging/WindowFinder.cs +++ b/Notepad.Extensions.Logging/WindowFinder.cs @@ -5,6 +5,13 @@ namespace Microsoft.Extensions.Logging static class WindowFinder { public static IntPtr FindNotepadWindow() + { + var hwnd = FindMainWindow(); + IntPtr edit = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null); + return edit; + } + + static IntPtr FindMainWindow() { IntPtr hwnd;