I have a program which needs to send every line of a text file to an application while minimized. I am able to send the text to the application but this causes it to be opened. Is there a way to do this while the application is minimized? I have read that I could use postmessage or sendmessage but am unsure how to do this.
public partial class Form1 : Form
{
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lp1, string lp2);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IntPtr handle = FindWindow(null, "Application");
if (!handle.Equals(IntPtr.Zero))
{
if (SetForegroundWindow(handle))
{
string[] dic = System.IO.File.ReadAllLines(@"text file name");
foreach (string a in dic)
{
SendKeys.Send(a);
}
}
}
}
}