Skip to content

Commit

Permalink
Sometimes, the editor handle seems not correct. So if the text length…
Browse files Browse the repository at this point in the history
… does not change by sending text to it, it is cleared in order to reget it.
  • Loading branch information
bstordrup committed May 30, 2023
1 parent 756b269 commit 7802dec
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ public override void Flush()
// Write the log message to Notepad
User32.SendMessage(_currentNotepadEditorHandle, User32.EM_REPLACESEL, (IntPtr)1, message);

buffer.Clear();
// Get how many characters are in the Notepad editor after putting in new text
var textLengthAfter = User32.SendMessage(_currentNotepadEditorHandle, User32.WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero);

// If no change in textLength, reset editor handle to try to find it again.
if (textLengthAfter == textLength)
_currentNotepadEditorHandle = IntPtr.Zero;

// Otherwise, we clear the buffer
else
buffer.Clear();
}

protected override void Dispose(bool disposing)
Expand Down

0 comments on commit 7802dec

Please sign in to comment.