Sign in to follow this  
Followers 0
plmguy

IsChecked not working with ControlCommand()

8 posts in this topic

I'm trying to obtain the IsChecked status of a .NET 2 checkbox (CLASS: WindowsForms10.BUTTON.app.0.2004eee) using ControlCommand()

I have been able to obtain the checkbox's IsVisible and IsEnabled status without a problem, and am able to obtain other checkbox info (control handle, instance number, text), so I'm pretty sure I have the function syntax correct. However, simply replacing "IsEnabled" with "IsChecked" always returns value of 0, regardless of actual checkbox state.

I've tried both enabling & disabling the checkbox prior to reading the IsChecked value. I've even tried obtaining the control text and stuffing it into the ControlCommand():

$strControlText = ControlGetText($strWindowTitle, "", $strControlId)
$intStatusValue = ControlCommand($strWindowTitle, $strControlText, $strControlId, "IsChecked", "")
I've used both ClassNN and ControlGetHandle() for the $strControlId argument.

@error shows no problem in calling ControlCommand()

I'm using AutoIt 3.2.10.0 under Virtual PC running WinXP (SP2)

Any ideas on the problem?

(BTW, I've also tried _SendMessage() with BM_GETSTATE, no better results.)

Thanks for any help!

Share this post


Link to post
Share on other sites



Hi,

Wellcome!

Have you tried use a class name:

$intStatusValue = ControlCommand($strWindowTitle, $strControlText, "[CLASS:WindowsForms10.BUTTON.app.0.2004eee]", "IsChecked")

Also from help file:

Some controls will resist automation unless they are the active window. Use the WinActive() function to force the control's window to the top before using ControlCommand() on these controls.

Maybe this is the case, try to activate the window.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Hi, MsCreatoR, I appreciate your help.

In fact, I get the ControlId handle in the first place by using the class name and screen coordinates, and iterating through all the controls for a match based on ControlGetPos().

I've previously tried using WinActive() and - because I think it makes more sense in the context - WinActivate() prior to the call. I didn't see any effect.

But the curious thing is that both of these (and a few others I've tried) would be used if the control's identity is elusive, when in fact I can easily obtain the correct instance, ID, handle, text, etc. Using ControlCommand() for "IsEnabled" on those checkboxes works just fine... it's only "IsChecked" that's resisting me.

I suspect that the code in ControlCommand() extracts the "IsChecked" status differently from "IsVisible" and "IsEnabled" and, in this particular case, that difference is causing my problem. The problem may go to how the WinAPI is being called, and may be why my _SendMessage($ctrlHnd,0x0F0,0,0) isn't working either. Is there a way to view the ControlCommand() source? I hate to make a nuisance of myself in my first post, and I'd prefer to see someone confirm/disprove my problem before suspecting a bug. :)

Thanks for your suggestions.

Share this post


Link to post
Share on other sites

After further exploration, I'm *assuming* that ControlCommand() uses Windows API function SendMessage().

MSDN says (http://msdn2.microsoft.com/en-us/library/bb775986(VS.85).aspx):

"The return value from a button created with the BS_AUTOCHECKBOX, BS_AUTORADIOBUTTON, BS_AUTO3STATE, BS_CHECKBOX, BS_RADIOBUTTON, or BS_3STATE style can be one of the following....

"If the button has a style other than those listed, the return value is zero."

So, I guess the state of a .NET checkbox is not available within AutoIt.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For those interested, this is how I solved the problem. While it's a work-around for identifying the .NET checkbox IsChecked state, I think it can be used for any checkbox control. I've tested it only on WinXP and Vista, older Windows may require changes in pixel locations.

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

Requires this utility function:

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
Edited by plmguy

Share this post


Link to post
Share on other sites

hi,plmguy,I tried your solution on win7 , but it didn't work, can you or anyone else give me some help? Thanks

Share this post


Link to post
Share on other sites

Please open a new thread, and when you do could you please give a lot more information in regards to the problem you're having, the expected outcome, any error messages you're getting, and AutoIt version and whether you're running Win7 x64 or x86, also if you're running the script as x64 or x86.

This thread is 5 years old, and plmguy hasn't been online since this thread died.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Please open a new thread, and when you do could you please give a lot more information in regards to the problem you're having, the expected outcome, any error messages you're getting, and AutoIt version and whether you're running Win7 x64 or x86, also if you're running the script as x64 or x86.

This thread is 5 years old, and plmguy hasn't been online since this thread died.

sorry for reply for a long period thread , I have opened a new thread, Thanks for help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0