13lack13lade

Check Checkbox by Name

6 posts in this topic

Hi All!

Feel like a noob here but im trying to get the status of a check box or just simply set it to checked.

I have tried controlclick, controlcommand, without luck... i think it is due to only being able to select the checkbox by name...

Here is the autoit window info:

 

window.png

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

3 hours ago, 13lack13lade said:

just simply set it to checked.

I have tried controlclick

Does this code really not work?

WinActivate("Personal Options")
ControlClick("Personal Options", "", "[NAME:chkShortPortfolios]")

Also try this

ControlSend("Personal Options", "", "[NAME:chkShortPortfolios]", "{space}")
; or
ControlCommand("Personal Options", "", "[NAME:chkShortPortfolios]", "SendCommandID", 0xF5) ; $BM_CLICK

 

Edited by InnI

Share this post


Link to post
Share on other sites

Hi Innl

Thanks for your help!

The only one that works is :

ControlSend("Personal Options", "", "[NAME:chkShortPortfolios]", "{space}")

and that is not viable as the checkbox might already be ticked in which case that would uncheck it.

Share this post


Link to post
Share on other sites
#include "CUIAutomation2.au3"

$Checked = _GetCheckBoxState(ControlGetHandle("Personal Options", "", "[NAME:chkShortPortfolios]"))
If Not @error And Not $Checked Then ControlSend("Personal Options", "", "[NAME:chkShortPortfolios]", "{space}")

Func _GetCheckBoxState($hControl)
  Local $oUIAutomation, $pElement, $oElement, $iState, $iErrorCode
  $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
  If Not IsObj($oUIAutomation) Then Return SetError(1, 0, -1)
  $oUIAutomation.ElementFromHandle($hControl, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return SetError(2, 0, -1)
  $iErrorCode = $oElement.GetCurrentPropertyValue($UIA_ToggleToggleStatePropertyId, $iState)
  If $iErrorCode Then Return SetError(3, 0, -1)
  Return $iState
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Can this not be made to work with:

If Not ControlCommand("Personal Options", "", "[NAME:chkShortPortfolios]", "IsChecked") Then
  ControlCommand("Personal Options", "", "[NAME:chkShortPortfolios]", "Check")
EndIf

Edit: Oops, need to add a NOT into that IsChecked

Edited by SlackerAl

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Share this post


Link to post
Share on other sites

Slacker, unfortunately that does not work as i cannot control the object using usual methods for some reason that is the whole dilemma.

Fortunately InnI has provided a solution for me! - Thank you !!!! will be using this IUIAutomation in the future !!!!!!

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