I’m trying to use SendMessage to Notepad, so that I can insert written text without making Notepad the active window.
I have done something like this in the past using SendText, but that required giving Notepad focus.
Now, first I’m retrieving the Windows handle:
Process[] processes = Process.GetProcessesByName('notepad'); Console.WriteLine(processes[0].MainWindowHandle.ToString());
I’ve confirmed it’s the right handle for Notepad, the same shown within Windows Task Manager.
[DllImport('User32.dll', EntryPoint = 'SendMessage')] public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
From here, I haven’t been able to get SendMessage to work in all my experimentation. Am I going in the wrong direction?
WM_SETTEXT=0x000c