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函数中使用该句柄来在设备 ...
随机推荐
- hostname - 显示或设置系统的主机名
NAME(名称) hostname - 显示或设置系统的主机名 domainname - 显示或设置系统的NIS/YP域名 dnsdomainname - 显示系统的DNS域名 nisdomainna ...
- Qt设置生成的exe文件图标
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_37354286/article/d ...
- tp5 apache 转 nginx 需要配置的伪静态
location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$ last; break; } }
- tensorflow 屏蔽 Log
pip install alfred-py 在代码中加入 from alfred.dl.tf.common import mute_tf mute_tf()
- @Autowired与@Resource的区别(转载)
原文地址:http://bhdweb.iteye.com/blog/1663907 1.@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上. ...
- 系统命令模块subprocess
系统命令 可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen* --废弃 popen2.* --废弃 commands.* --废弃,3.x中被移除 ...
- 补充:bytes类型以及字符编码转换
内容转自小猿圈链接:https://book.apeland.cn/details/41/ 定义 bytes类型是指一堆字节的集合,在python中以b开头的字符串都是bytes类型 b'\xe5\x ...
- 对TypeScript进行研究
1.npm install -g typescript 在编辑器,将下面的代码输入到greeter.ts文件里: function greeter(person) { return "Hel ...
- 2018山东省赛 G Game ( Nim博弈 && DP )
题目链接 题意 : 给出 N 堆石子,每次可以选择一堆石子拿走任意颗石子,最后没有石子拿的人为败者.现在后手 Bob 可以在游戏开始前拿掉不超过 d 堆的整堆石子,现在问你有几种取走的组合使得 Bob ...
- k8s安装报错 Error: unknown flag: --experimental-upload-certs
今天安装k8sV1.16的版本时候,执行突然发现命令不对,之前安装V1.15的时候是可以的,可能是版本升级的原因. 解决: unknown flag: --experimental-upload-ce ...