I noticed that SendMessage() changes the console window name, and not the console text. This is the code I'm using to find the console window and send text to it:
- Code: Select all
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr hWnd_Console = FindWindow(null, "ConsoleName");
- Code: Select all
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
SendMessage(hWnd_Console, WM_SETTEXT, 0, txt);
I figured I need to send the message to the right window class, but I don't know the class name. In Windows Notepad I found it using FindWindowEx() and setting "Edit" as the class name:
- Code: Select all
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, int lpszClass, string lpszWindow);
IntPtr child = FindWindowEx(consoleHandle, new IntPtr(0), "Edit", null);
How can I find the class name for my console "edit box" ?