Skip to content

Commit b2ba023

Browse files
authored
Add support for the redesigned Notepad in Windows 11 (#30)
1 parent 6a0a961 commit b2ba023

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Serilog.Sinks.Notepad/Sinks/Notepad/Interop/NotepadTextWriter.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void Flush()
5858

5959
var notepadWindowHandle = currentNotepadProcess.MainWindowHandle;
6060

61-
var notepadEditorHandle = User32.FindWindowEx(notepadWindowHandle, IntPtr.Zero, "Edit", null);
61+
var notepadEditorHandle = FindNotepadEditorHandle(notepadWindowHandle);
6262
if (notepadEditorHandle == IntPtr.Zero)
6363
{
6464
SelfLog.WriteLine($"Unable to access a Notepad Editor on process {currentNotepadProcess.ProcessName} ({currentNotepadProcess.Id})");
@@ -110,6 +110,19 @@ private static Process TryFindMostRecentNotepadProcess()
110110
return mostRecentNotepadProcess;
111111
}
112112

113+
private static IntPtr FindNotepadEditorHandle(IntPtr notepadWindowHandle)
114+
{
115+
// Windows 11 uses the new RichEditD2DPT class:
116+
// https://devblogs.microsoft.com/math-in-office/windows-11-notepad/#some-implementation-details
117+
if (User32.FindWindowEx(notepadWindowHandle, IntPtr.Zero, "RichEditD2DPT", null) is var richEditHandle
118+
&& richEditHandle != IntPtr.Zero)
119+
{
120+
return richEditHandle;
121+
}
122+
123+
return User32.FindWindowEx(notepadWindowHandle, IntPtr.Zero, "Edit", null);
124+
}
125+
113126
private void EnsureNotDisposed()
114127
{
115128
if (_disposed)

0 commit comments

Comments
 (0)