C#控制其它程序
Posted 黄海的编程知识世界
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#控制其它程序相关的知识,希望对你有一定的参考价值。
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
private static extern void SetForegroundWindow(IntPtr hwnd);
private void button1_Click(object sender, EventArgs e)
{
var hwndPhoto = FindWindow(null, "XMind"); //查找拍照程序的句柄【任务管理器中的应用程序名称】
if (hwndPhoto != IntPtr.Zero)
{
SetForegroundWindow(hwndPhoto); //将UcDemo程序设为当前活动窗口
SendKeys.Send("^o");
Clipboard.SetDataObject(@"D:\思维导图\文档\基础数据改造.xmind");
System.Threading.Thread.Sleep(200); //暂停500毫秒
SendKeys.Send("^v");
System.Threading.Thread.Sleep(200); //暂停500毫秒
SendKeys.Send("~");
System.Threading.Thread.Sleep(500); //暂停500毫秒
SendKeys.Send("^p");
System.Threading.Thread.Sleep(200); //暂停500毫秒
SendKeys.Send("~");
}
else
{
MessageBox.Show("没有启动 XMind");
}
}
以上是关于C#控制其它程序的主要内容,如果未能解决你的问题,请参考以下文章