0
我有一個程序需要發送文本文件的每一行到應用程序,同時最小化。我能夠將文本發送到應用程序,但這會導致它被打開。有沒有辦法在應用程序最小化時執行此操作?我讀過,我可以使用postmessage或sendmessage,但我不確定如何做到這一點。如何模擬最小化應用程序中的按鍵而不打開它?
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);
}
}
}
}
}
你可以改變其他應用程序的代碼?或者它是黑匣子,你不能改變它? –
你能解釋一下你試圖實現什麼,是否有你使用sendkeys來傳遞文本的理由? (例如,你是否試圖複製某人在窗口中輸入內容)? – ajg
是的,我試圖模擬鍵入應用程序,而它是最小化 – Allofthem