AutoIt 无法获取.net CheckBox 控件的状态
2011-12-27 16:49
393 查看
在AutoIt的帮助文档中, 提到可以用 ControlCommand函数判断checkbox是否选中,有个参数叫“IsChecked”, 但在实际的使用中,至少对.net的checkbox控件无效,网上有人给出了解决方法,原文地址:
http://www.autoitscript.com/forum/topic/61295-ischecked-not-working-with-controlcommand/
他自定义了一个方法,根据选中时控件的颜色变化来判断状态,这是一种新的思路。
http://www.autoitscript.com/forum/topic/61295-ischecked-not-working-with-controlcommand/
他自定义了一个方法,根据选中时控件的颜色变化来判断状态,这是一种新的思路。
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 $colorRGBL EndFunc
相关文章推荐
- 获取不到Repeater控件中的CheckBox选中状态
- 两层用户控件嵌套时最里层CheckBox无法初始化状态的问题解决
- 无法datalist里面的CheckBox控件选中状态
- 获取不到Repeater控件中的CheckBox选中状态的解決方案
- 获取ListControl控件中(复选框)CheckBox的状态
- 获取ListControl控件中(复选框)CheckBox的状态
- ASP.NET WebForm 的CheckBoxList控件通过js获取Value值问题
- win32 获取edit内容与把内容显示到edit控件上和设置控件无效状态
- 【iOS开发-12】UISwitch开关控件属性介绍以及获取开关状态并做出响应
- [第三方]SCNetworkReachability 获取网络状态控件使用方法
- 如何在Windows Form控件TreeView中遍历和查找指定的CheckBox状态
- FLEX 构建完美的带有CheckBox三状态的Tree控件(checkTree)[附测试下载]
- 无法从节点 XXX 状态 2 获取集群磁盘 3 的 SCSI 第 83h 页 VPD 描述符
- .NET----使用母版页后,控件名称自动生成导致js无法正常操作.net控件的问题
- .net(web) 根据 控件id 获取服务器端控件并进行操作
- 关于使用jspSmartUpload控件无法获取表单数据
- 一起谈.NET技术,关于Winform下,获取Treeview中CheckBox选中项的技巧
- 学习使用TreeView 控件的TreeNode 对象来获取选中了CheckBox的节点!
- js遍历gridview中某个CheckBox控件并获取选中值
- wex5中使用password控件,密码可以隐藏,判断输入框是否为空时,无法通过password的.val()方法获取数据