add support for nodepad++
Meir017 opened this issue · comments
I cannot figure this one out. I can get the windows, but it doesn't seem to respond to EM_REPLACESEL
in the same manner, if at all.
Notepad++ work on Scintilla and it has own events. I found some codes here. Now I can't understand why notepad++ closes every time when I send message to insert or append text. There may be a problem in the parameters.
const int SCI_APPENDTEXT = 2282;
const int SCI_DELETERANGE = 2645;
const int SCI_INSERTTEXT = 2003;
var windowName = "logging - Notepad++" // you can change it on 'new - Notepad++'
var windowPtr = NativeMethods.FindWindow(null, windowName);
if (windowPtr.Equals(IntPtr.Zero))
{
// when the file changes, notepad changes the name to "* Window Name", so later created loggers cannot find window
var builder = stringBuilderPool.Get();
builder.Append("*").Append(windowName);
windowPtr = NativeMethods.FindWindow(null, builder.ToString());
stringBuilderPool.Return(builder);
}
var scintillaPtr = NativeMethods.FindWindowEx(windowPtr, IntPtr.Zero, "Scintilla", null);
// delete first character
NativeMethods.SendMessage(scintillaPtr, SCI_DELETERANGE, (IntPtr)0, (IntPtr)1);
// it should append/insert text, but it just close notepad++
var res = NativeMethods.SendMessage(scintillaPtr, SCI_APPENDTEXT, (IntPtr)message.Length, message);
NativeMethods.SendMessage(scintillaPtr, SCI_INSERTTEXT, (IntPtr)1, message);
you should have this two methods:
[DllImport("User32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
[DllImport("User32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
Scintilla crashes, I'm trying to recompile from source to see why.
It crashes in SciLexer, apparently unable to read anything from the memory address provided by lParam
. I'm not sure why.