启动找到第三方软件的进程,并获取到它的句柄

int pid = 0;private void Form2_Load(object sender, EventArgs e){Process[] ps = Process.GetProcessesByName("MicroSIP");if (ps.Length > 0){foreach (Process p in ps)p.Kill();}pid = StartExe(@"D:\Users\lenovo\AppData\Local\MicroSIP\microsip.exe");}private void Button_Click(object sender, EventArgs e){Button btn = (Button)sender as Button;int btntext = Convert.ToInt32(btn.Text);ButtonLeftClick(btnList[btntext]);}private void button1_Click(object sender, EventArgs e){automationElement = GetWindowHandle(pid, 1);var autoBtn = automationElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "Button"));btnList = autoBtn;var textBox_str = automationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "ComboBox"));textBox1.Text = textBox_str.Current.Name;timer1.Start();}///<summary>///根据传入的路径启动相应的可执行程序,并返回进程ID///</summary>public Int32 StartExe(string strExePath){if (null == strExePath){return 0;}Process ps = Process.Start(strExePath);Thread.Sleep(3000);return ps.Id;}///<summary>///根据进程ID,查找相应窗体,并返回窗体句柄///</summary>public AutomationElement GetWindowHandle(Int32 pid, int iWaitSecond){AutomationElement targetWindow = null;int iWaitTime = 0;try{Process ps = Process.GetProcessById(pid);targetWindow = AutomationElement.FromHandle(ps.MainWindowHandle);while (null == targetWindow){if (iWaitTime > iWaitSecond){break;}Thread.Sleep(500);targetWindow = AutomationElement.FromHandle(ps.MainWindowHandle);}return targetWindow;}catch (System.Exception ex){string msg = "没有找到指定的窗口,请确认窗口已经启动!";throw new InvalidProgramException(msg, ex);}}

定位button按钮

///<summart>
///根据Button按钮句柄,进行鼠标左键单击
///</summary>
public static bool ButtonLeftClick(AutomationElement ButtonHandle)
{object objButton = null;InvokePattern ivkpButton = null;try{if (null == ButtonHandle){return false;}if (!ButtonHandle.TryGetCurrentPattern(InvokePattern.Pattern, out objButton)){return false;}ivkpButton = (InvokePattern)objButton;ivkpButton.Invoke();return true;}catch (System.Exception ex){string msg = "鼠标左键单击失败!";throw new InvalidProgramException(msg, ex);}
}

定位复选框

/// <summary>/// 判断复选框的值/// </summary>/// <param name="element"></param>/// <returns></returns>private bool IsElementToggledOn(AutomationElement element){if (element == null){return false;}Object objPattern;TogglePattern togPattern;if (true == element.TryGetCurrentPattern(TogglePattern.Pattern, out objPattern)){togPattern = objPattern as TogglePattern;return togPattern.Current.ToggleState == ToggleState.On;}return false;}/// <summary>/// 点击复选框/// </summary>/// <param name="element"></param>private void ClickToggledOn(AutomationElement element){if (element == null){// TODO: Invalid parameter error handling.return;}Object objPattern;TogglePattern togPattern;if (true == element.TryGetCurrentPattern(TogglePattern.Pattern, out objPattern)){togPattern = objPattern as TogglePattern;togPattern.Toggle();}}private void timer1_Tick(object sender, EventArgs e){try{var status = automationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "msctls_statusbar32"));string name = status.Current.Name;label1.Text = name;var textBox_str = automationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "ComboBox"));textBox1.Text = textBox_str.Current.Name;}catch (Exception ex){}}private void button22_Click(object sender, EventArgs e){Form3 form = new Form3();form.ShowDialog();var textBox_str = automationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "ComboBox"));ValuePattern valuePattern = (ValuePattern)textBox_str.GetCurrentPattern(ValuePattern.Pattern);valuePattern.SetValue(Form3.textNumber);}

C# 采用Automation控制自动拨打接听电话相关推荐

  1. 树莓派(二) adb命令控制手机拨打/接听电话

    实验场景: 将手机通过数据线与树莓派相连,使用终端命令查看是否已经连接上,若成功则显示: # 查看adb命令连接的设备 adb devices# 若成功连接则再次运行显示 List of device ...

  2. Android 8.1 9.0 10.0 拨打接听电话默认开启免提

    目录 1.概述 2.拨打接听电话默认开启免提核心代码 3.拨打接听电话默认开启免提代码分析

  3. Android拨打接听电话自动免提

    权限: <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-p ...

  4. 拨打接听电话只有免提模式,无法切换听筒。默认免提模式,可以切换听筒。

    只有免提模式,无法切换听筒: vendor/mediatek/proprietary/packages/services/Telecomm/src/com/android/server/telecom ...

  5. Android 电话的反射调用机制实现自动接听电话

    最近在看一些有关反射和aidl远程服务控制的类,自己也小写了这么一个Android 电话的反射调用机制实现静默接听电话demo 自己总结出来,以供查阅,若是还有其他问题,希望大家指出. 首先要调用系统 ...

  6. python实现自动拨打电话_twilio python自动拨打电话,播放自定义mp3音频的方法

    有个小项目,需求是某事件发生时,给客户打电话,提醒客户.需要事先录制好一段音频,客户接通电话后,自动播放. 1. 注册twilio账号 2. 买一个电话号码 3. 安装twilio pip insta ...

  7. python实现自动拨打电话_python 实现手机自动拨打电话的方法(通话压力测试)

    现在能用自动化实现的,尽量使用自动化程序去操作,代替人工去操作,更有效率. 今天说下用python结合adb命令去实现安卓手机端的通话压力测试. #操作前先在设置里打开power键可以结束通话按钮,否 ...

  8. 无法在Android手机上拨打或接听电话,如何解决

    使用Android,拨打和接听电话变得更加容易.您可以在几分之一秒内与其他联系人建立联系.但是,一些用户在无法在Android手机上拨打或接听电话时不断抱怨这些情况.在这样的时刻,当你看到周围的每个人 ...

  9. Android入门篇(四):自动拨打电话、手动拨打电话

    Android入门篇(四):自动拨打电话.手动拨打电话 一.前言 最近在做的项目需要用到自动拨号的这一功能,17年写了一个,最近拿出来用发现不能使用了,后面查资料据说是因为Android 6(api2 ...

  10. Android手机拨打电话、手动发送短信与自动拨打电话、自动发送短信(代码很简单哦)

    Android实现手动拨打电话,即点击后跳转到手机默认电话号码输入页面,可以将相应号码传送过去: <span style="font-size:18px;"> Inte ...

最新文章

  1. ejb 3中bean的种类
  2. windows java ekho_Vekou
  3. 并发和在线用户数的思考
  4. mysql 事物隔离级别详解
  5. JSON补丁:JSON-P 1.1概述系列
  6. igs无法分配驱动器映射表_硬盘无法使用,用DiskPart进行分区和格式化,非常简单...
  7. THUSCH 2017 大魔法师(矩阵乘法+线段树)
  8. python 实现C atoi函数
  9. mysql车库管理系统_小区停车管理系统(JSP+JAVA+MySQL)
  10. 【初学者入门C语言】之习题篇(一)
  11. 2D卷积和3D卷积的区别及pytorch实现
  12. 值得关注的5款“企业级低代码开发平台”推荐
  13. 用c语言 在图形状态下 编动画,用C语言实坝图形动画设计.pdf
  14. window.btoa与window.atob
  15. Ubuntu18.04 有线网络显示已连接但无法打开网页
  16. Android 4游戏编程入门经典
  17. 华为鸿蒙认证测试题,你能答对几道?
  18. linux去掉文件夹背景色
  19. 小龟机器人图形编程第一课——小车动起来
  20. 干电池升压IC,PW5100电路设计注意点

热门文章

  1. 2017年大数据行业盘点:方案落地转向了价值创造
  2. 一篇文章教你用matlab求定积分广义/变限积分
  3. 如何完全卸载mysql呢
  4. 北斗导航 | 基于奇偶矢量法的RAIM之SSE探索(附奇偶矢量法源代码)
  5. RAIM: A Reverse Auction-based Incentive Mechanism for Mobile Data Offloading through Opportunistic
  6. C语言实现九九乘法表
  7. 转:有效沟通的四种工具
  8. 服务器操作系统详解,深入解析Windows操作系统之总体架构
  9. 读《深入浅出设计模式》
  10. 全国电子设计大赛-电路模块准备