I know this question has already been answered. Here is my problem. I have a Windows Form with a button and a textbox. The user enters info into the textbox, and when the user clicks the button, an instance of notepad is launched and the text of the textbox is then loaded into the notepad.
Here is my code (which I got from a question on this site)
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
private void btnCopyToNotepad_Click(object sender, EventArgs e)
{
StartNotepad();
Process[] notepads = Process.GetProcessesByName("notepad");
if (notepads.Length == 0) return;
if (notepads[0] != null)
{
Clipboard.SetText(textBox1.Text);
SendMessage(FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null), 0x000C, 0, textBox1.Text);
}
}
private static void StartNotepad()
{
Process.Start("notepad.exe");
}
When I run this code, stepping through debug, it runs fine, and the logic does what its intended to do (copy text to the instance of notepad). When I run it in release, nothing is copied to the instance of notepad. Any ideas why this is happening? No i'm not running multiple instances of notepad..