博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AutoIt 无法获取.net CheckBox 控件的状态
阅读量:5248 次
发布时间:2019-06-14

本文共 4859 字,大约阅读时间需要 16 分钟。

在AutoIt的帮助文档中, 提到可以用 ControlCommand函数判断checkbox是否选中,有个参数叫“IsChecked”, 但在实际的使用中,至少对.net的checkbox控件无效,网上有人给出了解决方法,原文地址:

他自定义了一个方法,根据选中时控件的颜色变化来判断状态,这是一种新的思路。

Func CheckboxIsChecked($strWindowTitle, $strWindowText, $strCheckboxId);===============================================================================; Function Name: CheckboxIsChecked();   Description: Determines checkbox state using difference in color luminosity.;               A pixel within the checkmark, which significantly changes its;               luminosity based on the IsChecked value, is compared to a pixel;               that has luminosity that's relatively unaffected by IsChecked ;               state. The absolute difference can accommodate a variety of;               user color schemes.;               The location of the two pixels is relative to the upper left ;               corner of the control. These pixels were selected to provide ;               large contrast in both WinXP and Vista, with the checkbox both;               enabled and disabled. Other versions of Windows may require;               other pixels (e.g., older Windows uses an 'x' rather than tick);               or a different threshold; use a Select Case @OSVersion to ;               choose the best pixel pairs.;               Procedure:;                 1. get starting position (upper left corner of checkbox);                    which is defined as (0,0);                 2. get colors of two pixels: checkmark at (8,6) and baseline;                    at (8,11);                 3. place in RGB array to facilitate Min/Max calc;                 4. calculate luminousity of each pixel (Max+Min)/2;                 5. if luminousity difference > threshold then IsChecked=True;        Entry: $strWindowTitle is control's owner window;               $strWindowText is window text;               $strCheckboxId is ID of control to be examined;      Returns: 1 if IsChecked=True, otherwise 0;      Created: 2008-01-09;       Author: Ed Allwein, Active Sensing, Inc.  www.BuyPLM.com;===============================================================================    Local Enum $rgblRed=0, $rgblGreen=1, $rgblBlue=2, $rgblLum=3    Const $maskRed = 0x0FF0000    Const $maskGreen = 0x0FF00    Const $maskBlue = 0x0FF    Const $intThreshold = 26; good UI practice suggests at least 10% diff on scale of 0-255        Local $rectControl[4]    $rectControl = ControlGetPos($strWindowTitle, $strWindowText, $strCheckboxId)    Local $posX = 0 ; X offset from upper left corner of checkbox    Local $posY = 0 ; Y offset from upper left corner of checkbox; baseline pixel luminosity should be relatively stable regardless of checkmark luminosity    $posX = 8   ; baseline X offset    $posY = 11  ; baseline Y offset    Local $rgblBaseline[4]    $rgblBaseline = GetColorAsRGBL($rectControl[0]+$posX,$rectControl[1]+$posY); checkmark pixel should alternate between 2 luminosities (one of which is similar to baseline)    $posX = 8   ; checkmark X offset    $posY = 6   ; checkmark Y offset    Local $rgblCheckmark[4]    $rgblCheckmark = GetColorAsRGBL($rectControl[0]+$posX,$rectControl[1]+$posY)    If Abs($rgblBaseline[$rgblLum] - $rgblCheckmark[$rgblLum]) > $intThreshold Then        Return 1    ;notable luminousity difference between checkmark and baseline    Else        Return 0    EndIf EndFunc  Func GetColorAsRGBL($posX,$posY);===============================================================================; Function Name: GetColorAsRGBL();   Description: returns an array containing (R,G,B,Lum) values. Lum is useful;               for seeking relative intensity change regardless of RGB value;        Entry: $posX,$posY are the (x,y) coordinates of the pixel;         Exit: $colorRGBL is (R,G,B,Lum) array of integers in range of 0-255;      Created: 2008-01-09;       Author: Ed Allwein, Active Sensing, Inc.  www.BuyPLM.com;===============================================================================    Local Enum $rgblRed=0, $rgblGreen=1, $rgblBlue=2, $rgblLum=3    Local Const $maskRed = 0x0FF0000    Local Const $maskGreen = 0x0FF00    Local Const $maskBlue = 0x0FF        Local $colorRGB[3]  ; Lum is omitted during Min/Max tests     Local $colorRGBL[4]    Local $intColorValue = 0    $intColorValue = PixelGetColor($posX,$posY)     $colorRGB[$rgblRed] = BitShift(BitAND($intColorValue, $maskRed),16)    $colorRGBL[$rgblRed] = $colorRGB[$rgblRed]    $colorRGB[$rgblGreen] = BitShift(BitAND($intColorValue, $maskGreen),8)    $colorRGBL[$rgblGreen] = $colorRGB[$rgblGreen]    $colorRGB[$rgblBlue] = BitAND($intColorValue, $maskBlue)    $colorRGBL[$rgblBlue] = $colorRGB[$rgblBlue]; calculate luminosity of pixel    $colorRGBL[$rgblLum] = Round((_ArrayMax($colorRGB, 1) + _ArrayMin($colorRGB, 1)) / 2)    Return $colorRGBLEndFunc

转载于:https://www.cnblogs.com/zhaojin/archive/2011/12/27/AutoIt.html

你可能感兴趣的文章
寄Android开发Gradle你需要知道的知识
查看>>
简述spring中常有的几种advice?
查看>>
牛客网——华为机试(题21:简单密码)(Java)
查看>>
学习Redux之分析Redux核心代码分析
查看>>
STL bind1st bind2nd详解
查看>>
Hive2.x 版本的安装及配置 以及要注意的事项
查看>>
window 如何访问虚拟机的mapreduce(遇到的坑)
查看>>
【原创】大叔经验分享(31)CM金丝雀Canary报错
查看>>
李飞飞机器视觉课程笔记:第2课 K最近邻与线性分类器
查看>>
import keras,tensorflow,出现kernel died restarting,解决办法
查看>>
spring applicationContext.xml最全约束
查看>>
Linux系统下安装rz/sz命令及使用说明
查看>>
C#正则表达式(通俗易懂)
查看>>
matlab读取多个excel某列数据
查看>>
Starship Troopers
查看>>
gulp前端自动化构建工具
查看>>
MQTT——订阅报文
查看>>
LinqToDB 源码分析——DataContext类
查看>>
django学习笔记之ORM入门
查看>>
sql 获取时间常用语句
查看>>