Jump to content
DazGizmo

Getting state from a Check Box in another program

Recommended Posts

DazGizmo

Really battling with this one as I cannot get the info of the state of the Checkbox... using and testing many references for "IsChecked" to no avail...

Anything I am doing wrong or you can suggest please?

Tries:

1. ControlFocus($hWnd, "Material Editor", "[HANDLE:0x00000000000814B4]") ;Fresnel True
            Send("{+}")

2.  ControlCommand($hWnd, "Material Editor", "[CLASSNN:WindowsForms10.BUTTON.app.0.32b818c_r12_ad118]", "IsChecked", "")

3. ControlCommand($hWnd, "Material Editor", "[NAME:FresnelCheckBox]", "IsChecked", "")

 

These work but do the same thing:

ControlCommand($hWnd, "Material Editor", "[NAME:FresnelCheckBox]", "Check", "")  ;will uncheck if already checked

ControlCommand($hWnd, "Material Editor", "[NAME:FresnelCheckBox]", "UnCheck", "") ;will check if already unchecked

ARtiCAD V21 - Cannot get ticked state from the Fresnel Tick Box.jpg

Share this post


Link to post
Share on other sites
Malkey

Try this example. 
It successfully returned the state of a checkbox in the AutoIt help file.

I have modified this script for your  needs.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()


Func Example()
    Local $sWinTitle = "Material Editor" ; Tested on "AutoIt Help (v3.3.14.5)" window.
    WinActivate($sWinTitle, "")
    WinWaitActive($sWinTitle, "")

    ;If _IsChecked($sWinTitle, 'Button4') Then ; Again tested on 'Button4' - Under Search tab of AutoIt Help Window.
    If _IsChecked($sWinTitle, "WindowsForms10.BUTTON.app.0.32b818c_r12_ad118") Then 
        MsgBox(0, "", "The checkbox is checked.")
    Else
        MsgBox(0, "", "The checkbox is not checked.")
    EndIf
EndFunc   ;==>Example

; Modified from GUICtrlCreateCheckbox function example in AutoIt Help file.
Func _IsChecked($sWinTitle, $sControlClassnameNN)
    ;Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
    Return ControlCommand($sWinTitle, "", $sControlClassnameNN, "IsChecked", "")
EndFunc   ;==>_IsChecked

 

Share this post


Link to post
Share on other sites
DazGizmo
23 minutes ago, Malkey said:

Try this example. 
It successfully returned the state of a checkbox in the AutoIt help file.

I have modified this script for your  needs.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()


Func Example()
    Local $sWinTitle = "Material Editor" ; Tested on "AutoIt Help (v3.3.14.5)" window.
    WinActivate($sWinTitle, "")
    WinWaitActive($sWinTitle, "")

    ;If _IsChecked($sWinTitle, 'Button4') Then ; Again tested on 'Button4' - Under Search tab of AutoIt Help Window.
    If _IsChecked($sWinTitle, "WindowsForms10.BUTTON.app.0.32b818c_r12_ad118") Then 
        MsgBox(0, "", "The checkbox is checked.")
    Else
        MsgBox(0, "", "The checkbox is not checked.")
    EndIf
EndFunc   ;==>Example

; Modified from GUICtrlCreateCheckbox function example in AutoIt Help file.
Func _IsChecked($sWinTitle, $sControlClassnameNN)
    ;Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
    Return ControlCommand($sWinTitle, "", $sControlClassnameNN, "IsChecked", "")
EndFunc   ;==>_IsChecked

 

Many Thanks Malkey for your efforts but it is not returning the correct state as it says Not Checked when It is Checked....
Could it be anything to do with the program being 64bit?

ArtiCAD V21 - Fresnel Checkbox code not returning correct state.jpg

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

I believe that windowform controls use a type of guid at runtime for the ID and class...you should probably use the name.

https://www.autoitscript.com/autoit3/docs/intro/controls.htm

[NAME:FresnelCheckBox]

Use ControlGetHandle to first get the handle of the control...output that so that you can check that you even have the correct 'button' before even sending it (the handle) to the _IsChecked function.

 

Try this:

Func Example()
    Local $sWinTitle = "Material Editor"
    $hWin = WinGetHandle($sWinTitle)
    If Not IsHWnd($hWind) Then
        MsgBox(1,1,"window does not exist")
        Return False
    EndIf
    WinActivate($hWin)
    $hControl = ControlGetHandle($hWin,"","[NAME:FresnelCheckBox]")
    If Not IsHWnd($hControl) Then
        MsgBox(1,1,"couldn't identify control")
        Return False
    EndIf

    MsgBox(1,1,"Control found with handle=[" & $hControl & "]")

    If _IsChecked($hWin,$hControl) Then
        MsgBox(0, "", "The checkbox is checked.")
    Else
        MsgBox(0, "", "The checkbox is not checked.")
    EndIf
EndFunc   ;==>Example

Func _IsChecked($hWindow,$hControl)
    Return ControlCommand($hWindow,"",$hControl,"IsChecked","")
EndFunc   ;==>_IsChecked

 

In regards to your 64bit question: no, that does not matter.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
DazGizmo
14 hours ago, jdelaney said:

I believe that windowform controls use a type of guid at runtime for the ID and class...you should probably use the name.

https://www.autoitscript.com/autoit3/docs/intro/controls.htm

[NAME:FresnelCheckBox]

Use ControlGetHandle to first get the handle of the control...output that so that you can check that you even have the correct 'button' before even sending it (the handle) to the _IsChecked function.

 

Try this:

Func Example()
    Local $sWinTitle = "Material Editor"
    $hWin = WinGetHandle($sWinTitle)
    If Not IsHWnd($hWind) Then
        MsgBox(1,1,"window does not exist")
        Return False
    EndIf
    WinActivate($hWin)
    $hControl = ControlGetHandle($hWin,"","[NAME:FresnelCheckBox]")
    If Not IsHWnd($hControl) Then
        MsgBox(1,1,"couldn't identify control")
        Return False
    EndIf

    MsgBox(1,1,"Control found with handle=[" & $hControl & "]")

    If _IsChecked($hWin,$hControl) Then
        MsgBox(0, "", "The checkbox is checked.")
    Else
        MsgBox(0, "", "The checkbox is not checked.")
    EndIf
EndFunc   ;==>Example

Func _IsChecked($hWindow,$hControl)
    Return ControlCommand($hWindow,"",$hControl,"IsChecked","")
EndFunc   ;==>_IsChecked

 

In regards to your 64bit question: no, that does not matter.

Thanks for your input but when I run it nothing happens, no msgbox's show up at all... I did change $hWin to $hWind and the Func _IsChecked ($hWindow to $hWind.....

ArtiCAD V21 - Fresnel Checkbox code not returning any infojpg.jpg

Share this post


Link to post
Share on other sites
jdelaney

You can't exercise the function without calling it


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
DazGizmo
21 minutes ago, jdelaney said:

You can't exercise the function without calling it

Okay... sorry forgot that...

It's still not reading it correctly... saying it's not checked when it is...

ArtiCAD V21 - Fresnel Checkbox code Not correctly giving the state.jpg

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

Did the handle returned match then handle of the control in the spy tool?

 

If they match, then work still needs to be done on _ischecked

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
DazGizmo
16 minutes ago, jdelaney said:

Did the handle returned match then handle of the control in the spy tool?

 

If they match, then work still needs to be done on _ischecked

I think they are the same.... not showing as many zero's though:
 

ArtiCAD 21 - Fresnel Checkbox Spytool results.jpg

Share this post


Link to post
Share on other sites
Danyfirex

I think BM_GETCHECK does not work with Net checkbox. You will need to hanble it with pixel color check. you could do this get a checkbox capture and check color or use pixelgetcolor.

 

Saludos

Share this post


Link to post
Share on other sites
DazGizmo
23 minutes ago, junkew said:

Check FAQ31 and check with simplespy what you get back. With IUIAutomation you should be able to get state of your checkbox

 

Yes, I have looked at your SimplySpy...... How would I go about coding the state and using it some pointers would be great... this is what I get running control+W:
 

https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1156373 
At least we have an element title: [Fresnel:] class: [WindowsForms10.BUTTON.app.0.32b818c_r12_ad1]

Having the following values for all properties: 
Title is: <Fresnel:>    Class   := <WindowsForms10.BUTTON.app.0.32b818c_r12_ad1>    controltype:= <UIA_CheckBoxControlTypeId>   ,<50002>    , (0000C352)    517;544;195;20
*** Parent Information top down ***
11: Title is: <Edit Default Material Selections>    Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_WindowControlTypeId> ,<50032>    , (0000C370)    191;147;1538;906
"Title:=Edit Default Material Selections;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""    
10: Title is: <Material Editor> Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_WindowControlTypeId> ,<50032>    , (0000C370)    482;185;955;830
"Title:=Material Editor;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1"" 
9: Title is: <> Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    505;230;908;725
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""  
8: Title is: <> Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    505;230;602;725
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""  
7: Title is: <> Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    505;230;602;725
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""  
6: Title is: <> Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    505;230;602;725
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""  
5: Title is: <> Class   := <WindowsForms10.SysTabControl32.app.0.32b818c_r12_ad1>   controltype:= <UIA_TabControlTypeId>    ,<50018>    , (0000C362)    505;273;602;682
"Title:=;controltype:=UIA_TabControlTypeId;class:=WindowsForms10.SysTabControl32.app.0.32b818c_r12_ad1""    
4: Title is: <Advanced> Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    509;297;594;654
"Title:=Advanced;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""  
3: Title is: <Colour:>  Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    509;297;594;654
"Title:=Colour:;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""   
2: Title is: <> Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    509;401;594;475
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""  
1: Title is: <Specular Settings>    Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    513;404;203;163
"Title:=Specular Settings;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1"" 
0: Title is: <No texture selected.> Class   := <WindowsForms10.Window.8.app.0.32b818c_r12_ad1>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    517;421;195;143
"Title:=No texture selected.;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1""  


;~ *** Standard code maintainable ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("oP1","Title:=Edit Default Material Selections;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")  ;Edit Default Material Selections
_UIA_setVar("oP2","Title:=Material Editor;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")   ;Material Editor
_UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")    ;
_UIA_setVar("oP4","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")    ;
_UIA_setVar("oP5","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")    ;
_UIA_setVar("oP6","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")    ;
_UIA_setVar("oP7","Title:=;controltype:=UIA_TabControlTypeId;class:=WindowsForms10.SysTabControl32.app.0.32b818c_r12_ad1")  ;
_UIA_setVar("oP8","Title:=Advanced;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")    ;Advanced
_UIA_setVar("oP9","Title:=Colour:;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1") ;Colour:
_UIA_setVar("oP10","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")   ;
_UIA_setVar("oP11","Title:=Specular Settings;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")  ;Specular Settings
_UIA_setVar("oP12","Title:=No texture selected.;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1")   ;No texture selected.

_UIA_setVar("Fresnel:.mainwindow","title:=Fresnel:;classname:=WindowsForms10.BUTTON.app.0.32b818c_r12_ad1")

;~ Actions split away from logical/technical definition above can come from configfiles 

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")
;~_UIA_Action("oP2","highlight")
_UIA_Action("oP2","setfocus")
;~_UIA_Action("oP3","highlight")
_UIA_Action("oP3","setfocus")
;~_UIA_Action("oP4","highlight")
_UIA_Action("oP4","setfocus")
;~_UIA_Action("oP5","highlight")
_UIA_Action("oP5","setfocus")
;~_UIA_Action("oP6","highlight")
_UIA_Action("oP6","setfocus")
;~_UIA_Action("oP7","highlight")
_UIA_Action("oP7","setfocus")
;~_UIA_Action("oP8","highlight")
_UIA_Action("oP8","setfocus")
;~_UIA_Action("oP9","highlight")
_UIA_Action("oP9","setfocus")
;~_UIA_Action("oP10","highlight")
_UIA_Action("oP10","setfocus")
;~_UIA_Action("oP11","highlight")
_UIA_Action("oP11","setfocus")
;~_UIA_Action("oP12","highlight")
_UIA_Action("oP12","setfocus")

_UIA_action("Fresnel:.mainwindow","setfocus")


;~ *** Standard code Flexible***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP11=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Edit Default Material Selections;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)    
_UIA_Action($oP11,"setfocus")
Local $oP10=_UIA_getObjectByFindAll($oP11, "Title:=Material Editor;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children) 
_UIA_Action($oP10,"setfocus")
Local $oP9=_UIA_getObjectByFindAll($oP10, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)   
_UIA_Action($oP9,"setfocus")
Local $oP8=_UIA_getObjectByFindAll($oP9, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)    
_UIA_Action($oP8,"setfocus")
Local $oP7=_UIA_getObjectByFindAll($oP8, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)    
_UIA_Action($oP7,"setfocus")
Local $oP6=_UIA_getObjectByFindAll($oP7, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)    
_UIA_Action($oP6,"setfocus")
Local $oP5=_UIA_getObjectByFindAll($oP6, "Title:=;controltype:=UIA_TabControlTypeId;class:=WindowsForms10.SysTabControl32.app.0.32b818c_r12_ad1", $treescope_children)  
_UIA_Action($oP5,"setfocus")
Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=Advanced;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)    
_UIA_Action($oP4,"setfocus")
Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=Colour:;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children) 
_UIA_Action($oP3,"setfocus")
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)    
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Specular Settings;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)   
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=No texture selected.;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.32b818c_r12_ad1", $treescope_children)    
_UIA_Action($oP0,"setfocus")
_UIA_setVar("Fresnel:.mainwindow","title:=Fresnel:;classname:=WindowsForms10.BUTTON.app.0.32b818c_r12_ad1")
_UIA_action("Fresnel:.mainwindow","setfocus")


*** Detailed properties of the highlighted element ***
UIA_title:= <Fresnel:>
UIA_text:= <Fresnel:>
UIA_regexptitle:= <Fresnel:>
UIA_class:= <WindowsForms10.BUTTON.app.0.32b818c_r12_ad1>
UIA_regexpclass:= <WindowsForms10.BUTTON.app.0.32b818c_r12_ad1>
UIA_iaccessiblechildId:= <0>
UIA_id:= <FresnelCheckBox>
UIA_handle:= <71774>
UIA_RuntimeId:= <42;71774>
UIA_BoundingRectangle:= <517;544;195;20>
; Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <False>

 

Share this post


Link to post
Share on other sites
DazGizmo
1 hour ago, Danyfirex said:

I think BM_GETCHECK does not work with Net checkbox. You will need to hanble it with pixel color check. you could do this get a checkbox capture and check color or use pixelgetcolor.

 

Saludos

Thanks for your input Saludos.... I have read in a few places about grabbing the pixel colour but would rather find a better method if possible...

Share this post


Link to post
Share on other sites
AdamUL

Check the @error value returned by _IsChecked to make sure the ControlCommand function is not throwing an error.  Replace the _IsChecked call with the following.  

Local $iIsChecked = _IsChecked($hWin, $hControl) 
    Local $iIsCheckedError = @error

    If $iIsChecked And Not $iIsCheckedError Then
        MsgBox(0, "", "The checkbox is checked.")
    ElseIf Not $iIsChecked And Not $iIsCheckedError Then
        MsgBox(0, "", "The checkbox is not checked.")
    Else
        MsgBox(16, "ERROR!", 'Error with ControlCommand "IsChecked"')
    EndIf

Also, when I have had to automate some hard to automate controls to I've use a loop with IsChecked and and UnCheck.  Example below.  

Global $sDialogTitle = "[CLASS:WindowsForms10.Window.8.app.0.32b818c_r12_ad1; TEXT:Material Editor]"
Global $sDialogText = ""
Global $sControlInfo = "[CLASS:WindowsForms10.BUTTON.app.0.32b818c_r12_ad1; TEXT:Fresnel:]"

While ControlCommand($sDialogTitle, $sDialogText, $sControlInfo, "IsChecked", "")
    ControlCommand($sDialogTitle, $sDialogText, $sControlInfo, "UnCheck", "")
WEnd

 

Adam

 

Share this post


Link to post
Share on other sites
jdelaney

You can also try the function

_guictrlbutton_getchecked


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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

×