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无法读数据的难题,顺便实现了鼠标模拟滚轮的更多相关文章

  1. linux 中的进程wait()和waitpid函数,僵尸进程详解,以及利用这两个函数解决进程同步问题

    转载自:http://blog.sina.com.cn/s/blog_7776b9d3010144f9.html 在UNIX 系统中,一个进程结束了,但是他的父进程没有等待(调用wait / wait ...

  2. 12 —— node 获取文件属性 —— 利用 自调用 闭包函数 解决 i 丢失的问题

    闭包的作用 : 保存变量 一,i 丢失的案例 var arr = ['node','vue','mysql'] for(var i=0;i<arr.length;i++){ setTimeout ...

  3. C# 窗体常用API函数 应用程序窗体查找

    常用的处理窗体的API函数如下(注意:API函数必须放在窗体中...): 使用C#语言,要引用DllImport,必须要添加using System.Runtime.InteropServices命名 ...

  4. mfc 调用Windows的API函数实现同步异步串口通信(源码)

    在工业控制中,工控机(一般都基于Windows平台)经常需要与智能仪表通过串口进行通信.串口通信方便易行,应用广泛. 一般情况下,工控机和各智能仪表通过RS485总线进行通信.RS485的通信方式是半 ...

  5. Detours简介 (拦截x86机器上的任意的win32 API函数)

    Detours 当然是用detours,微软明显高腾讯一筹,同上,至今没失败过.写这种HOOK一定要再写个测试程序,不要直接HOOK你的目的程序,例如QQ,因为这样不方面更灵活的测试.说明一下:Det ...

  6. WINDOWS-API:API函数大全

    操作系统除了协调应用程序的执行.内存分配.系统资源管理外,同时也是一个很大的服务中心,调用这个服务中心的各种服务(每一种服务是一个函数),可以帮肋应用程序达到开启视窗.描绘图形.使用周边设备的目的,由 ...

  7. Windows API 函数列表 附帮助手册

    所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...

  8. 初识API函数

    我之前是一个只会编写数值计算的程序的OIer,但我并不甘于这种现状,于是我编写了我的第一个使用API函数的C++程序,开发平台是VS2012: // ConsoleApplication.cpp : ...

  9. C#关于外挂汉化的一些思考(API函数FindWindow,FindWindowEx,SendMessage)(转)

    这次我们试着运用C#的API函数去修改别的程序的标题文本(适用范围C#) 其实这是FindWindow,FindWindowEx,SendMessage的应用举例之一 也就是所谓的外挂汉化. 附:Wi ...

随机推荐

  1. 关于选中的磁盘具有MBR分区表。在EFI系统上,Windows只能安装到GPT磁盘。问题解决

    昨天在为一位学弟装系统的时候需要了这个问题,现在把解决问题的步骤写下来. 在此界面按shift+F10 启动cmd命令行模式 在cmd模式中输入diskpart,进入diskpart模式 此时,lis ...

  2. Java编程思想 两个主函数

    //: initialization/DynamicArray.javapackage initialization; /* Added by Eclipse.py */// Array initia ...

  3. dr03_

    1.温州配调-->全网-->厂站-->瓯海-->竹溪变 1.1.“10kVI段”,“60号间隔”,手车开关 --> 合上 2. 2.1. 2.2. TdrSvgDll.A ...

  4. 184. Department Highest Salary

    问题描述 解决方案 select b.Name Department,a.Name Employee,a.Salary from ( select e1.Salary,e1.Name,e1.Depar ...

  5. Excel 导入到处问题处理!

    1.未在本地计算机上注册"Microsoft.Jet.OLEDB.4.0" 因为没有安装64位的Jet40驱动.可以到 http://www.microsoft.com/downl ...

  6. nyoj 42 一笔画 欧拉通路

    http://acm.nyist.net/JudgeOnline/problem.php?pid=42 一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 zyc ...

  7. 二维码的扫描和生成--第三方开源--ZXing

    ZXing的二维码功能的提取lib下载地址:https://github.com/xuyisheng/ZXingLib 1.扫描二维码: 我们扫描就是要用到这个CaptureActivity类,直接把 ...

  8. @angular/cli项目构建--路由1

    app.module.ts import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angu ...

  9. 马拉车——模版+KMP——模版

    void Manacher(){ ;t[i];++i,len+=){ s[i<<]='#'; |]=t[i]-'A'+'a'; |]=t[i]; } s[len++]='#'; ,pos= ...

  10. GCD多线程的使用

    转载自http://blog.csdn.net/nono_love_lilith/article/details/7829557 写得非常好 1.下面来看下如何使用gcd编程的异步 dispatch_ ...