C# 窗口模拟点击按钮或关闭窗口
public class CloseForm
{
[DllImport("user32", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern void SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam); private const int WM_CLOSE = 0x10;//关闭
private const int BM_CLICK = 0xF5;//点击 private DateTime dt = DateTime.Now;//当前时间 private string MsgTitle { get; set; } public void CloseTitleForm(string title)
{
this.MsgTitle = title;
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Enabled = true;
//MessageBox.Show("若不回應的話,X秒後此 MsgBox 會自動關閉", MsgTitle);
//timer1.Enabled = false;
} private void timer1_Tick(object sender, EventArgs e)
{
IntPtr hWnd = FindWindow(null, MsgTitle);
//窗体按钮
IntPtr childHwnd = FindWindowEx(hWnd, IntPtr.Zero, null, "是(&Y)");
if (childHwnd != IntPtr.Zero)
{
//模拟点击 是(&Y)
SendMessage(childHwnd, BM_CLICK, IntPtr.Zero, 0);
}
else
{
//没有找到按钮则关闭
SendMessage(hWnd, WM_CLOSE, IntPtr.Zero, 0);
}
if (DateTime.Now.Subtract(dt).TotalSeconds > 10)
{
//10秒后停止执行
((System.Windows.Forms.Timer)sender).Stop();
}
}
}
C# 窗口模拟点击按钮或关闭窗口的更多相关文章
- lhgdialog在打开的窗口里点击按钮关闭当前窗口
lhgdialog在打开的窗口里点击按钮关闭当前窗口 var api = frameElement.api, W = api.opener; api.close();
- win32 htmlayout点击按钮创建新窗口,以及按钮图片样式
最近在做一个C++ win32的桌面图形程序,我不是C++程序员,做这个只是因为最近没什么java的活. windows api,之前接触的时候,还是大学,那时用这个开发打飞机游戏纯粹是娱乐.现在基本 ...
- TProcedure,TMethod,TNotifyEvent,TWndMethod的区别,并模拟点击按钮后发生的动作
忽然发现TProcedure和TNotifEvent的区别还挺大的: procedure TForm1.Button2Click(Sender: TObject); begin ShowMessage ...
- JS点击按钮弹出窗口
由于没有系统学习过JS,遇到一个需求:点击按钮,弹出一个独立的窗口. 在网上百度了一下,并没有找到满意的结果,最重要的是各种方法很复杂.最终,仔细研究了一下,原来只是需要只要一个简单的函数就能满足自己 ...
- mui 对话框 点击按钮不关闭对话框的办法
目前版本的 mui.js 点击对话框的按钮只能关闭对话框 做如下修改 点击按钮后return false 即可
- JavaScript-打开新窗口(window.open)和 关闭窗口(window.close)
JavaScript-打开新窗口 open() 方法可以查找一个已经存在或者新建的浏览器窗口. 语法: window.open([URL], [窗口名称], [参数字符串]) 参数说明: URL:可选 ...
- C#根据弹窗标题获取窗体句柄并模拟点击按钮(FindWindow,FindWindowEx,SendMessage)
任务:将下面弹窗自动关闭 /// <summary> /// 找到窗口 /// </summary> /// <param name="lpClassName& ...
- alert弹出窗口,点击确认后关闭页面
alert("点击确认后,关闭页面"); window.opener=null;window.top.open('','_self','');window.close(this);
- java jframe关闭窗口
frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { i ...
随机推荐
- for与while的特点及其if在什么情况下使用情况
for和while的特点: 什么时候使用循环结构呢? 1:当对某些代码执行很多次时,使用循环结构完成. 2:当对一个条件进行一次判断时,可以使用if语句. 3:当对一个条件进行多次判断时,可以使用wh ...
- (转)找回Git中丢失的Commit
总结:更新代码前一定要先将本地修改的文件存到本地git仓库.今天脑残直接更新了远程仓库代码导入今天写的代码...... @[git|commit|reflog] 在使用Git的过程中,有时候会因为一些 ...
- Andrew Ng-ML-第十七章-推荐系统
1.问题规划 图1.推荐系统在研究什么? 例子:预测电影的评分. 当知道n_u用户数,n_m电影数:r(i,j)用户j评价了电影i,那么就是1:y(i,j)如果r(i,j)为1,那么就给出评分. 问 ...
- linux命令:压缩解压命令
压缩解压命令:gzip 命令名称:gzip 命令英文原意:GNU zip 命令所在路径:/bin/gzip 执行权限:所有用户 语法:gzip 选项 [文件] 功能描述:压缩文件 压缩后文件格式:g ...
- Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class
转自http://www.anylogic.com/anylogic/help/index.jsp?topic=/com.xj.anylogic.help/html/code/Arrays_Colle ...
- C语言常用函数大全
一.数学函数 调用数学函数时,要求在源文件中包下以下命令行: #include <math.h> 函数原型说明 功能 返回值 说明 int abs( int x) 求整数x的绝对值 计算结 ...
- 2:4 动态方法的调用(简化Action的配置)
动态方法的第一种方法: 所以我们要手动设置 动态调用的开关打开:strus-core-jar里面:修改常量 使用方法: 根据请求来区分用哪个方法处理,处理完了,注意要在该方法里面返回与请求相同的字符串 ...
- Python - matplotlib 数据可视化
在许多实际问题中,经常要对给出的数据进行可视化,便于观察. 今天专门针对Python中的数据可视化模块--matplotlib这块内容系统的整理,方便查找使用. 本文来自于对<利用python进 ...
- Unirest-拼装http请求发送rest接口
public static Integer getInfo(String name) { HttpResponse<Integer> httpResponse = null; try { ...
- java opencv使用相关
Using OpenCV Java with Eclipse http://docs.opencv.org/2.4/doc/tutorials/introduction/java_eclipse/ja ...