C# user32.dll 找窗口 填数据
工具:SpyLite
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private extern static 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 = "SendMessageA")]
private static extern int SendMessageA(IntPtr hwnd, int wMsg, IntPtr wParam, string lParam);//向目标填充栏 填充文本(有时候目标有【仅数字】之类的限制,这时候发不符合的文本就不行了)
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd);//类似树结构的查找方式,实测中GW_HWNDNEXT经常找不着,鼠标划过一下目标,又找着了......
const int WM_SETTEXT = 0x000C;
enum GetWindow_Cmd : uint
{
GW_HWNDFIRST = ,
GW_HWNDLAST = ,
GW_HWNDNEXT = ,
GW_HWNDPREV = ,
GW_OWNER = ,
GW_CHILD = ,
GW_ENABLEDPOPUP =
}
string msg = "";
IntPtr hMainWnd = FindWindow(null, "父窗口名");//此处有待修改,父窗口类型和标题,那个唯一的可能性更大就用哪个
IntPtr hNextWnd;
IntPtr hLastWnd;
if (hMainWnd != IntPtr.Zero)
{ //子 hKPfameWnd
hNextWnd = FindWindowEx(hMainWnd, IntPtr.Zero, null, "FPtiankai_new");
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-1没找到"; return msg; }
hLastWnd = hNextWnd; //向下找两层
for (int i = ; i < ; i++)
{
hNextWnd = FindWindowEx(hLastWnd, IntPtr.Zero, "WindowsForms10.Window.8.app.0.3598b65_r16_ad1", null);
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-2没找到"; return msg;
}
hLastWnd = hNextWnd;
} hNextWnd = GetWindow(hLastWnd, GetWindow_Cmd.GW_CHILD);//返回其第一个子窗体
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-3没找到";
return msg;
}
hLastWnd = hNextWnd; /*此时的窗口布局如下
3541882 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:北京 这是刚刚找到的
4853516 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:北 京
1513288 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:ddd
4919418 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题:
4000606 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题:
1443834 WindowsForms10.EDIT.app.0.3598b65_r16_ad1 标题:
1181678 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:¥0.00
22088970 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:零圆整
10817716 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:¥0.00
1247228 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:¥0.00
5969752 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:2017年08月08日
10425028 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:08919001
920118 WindowsForms10.STATIC.app.0.3598b65_r16_ad1 标题:1100164320
4852040 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题:
788912 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题:
1706660 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题:
5179046 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题:
3018896 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题:
5444734 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题: 子窗口——WindowsForms10.EDIT.app.0.3598b65_r16_ad1——目标【1】
24187592 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题: 同上——目标【2】
985234 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题: 同上——目标【3】
5965524 WindowsForms10.Window.8.app.0.3598b65_r16_ad1 标题: 同上——目标【4】
*/ //同一层找接下来18个控件
for (int i = ; i < ; i++)
{ hNextWnd = GetWindow(hLastWnd, GetWindow_Cmd.GW_HWNDNEXT);//找的是NEXT
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-i="+i+"没找到";
return msg;
}
hLastWnd = hNextWnd;
}
//【hLastWnd不更新 】 //目标1
hNextWnd = FindWindowEx(hLastWnd, IntPtr.Zero, "WindowsForms10.EDIT.app.0.3598b65_r16_ad1", null);
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-目标1";
return msg;
}
SendMessageA(hNextWnd, WM_SETTEXT, IntPtr.Zero, info.Bank + " " + info.BankAccount); //hLastWnd再更新
hNextWnd = GetWindow(hLastWnd, GetWindow_Cmd.GW_HWNDNEXT);
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-4没找到";
return msg;
}
hLastWnd = hNextWnd;
//目标2
hNextWnd = FindWindowEx(hLastWnd, IntPtr.Zero, "WindowsForms10.EDIT.app.0.3598b65_r16_ad1", null);
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-目标2";
return msg;
}
SendMessageA(hNextWnd, WM_SETTEXT, IntPtr.Zero, info.TaxpayerCode); //hLastWnd再更新
hNextWnd = GetWindow(hLastWnd, GetWindow_Cmd.GW_HWNDNEXT);
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-5没找到";
return msg;
}
hLastWnd = hNextWnd;
//目标3
hNextWnd = FindWindowEx(hLastWnd, IntPtr.Zero, "WindowsForms10.EDIT.app.0.3598b65_r16_ad1", null);
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-目标3";
return msg;
}
SendMessageA(hNextWnd, WM_SETTEXT, IntPtr.Zero, info.Address + " " + info.Telephone); //hLastWnd再更新
hNextWnd = GetWindow(hLastWnd, GetWindow_Cmd.GW_HWNDNEXT);
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-6没找到";
return msg;
}
hLastWnd = hNextWnd;
//目标4
hNextWnd = FindWindowEx(hLastWnd, IntPtr.Zero, "WindowsForms10.EDIT.app.0.3598b65_r16_ad1", null);
if (IntPtr.Zero == hNextWnd)
{
msg = "SetValueGolden = ::FindWindowEx-目标4";
return msg;
}
SendMessageA(hNextWnd, WM_SETTEXT, IntPtr.Zero, info.TaxpayerName); }
else
{
msg = "没有找到目标软件";
return msg;
}
实测:FindWindowEx 比 GetWindow靠谱,查找文本框等需要填充的控件,尽量使用FindWindowEx按窗体类型查找
C# user32.dll 找窗口 填数据的更多相关文章
- C# user32.dll找窗口时,使用GetClass方法解决 【带有系统自动编译的窗体类后缀名】 问题
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern int G ...
- 调用user32.dll显示其他窗口
/// 该函数设置由不同线程产生的窗口的显示状态 /// </summary> /// <param name="hWnd">窗口句柄</param& ...
- C#中可直接调用WIN32的API函数--USER32.DLL
Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...
- Winform API "user32.dll"中的函数
命名空间:System.Runtime.InteropServices /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在G ...
- 【转】c# 调用windows API(user32.dll)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- user32.dll
user32.dll中的所有函数 using System; using System.Collections.Generic; using System.Linq; using System.Tex ...
- 【WinAPI】User32.dll注释
#region User32.dll 函数 /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备 ...
- 【整理】c# 调用windows API(user32.dll)
User32.dll提供了很多可供调用的接口,大致如下(转自http://blog.csdn.net/zhang399401/article/details/6978803) using System ...
- C# user32.dll
#region User32.dll 函数 /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备 ...
随机推荐
- Delphi简介
- PHP漏洞函数
1. is_numeric函数 bool is_numeric ( mixed $var ) 此函数用于判断变量是否数字或者数字字符串,不仅能接受十进制,还能接受十六进制,这样就有了绕过的方法 < ...
- 2017 ICPC 南宁 L 带权最大递增子序列
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #inclu ...
- 如何配置SQL Server数据库远程连接
本地数据库(SQL Server 2012或以上) 连接外网服务器的数据库,外网的服务器端需要做如下配置: 1.首先是要打开 数据的配置管理工具 2.配置相关的客户端协议,开启TCP/IP 3.数据库 ...
- web.xml中url-pattern中/和/*的区别(来自网络)
其中/和/*的区别: < url-pattern > / </ url-pattern > 不会匹配到*.jsp,即:*.jsp不会进入spring的 Dispatcher ...
- java课堂动手测试
课堂实验3 一个Java类文件中真的只能有一个公有类吗? 经过测试,当含有两个public 类时会报错,不能执行,假如删除第二个public则可以正常生成,说明一个java文件只能有一个公有类. 课 ...
- springMVC项目访问URL链接时遇到某一段然后忽略后面的部分
背景:一个链接URL:http:localhost/tq/asf/218732,配置URL使遇到/asf后直接跳转不识别/asf后面的218732 因为是在ssm框架下做的项目,所以用spring的注 ...
- 常用数列总结&性质记录
1.斐波那契数列 P.S.:这里首项下标为 1 递推式:\[F_i=F_{i-1}+F_{i-2},F_1=F_2=1\] 性质: \(1.\sum^{n}_{i=1}F_{i}=F_{n+2}-1\ ...
- python接口自动化六(参数化也就是把之前敲过的代码封装成方法)
前言 前面一篇实现了参数的关联,那种只是记流水账的完成功能,不便于维护,也没什么可读性,接下来这篇可以把每一个动作写成一个函数,这样更方便了. 参数化的思维只需记住一点:不要写死 (由于博客园登录机制 ...
- 对vue虚拟dom的研究
Vue.js通过编译将template 模板转换成渲染函数(render ) ,执行渲染函数就可以得到一个虚拟节点树 在对 Model 进行操作的时候,会触发对应 Dep 中的 Watcher 对象. ...