winfrom 关闭别的应用程序的窗体或者弹出框(winform 关闭句柄)
2024-10-19 03:30:54
在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); //单击这个句柄中的按钮
// }
} }
最新文章
- swift tableview的分割线不能到头
- Rock-Paper-Scissors Tournament[HDU1148]
- Longest Substring Without Repeating Characters -- LeetCode
- CSS 布局属性(display,float,clear,visibility,overflow,overflow-x,overflow-y)
- C语言的数组名和对数组名取地址
- [SQL]不知道1
- 实现JQuery EasyUI右键菜单变灰不可用效果
- Oracle_集合
- 从bug中学习怎么写代码
- android动画效果编程基础--Android Animation
- LESS使用方法简介(装逼神器)
- 轻量级的内部测试过程r \\ u0026研发团队
- 对于行高(line-height)的一些理解
- HUST 1372 marshmallow
- Java http请求和调用
- [原] inline operator delete &; DLL boundary
- C# ExecutionContext 实现
- ThinkPad X220 完美黑苹果 Hackintosh OS X 10.11 El Capitan
- Android 中的广播机制
- App升级iOS7体会
热门文章
- [c/c++] programming之路(22)、字符串(三)——字符串封装
- Python将list中的string批量转化成int/float
- log4net架构、配置、使用
- 8th,常用模块、正则表达式
- ES6 常用总结(前端开发js技术进阶提升总结)
- pixi.js(入门)
- 解决Firefox显示“已阻止载入混合活动内容”的方法
- C语言获取Linux系统精确时间
- phpmyadmin-您可能正在上传很大的文件,请参考文档来寻找解决方法
- [JavaScript] 邮箱验证