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 ...
随机推荐
- vue学习之node.js
Node.js是一个Javascript运行环境(runtime environment),发布于2009年5月,由Ryan Dahl开发,实质是对Chrome V8引擎进行了封装.本文详细介绍了No ...
- Gson的两种解析用法
第一种. 常见的解析,直接将json字符串解析为对应的类. public JavaBean getJsonString(String jsonString) { Gson gson = new Gso ...
- Linux实验楼学习之三
查看用户 who am i or who mom likes who 命令其它常用参数 参数 说明 -a 打印能打印的全部 -d 打印死掉的进程 -m 同am i,mom likes -q 打印当前登 ...
- [LeetCode] 127. Word Ladder _Medium tag: BFS
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest t ...
- python-字符串前面添加u,r,b的含义
u/U:表示unicode字符串 不是仅仅是针对中文, 可以针对任何的字符串,代表是对字符串进行unicode编码. 一般英文字符在使用各种编码下, 基本都可以正常解析, 所以一般不带u:但是中文, ...
- mongodb权限
1.在无密码模式下添加账号 db.createUser( { user: "user", pwd: "pwd", roles: [ { role: " ...
- 去n的第一个出现的1
实例十八:去n的第一个出现的1 方法:result=n & (n-1) 与实例十七 思路类似.实例十七是不断取1,本例只去最低位. 解释:n 0000 1111n-1 0000 1110&am ...
- Java缓存学习之五:spring 对缓存的支持
(注意标题,Spring对缓存的支持 这里不单单指Ehcache ) 从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache ...
- 新项目新工作空间新仓库新setting文件
maven项目涉及到仓库,本地jar包存放在本地仓库中,新项目新工作空间新仓库新setting文件,可以避免很多问题,不同项目工程的版本可能不一样,所涉及的jar包版本可能也不一样,不分开会有一些冲 ...
- Oracle提示错误消息ORA-28001: the password has expired
首先,以SYS DBA身份进入sqlpuls 打开sqlpuls SQL->请输入用户名:sys as sysdba SQL->密码: 登录成功以后查询DBA用户状态 SQL->se ...