2015.4.25利用UIAutomation 替代API函数,解决了ListView无法读数据的难题,顺便实现了鼠标模拟滚轮
UIAutomation比API的优点是类似于消息处理机制,而不是主要靠模拟鼠标键盘发送消息
首先添加引用UIAutomationClient和UIAutomationTypes,在安装.net3.5的电脑上可用。低版本的VS可以直接引用dll。
using System.Windows.Automation;
//先用传统方法找到hwnd,用UI也能找到,新项目应统一到UI
IntPtr leftview = API.FindWindowEx(wd0, 0, "SysListView32", "CFQS");
IntPtr rightview = API.FindWindowEx(wd0, 0, "SysListView32", "List2");
if (leftview == IntPtr.Zero || rightview == IntPtr.Zero) return;
AutomationElement el = AutomationElement.FromHandle(leftview); //左侧view
AutomationElement er = AutomationElement.FromHandle(rightview); //右侧view
PropertyCondition condition_bk = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem); //查找子窗口的条件 同样是ListViewItem,对左边的只能用ControlType.DataItem,右边的用ControlType.ListItem
AutomationElementCollection bks = el.FindAll(TreeScope.Children, condition_bk); //获得所有满足条件子窗口的集合
//还有一种遍历子窗口的方法 用TreeWalker
//AutomationElement el = AutomationElement.FromHandle(leftview);
//TreeWalker walker = TreeWalker.ContentViewWalker;
//for (AutomationElement child = walker.GetFirstChild(el); child != null; child = walker.GetNextSibling(child)) //{
// string name=child.Current.Name
//}
API.mouse_event((int)(MouseEventFlags.Wheel | MouseEventFlags.Absolute), 0, 0, -380, IntPtr.Zero); //让滚动条下滚,仅为视觉效果,不要也行
SelectionItemPattern selPattern = (SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern);
selPattern.Select(); //选择该板块 //实现ListView内部元素选择
// item.Current.Name 可取出Listview内部元素内容
//PropertyCondition condition = new PropertyCondition(AutomationElement.IsEnabledProperty, true); //可通用所有非禁用项作为类型
2016.9.2补充
往控件中输入内容
AutomationElement element = AutomationElement.FromHandle(edbox);
object valuePattern = null;
if (element.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern)) //是否支持直接写入
{
// Set focus for input functionality and begin.
element.SetFocus();
((ValuePattern)valuePattern).SetValue(fullpath);
}
else //否则模拟键入
{
// Set focus for input functionality and begin.
element.SetFocus();
// Pause before sending keyboard input.
Thread.Sleep(100);
// Delete existing content in the control and insert new content.
SendKeys.SendWait("^{HOME}"); // Move to start of control
SendKeys.SendWait("^+{END}"); // Select everything
SendKeys.SendWait("{DEL}"); // Delete selection
SendKeys.SendWait(fullpath);
}
2015.4.25利用UIAutomation 替代API函数,解决了ListView无法读数据的难题,顺便实现了鼠标模拟滚轮的更多相关文章
- linux 中的进程wait()和waitpid函数,僵尸进程详解,以及利用这两个函数解决进程同步问题
转载自:http://blog.sina.com.cn/s/blog_7776b9d3010144f9.html 在UNIX 系统中,一个进程结束了,但是他的父进程没有等待(调用wait / wait ...
- 12 —— node 获取文件属性 —— 利用 自调用 闭包函数 解决 i 丢失的问题
闭包的作用 : 保存变量 一,i 丢失的案例 var arr = ['node','vue','mysql'] for(var i=0;i<arr.length;i++){ setTimeout ...
- C# 窗体常用API函数 应用程序窗体查找
常用的处理窗体的API函数如下(注意:API函数必须放在窗体中...): 使用C#语言,要引用DllImport,必须要添加using System.Runtime.InteropServices命名 ...
- mfc 调用Windows的API函数实现同步异步串口通信(源码)
在工业控制中,工控机(一般都基于Windows平台)经常需要与智能仪表通过串口进行通信.串口通信方便易行,应用广泛. 一般情况下,工控机和各智能仪表通过RS485总线进行通信.RS485的通信方式是半 ...
- Detours简介 (拦截x86机器上的任意的win32 API函数)
Detours 当然是用detours,微软明显高腾讯一筹,同上,至今没失败过.写这种HOOK一定要再写个测试程序,不要直接HOOK你的目的程序,例如QQ,因为这样不方面更灵活的测试.说明一下:Det ...
- WINDOWS-API:API函数大全
操作系统除了协调应用程序的执行.内存分配.系统资源管理外,同时也是一个很大的服务中心,调用这个服务中心的各种服务(每一种服务是一个函数),可以帮肋应用程序达到开启视窗.描绘图形.使用周边设备的目的,由 ...
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
- 初识API函数
我之前是一个只会编写数值计算的程序的OIer,但我并不甘于这种现状,于是我编写了我的第一个使用API函数的C++程序,开发平台是VS2012: // ConsoleApplication.cpp : ...
- C#关于外挂汉化的一些思考(API函数FindWindow,FindWindowEx,SendMessage)(转)
这次我们试着运用C#的API函数去修改别的程序的标题文本(适用范围C#) 其实这是FindWindow,FindWindowEx,SendMessage的应用举例之一 也就是所谓的外挂汉化. 附:Wi ...
随机推荐
- How to use Jenkins
一.关键点 1.how to start the build server? do i need to start some app to do this? I don't believe so... ...
- 内网批量测试登录机器工具,并且dir 目标机器c盘
// Ipc.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #include <w ...
- cern-cloud-architecture
规模: 总体: 有26个Cell 一个数据中心运行控制节点,另外一个仅仅运行nova cell 统一,灵活 nova-api运行在VM中,当然需要至少一个部署在物理机上来启动VM. 每个cell只有一 ...
- review37
线程的常用方法 1.start() 线程调用该方法将启动线程,使之从新建状态进入就绪队列排队. 2.run() 3.sleep() 4.isAlive() 线程处于新建状态时,线程调用isAlive( ...
- 1001 字符串“水”题(二进制,map,哈希)
1001: 字符串“水”题 时间限制: 1 Sec 内存限制: 128 MB提交: 210 解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...
- mysql分组取topn
本文来自 http://www.jb51.net/article/31590.htm 有些语句sql top n 是sqlserver语法 --按某一字段分组取最大(小)值所在行的数据 代码如下: ...
- shell_script_查询主机名、ip地址 、DNS地址
#!/bin/bashhostnameip=`/sbin/ifconfig eth0|grep "inet addr:"|sed 's/Bcast.*$//'g |awk -F & ...
- 信息标记 以及信息提取--xml-json-yaml
1 信息标记的三种方式: XML: JSON: YAML: 1 缩进 表示所属关系: 2 - 表示并列关系: 3 | 表示整块数据: HTML----XML的一种形式: 2 信息提取的方法: ...
- Codeforces Round #254(div2)B
就是看无向图有几个连通块,答案就是2n-num. 范围很小,就用矩阵来存图减少代码量. #include<iostream> #include<cstdio> #include ...
- 让camera实现类似cs第一人称视角旋转和位移
直接把这个脚本挂在摄像机上就可: using System.Collections; using System.Collections.Generic; using UnityEngine; /* * ...