private void button1_Click(object sender, EventArgs e)
{
var appWord = new Microsoft.Office.Interop.Word.Application();
var doc = new Microsoft.Office.Interop.Word.Document();
object oMissing = System.Reflection.Missing.Value;//这个是什么东西,我始终没搞明白-_-
//打开模板文档,并指定doc的文档类型
object objTemplate = @"c:\18_0000f032-1c39-4bc9-a47c-327d8d493978.docx";
object objDocType = WdDocumentType.wdTypeDocument;
appWord.Visible = true;
doc = appWord.Documents.Add(ref objTemplate, ref oMissing, ref objDocType, ref oMissing);
object start = 0;
object end = 160;
doc.Range(ref start, ref end).Select();
appWord.Selection.Range.Copy();

var process = new Process();
process = Process.Start("mspaint.exe",@"c:\1.jpg");
var processId = process.Id;
var element = FindWindowByProcessId(processId);
SendKeys.SendWait("^v"); //发送 Ctrl + s 键
SendKeys.SendWait("^s"); //发送 Ctrl + s 键
SendKeys.SendWait("%{F4}"); // 发送 Alt + F4 键
}

public static AutomationElement FindWindowByProcessId(int processId)
{
AutomationElement targetWindow = null;
int count = 0;
try
{
Process p = Process.GetProcessById(processId);
targetWindow = AutomationElement.FromHandle(p.MainWindowHandle);
return targetWindow;
}
catch (Exception ex)
{
count++;
StringBuilder sb = new StringBuilder();
string message = sb.AppendLine(string.Format("Target window is not existing.try #{0}", count)).ToString();
if (count > 5)
{
throw new InvalidProgramException(message, ex);
}
else
{
return FindWindowByProcessId(processId);
}
}
}

最新文章

  1. 在Ubuntu下搭建ASP.NET 5开发环境
  2. Visual Studio 生成事件命令
  3. 商贸食品车销成功应用PDA抄单 现场开单 打印销售单安卓智能手持POS应用
  4. poj 1806 分块模拟
  5. Codeforces 549A. Face Detection[模拟]
  6. spark性能调优:资源优化
  7. iOS开发Block的使用
  8. 在C#中实现软件自动升级
  9. kontalk
  10. CentOS 7 +Nginx
  11. android学习笔记Fragment的使用
  12. Kubernetes集群部署史上最详细(一)Kubernetes集群安装
  13. SpringBoot系列——Spring-Data-JPA(究极进化版) 自动生成单表基础增、删、改、查接口
  14. SEO高手和SEO屌丝的八个区
  15. 几张简单的terraform flow 图——可以快速了解terraform的使用
  16. 二叉树的递归,非递归遍历(C++)
  17. python学习笔记比较全
  18. PLsql登录数据库提示密码即将过期-
  19. gettimeofday的使用
  20. 项目Alpha冲刺——代码规范、本次冲刺任务与计划

热门文章

  1. 【枚举暴力】【UVA11464】 Even Parity
  2. Train-net流程
  3. mapper.xml配置读取不到
  4. [Android问答] px、dp和sp,这些单位有什么区别?
  5. Python爬虫学习笔记之微信宫格验证码的识别(存在问题)
  6. mysql5.6以上(适用5.7)免安装版本 终极配置
  7. js的alert抛出之后怎么让页面停止执行?
  8. 【Foreign】Weed [线段树]
  9. 【BZOJ4821】【SDOI2017】相关分析 [线段树]
  10. 聂老师的考验(反向bfs)