Sign in to follow this  
Followers 0
lakshmi10

Get the State of a Checkbox in a .Net Windows Application

2 posts in this topic

Hi,

I am writing scripts to automate a .Net Windows based application. In the application i need to verify whether a checkbox is selected or not (i.e. need to get the state of a checkbox). I used the below mentioned code snippets. Everytime the message "Not Checked" is displayed irrespective whether the checkbox is selected or not.

; Using GUICtrlRead

#include <GUIConstants.au3>

$hndl = WinGetHandle(WinGetTitle("Test",""),"")

WinActivate($hndl,"")

$chndl = ControlGetHandle($hndl,"","WindowsForms10.BUTTON.app.0.21af1a517")

if BitAnd(GUICtrlRead($chndl),$GUI_CHECKED) = $GUI_CHECKED then

MsgBox(1, "Status", "Checked")

else

MsgBox(1, "Status", "Not Checked")

endif

;Using _SendMessage Function

Global Const $BM_GETSTATE = 0xF0

$hndl = WinGetHandle(WinGetTitle("Test",""),"")

WinActivate($hndl,"")

$chndl = ControlGetHandle($hndl,"","WindowsForms10.BUTTON.app.0.21af1a517")

$chkstat = _SendMessage($chndl, $BM_GETSTATE, 0, 0)

if $chkstat= 0 then

MsgBox(1, "Status", "Not checked")

else

MsgBox(1, "Status", "Checked")

endif

;Using ControlCommand Function

$hndl = WinGetHandle(WinGetTitle("Test",""),"")

WinActivate($hndl,"")

$chndl = ControlGetHandle($hndl,"","WindowsForms10.BUTTON.app.0.21af1a517")

$chkstat= ControlCommand($hndl,"",$chndl ,"IsChecked")

if $chkstat= 0 then

MsgBox(1, "Status", "Not checked")

else

MsgBox(1, "Status", "Checked")

endif

Please let me know what is wrong in the above mentioned code snippets or let me know if you have any alternative solution.

Thanks in advance.

Share this post


Link to post
Share on other sites



Afaik GUICtrlRead and ControlCommand work with the ControlID, not the control handle, but I may be wrong.

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