From e512889b17c4569466c5413bdde68d4fb1b918fb Mon Sep 17 00:00:00 2001 From: Yaakov Date: Thu, 21 May 2020 17:40:53 +1000 Subject: [PATCH] Move edit window lookup too --- Notepad.Extensions.Logging/NotepadLogger.cs | 3 +-- Notepad.Extensions.Logging/WindowFinder.cs | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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;