I am trying to put text in another program and when I use notepad it works:
CODE
private void button2_Click(object sender, EventArgs e)
{ string lpClassName = "Notepad";
string lpWindowName = "Untitled - Notepad";
IntPtr hWnd = FindWindow(lpClassName, lpWindowName);
SetForegroundWindow(hWnd); string z = "TEXT"; const int WM_SETTEXT = 0x0C; SendMessage(hWnd, WM_SETTEXT, IntPtr.Zero, z);
SendKeys.Send("This is my text");
}
That works fine but when I try:
CODE
private void button2_Click(object sender, EventArgs e)
{ string lpClassName = "Wordpad";
string lpWindowName = "Document1 - WordPad";
IntPtr hWnd = FindWindow(lpClassName, lpWindowName);
SetForegroundWindow(hWnd); string z = "TEXT";
const int WM_SETTEXT = 0x0C; SendMessage(hWnd, WM_SETTEXT, IntPtr.Zero, z);
SendKeys.Send("This is my text");
}
it either just stalls, puts "This is my text" into the textbox in my program, or just puts it in notepad (if it's open). What should the ClassName be? Is it the exe that is running or the default name or the program?