惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
雷峰网
雷峰网
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
D
DataBreaches.Net
量子位
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
人人都是产品经理
人人都是产品经理
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Proofpoint News Feed
Help Net Security
Help Net Security
腾讯CDC
I
InfoQ
Know Your Adversary
Know Your Adversary
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
W
WeLiveSecurity
NISL@THU
NISL@THU
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
月光博客
月光博客
Schneier on Security
Schneier on Security
Forbes - Security
Forbes - Security
Project Zero
Project Zero
宝玉的分享
宝玉的分享
P
Palo Alto Networks Blog
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
S
Security Affairs
I
Intezer
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
A
Arctic Wolf
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG
T
Tenable Blog
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - flyfish

Microsoft SQL Server 2005 -- 错误 29503。SQL Server 服务无法启动 模拟鼠标移动和左键单击 在ASP程序中调用Web Service ASPNET2.0中读写Cookie的方法! - flyfish - 博客园 转 跨域读取Cookie和session之HttpWebRequest另类方法(网站API开发) ASP.NET WAP开发 用ASP.NET创建移动Web窗体[转] ASP.NET 2.0移动开发入门之使用模拟器 [WAP]dotNet在WAP应用开发中实现按指定页数翻页的解决方案 SQL Server 自增字段归零等问题 ntext replace sql SQLServer2005数据库还原到SQLServer2000 如何去除Google搜索结果病毒提示 Tomcat 6 连接 MS SQL 2005 Windows 2003远程桌面连接数限制 如何用SQL命令修改字段名称 FCKeditor详细的设置 log4net 配置与应用 两个sql server 2000的通用分页存储过程
.C# 获取另一程序控件,改变值,触发事件 - flyfish - 博客园
flyfish · 2009-10-13 · via 博客园 - flyfish

Posted on 2009-10-13 14:29  flyfish  阅读(917)  评论()    收藏  举报

[DllImport("User32.dll", 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 int SendMessage(IntPtr hWnd,
int Msg, IntPtr wParam, string lParam);
const int WM_GETTEXT = 0x000D;
const int WM_SETTEXT = 0x000C;
const int WM_CLICK = 0x00F5;
private void button3_Click(object sender, EventArgs e)
{
int retval = 0; //增加一个返回值用来判断操作是否成功
//下面的这些参数都可以用Spy++查到
//string lpszParentClass = "#32770"; //整个窗口的类名
string lpszParentWindow = "Form1"; //窗口标题
string lpszClass = "WindowsForms10.EDIT.app.0.b7ab7b"; //需要查找的子窗口的类名,也就是输入框
string lpszClass_Submit = "WindowsForms10.BUTTON.app.0.b7ab7b"; //需要查找的Button的类名
string lpszName_Submit = "确定"; //需要查找的Button的标题
string text = "";
IntPtr ParenthWnd = new IntPtr(0);
IntPtr EdithWnd = new IntPtr(0);
//查到窗体,得到整个窗体
ParenthWnd = FindWindow(null, lpszParentWindow);
//判断这个窗体是否有效
if (!ParenthWnd.Equals(IntPtr.Zero))
{
//得到User Name这个子窗体,并设置其内容
EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, lpszClass, "");
if (!EdithWnd.Equals(IntPtr.Zero))
{
text = "Book";
//调用SendMessage方法设置其内容
SendMessage(EdithWnd, WM_SETTEXT, (IntPtr)0, text);
retval++;
}
//得到Password这个子窗体,并设置其内容
EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, lpszClass, "");
if (!EdithWnd.Equals(IntPtr.Zero))
{
text = "ITest";
SendMessage(EdithWnd, WM_SETTEXT, (IntPtr)0, text);
retval++;
}
//得到Domain这个子窗体,并设置其内容
EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, lpszClass, "");
if (!EdithWnd.Equals(IntPtr.Zero))
{
text = "Ilove";
SendMessage(EdithWnd, WM_SETTEXT, (IntPtr)0, text);
retval++;
}
//得到Button这个子窗体,并触发它的Click事件
EdithWnd = FindWindowEx(ParenthWnd,
(IntPtr)0, lpszClass_Submit, lpszName_Submit);
if (!EdithWnd.Equals(IntPtr.Zero))
{
SendMessage(EdithWnd, WM_CLICK, (IntPtr)0, "0");
retval++;
}
}      
文章出处:DIY部落(http://www.diybl.com/course/3_program/vc/vc_js/20090727/168175.html)