在word转换成html的时候,由于系统版本不一样,office总是抛出异常,Microsoft Word停止工作,下面有三个按钮,关闭程序等等,但是我的转换工作需要自动的,每当抛出异常的时候我的程序就会停止工作,对此就需要自动关闭这个异常,需要以下的这个代码!

    --相应的引用
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
private static extern int FindWindowEx(IntPtr lpClassName, IntPtr lpWindowName, string isnull, string anniu);
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private void test()
{
const int WM_CLOSE = 0x10; //关闭 const uint WM_DESTROY = 0x02; const uint WM_QUIT = 0x12; const int BM_CLICK = 0xF5; //单击
IntPtr Window_Handle = (IntPtr)FindWindow(null, "Microsoft Word");//查找所有的窗体,看看想查找的句柄是否存在,Microsoft Word 句柄 //
if (Window_Handle ==IntPtr.Zero) //如果没有查找到相应的句柄
{ MessageBox.Show("没有找到窗体");
}
else //查找到相应的句柄
{
SendMessage(Window_Handle, WM_CLOSE, , ); //关闭窗体 // IntPtr childHwnd = (IntPtr)FindWindowEx(Window_Handle, IntPtr.Zero, null, "点击");//查找句柄中相应的按钮
// if (childHwnd == IntPtr.Zero)
// {
// MessageBox.Show("没有找到按钮");
// }
// else
// {
// SendMessage(childHwnd, BM_CLICK, 0, 0); //单击这个句柄中的按钮
// }
} }

最新文章

  1. swift tableview的分割线不能到头
  2. Rock-Paper-Scissors Tournament[HDU1148]
  3. Longest Substring Without Repeating Characters -- LeetCode
  4. CSS 布局属性(display,float,clear,visibility,overflow,overflow-x,overflow-y)
  5. C语言的数组名和对数组名取地址
  6. [SQL]不知道1
  7. 实现JQuery EasyUI右键菜单变灰不可用效果
  8. Oracle_集合
  9. 从bug中学习怎么写代码
  10. android动画效果编程基础--Android Animation
  11. LESS使用方法简介(装逼神器)
  12. 轻量级的内部测试过程r \\ u0026研发团队
  13. 对于行高(line-height)的一些理解
  14. HUST 1372 marshmallow
  15. Java http请求和调用
  16. [原] inline operator delete & DLL boundary
  17. C# ExecutionContext 实现
  18. ThinkPad X220 完美黑苹果 Hackintosh OS X 10.11 El Capitan
  19. Android 中的广播机制
  20. App升级iOS7体会

热门文章

  1. [c/c++] programming之路(22)、字符串(三)——字符串封装
  2. Python将list中的string批量转化成int/float
  3. log4net架构、配置、使用
  4. 8th,常用模块、正则表达式
  5. ES6 常用总结(前端开发js技术进阶提升总结)
  6. pixi.js(入门)
  7. 解决Firefox显示“已阻止载入混合活动内容”的方法
  8. C语言获取Linux系统精确时间
  9. phpmyadmin-您可能正在上传很大的文件,请参考文档来寻找解决方法
  10. [JavaScript] 邮箱验证