Jump to content

Checking state of a checkbox that has two states


Recommended Posts

OK, the title might be a little confusing, but it's not. (NOTE: please do not post CODE. I am trying to teach myself how to write scripts, let me figure it out with some hints if you have them)

There is an application that runs on startup, sits in the system tray, and has a default setting that is annoying (and won't save). It also has the bad habit of going into a high CPU use mode if I remote into the machine, so I also need my app to restart this from a shortcut on the desktop. Simple enough.

So I make a script (full source below) to bring the app up, uncheck the check for the annoying option, then minimize. Perfect, all is happy. Except that I got curious.

The checkbox has three states - checked, semi-checked (the check is grey), and unchecked. Since it always starts up checked, my script brings the window up then double-taps the hotkey to uncheck it. Brute force, and not elegant.

So I got curious about checking the status of this checkbox, and for the life of me can't find the answer. This is not in an AutoIT GUI, it's a commercial application.

What function(s) will check the status of a checkbox in this case (not an AutoIt gui)?

Remember, hints only please, no spoilers!

;the control I got curious about

>>>> Control <<<<
Class:  Button
Instance:   9
ClassnameNN:    Button9
Advanced (Class):   [CLASS:Button; INSTANCE:9]
ID: 1038
Text:   Open &with PIN
Position:   75, 436
Size:   92, 16
ControlClick Coords:    57, 9
Style:  0x50010006
ExStyle:    0x00000004
Handle: 0x00010568

; Script below

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\..\KickCDSetup.ico
#AutoIt3Wrapper_outfile=KickCDSetup.exe
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
;Just thought I'd make something useful
;v 2.0
;now waits for cdsetup and sets the pin cache off, useful in startup
;ToDo - make a loop that will time out and exit if app not found after xx minutes
#include <ServiceControl.au3>
#include <WinAPI.au3>

Global $cdsetup, $error, $hControl, $hWnd, $i, $nDelay, $noRun, $oldChildMode, $oldMatchMode
Global $posStart, $posWin, $WINTITLE, $wkstatn, $x, $y

_ChkSrv()
_doKickCDSetup()
Sleep(5000)
_ChkSrv()
_setNoPin()


;--------------------------------------------------------------------------------
; setNoPin unchecks the pin cache option
;--------------------------------------------------------------------------------
Func _setNoPin()
    local $WINTITLE = "SECUDE Profile Manager"
; restore window
   WinSetState($WINTITLE,'',@SW_RESTORE)
   winactivate($WINTITLE)
; button 9
    Send("!w")
    Send("!w")
    WinSetState($WINTITLE,'',@SW_HIDE)
EndFunc  ;==>_setNoPin

;--------------------------------------------------------------------------------
; ChkSrv() looks for the services/app to be running
;--------------------------------------------------------------------------------
Func _ChkSrv()
    While $noRun = 0
        Do
            $i = 0
            If ProcessExists("cdsetup.exe") Then
                $cdsetup = 1
            EndIf
        ; These functions must take place outside the if...then
            $i = $i + $cdsetup
        ;Meter($i)
            $cdsetup = 0
            Sleep(1500)
        Until $i = 1
        $noRun = 1
    WEnd
EndFunc  ;==>_ChkSrv

;--------------------------------------------------------------------------------
; doKickCDSetup() restarts cdsetup
;--------------------------------------------------------------------------------
Func _doKickCDSetup()
    SplashTextOn("Kick CDSetup", "Restarting CDSetup", 200, 50)
    Run("taskkill /im cdsetup.exe /f", "", @SW_HIDE)
    Sleep(1000)
    Call("_RefreshSystemTray")
    Sleep(1000)
;odd, if we execute cdsetup without explicit path an installdir folder pops into the current folder when the exe is run (e.g., the desktop)
    Run("C:\Program Files\SECUDE\cdsetup.exe", "C:\Program Files\SECUDE\", @SW_MINIMIZE)
EndFunc  ;==>_doKickCDSetup

; ===================================================================
; _RefreshSystemTray($nDelay = 1000)
; by Valik = http://www.autoitscript.com/forum/index.php?showuser=39
; Removes any dead icons from the notification area.
; Parameters:
;   $nDelay - IN/OPTIONAL - The delay to wait for the notification area to expand with Windows XP's
;       "Hide Inactive Icons" feature (In milliseconds).
; Returns:
;   Sets @error on failure:
;       1 - Tray couldn't be found.
;       2 - DllCall error.
; ===================================================================
Func _RefreshSystemTray($nDelay = 1000)
; Save Opt settings
    Local $oldMatchMode = Opt("WinTitleMatchMode", 4)
    Local $oldChildMode = Opt("WinSearchChildren", 1)
    Local $error = 0
    Do; Pseudo loop
        Local $hWnd = WinGetHandle("classname=TrayNotifyWnd")
        If @error Then
            $error = 1
            ExitLoop
        EndIf

        Local $hControl = ControlGetHandle($hWnd, "", "Button1")

    ; We're on XP and the Hide Inactive Icons button is there, so expand it
        If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
            ControlClick($hWnd, "", $hControl)
            Sleep($nDelay)
        EndIf

        Local $posStart = MouseGetPos()
        Local $posWin = WinGetPos($hWnd)

        Local $y = $posWin[1]
        While $y < $posWin[3] + $posWin[1]
            Local $x = $posWin[0]
            While $x < $posWin[2] + $posWin[0]
                DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y)
                If @error Then
                    $error = 2
                    ExitLoop 3; Jump out of While/While/Do
                EndIf
                $x = $x + 8
            WEnd
            $y = $y + 8
        WEnd
        DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1])
    ; We're on XP so we need to hide the inactive icons again.
        If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
            ControlClick($hWnd, "", $hControl)
        EndIf
    Until 1

; Restore Opt settings
    Opt("WinTitleMatchMode", $oldMatchMode)
    Opt("WinSearchChildren", $oldChildMode)
    SetError($error)
EndFunc  ;==>_RefreshSystemTray

; FUNCTIONS
; _ChkSrv(), _doKickCDSetup(), _RefreshSystemTray($nDelay = 1000), _setNoPin()

Always carry a towel.

Link to comment
Share on other sites

Have you tried checking the window info tool over the control in each of the three states to see if it changes?

I had not, but just did. The only thing that changes is the click coordinates (which is the location I clicked to change the check state).

Not the answer but thanks for the advice!

Always carry a towel.

Link to comment
Share on other sites

Nuts, no edit controls for my post. :-(

Code now has a timer (for startup purposes). Still no checkbox-checking, but I might look into the ability to look at pixels onscreen tomorrow (unless work intervenes).

;Just thought I'd make something useful
;v 3.0
;Looks for an app to be running, if not keeps looking for 10 minutes.
;Once app is running it restarts it, then sets a checkbox
;
;The app is known to use high CPU resources after remote desktop into machine 
;thus the restart
;
;the checkbox is an annoyance
;--------------------------------------------------------------------------------

#include <ServiceControl.au3>
#include <WinAPI.au3>

Global $cdsetup, $error, $hControl, $hWnd, $i, $iCounter, $iCounter = TimerInit(), $nDelay
Global $noRun, $oldChildMode, $oldMatchMode, $posStart, $posWin, $waitTime, $WINTITLE, $wkstatn
Global $x, $y


;seconds to wait (e.g., 10*60 = 10 minutes)
$waitTime = 10 * 60

_ChkSrv()
_doKickCDSetup()
Sleep(5000)
_ChkSrv()
_setNoPin()

;--------------------------------------------------------------------------------
; ChkSrv() looks for the services/app to be running, will run for value of $waitTime
;--------------------------------------------------------------------------------
Func _ChkSrv()
    Dim $iCounter = TimerInit()
    Do
        $noRun = 0
        $i = 0
        If ProcessExists("cdsetup.exe") Then
            $cdsetup = 1
        EndIf
    ; These functions must take place outside the if...then
        $i = $i + $cdsetup
        $cdsetup = 0
        Sleep(1500)
        If $i = 1 Then
            $iCounter = $waitTime
        Else
            $noRun = 0
        EndIf
    Until TimerDiff($iCounter) / 1000 > $waitTime
EndFunc  ;==>_ChkSrv

;--------------------------------------------------------------------------------
; setNoPin unchecks the pin cache option
;--------------------------------------------------------------------------------
Func _setNoPin()
    Local $WINTITLE = "SECUDE Profile Manager"
; restore window
    WinSetState($WINTITLE, '', @SW_RESTORE)
    WinActivate($WINTITLE)
; button 9
    Send("!w")
    Send("!w")
    WinSetState($WINTITLE, '', @SW_HIDE)
EndFunc  ;==>_setNoPin

;--------------------------------------------------------------------------------
; doKickCDSetup() restarts cdsetup
;--------------------------------------------------------------------------------
Func _doKickCDSetup()
    SplashTextOn("Kick CDSetup", "Restarting CDSetup", 200, 50)
    Run("taskkill /im cdsetup.exe /f", "", @SW_HIDE)
    Sleep(1000)
    Call("_RefreshSystemTray")
    Sleep(1000)
;odd, if we execute cdsetup without explicit path an installdir folder pops into the current folder when the exe is run (e.g., the desktop)
    Run("C:\Program Files\SECUDE\cdsetup.exe", "C:\Program Files\SECUDE\", @SW_MINIMIZE)
EndFunc  ;==>_doKickCDSetup

; ===================================================================
; _RefreshSystemTray($nDelay = 1000)
; by Valik = http://www.autoitscript.com/forum/index.php?showuser=39
; Removes any dead icons from the notification area.
; Parameters:
;   $nDelay - IN/OPTIONAL - The delay to wait for the notification area to expand with Windows XP's
;       "Hide Inactive Icons" feature (In milliseconds).
; Returns:
;   Sets @error on failure:
;       1 - Tray couldn't be found.
;       2 - DllCall error.
; ===================================================================
Func _RefreshSystemTray($nDelay = 1000)
; Save Opt settings
    Local $oldMatchMode = Opt("WinTitleMatchMode", 4)
    Local $oldChildMode = Opt("WinSearchChildren", 1)
    Local $error = 0
    Do; Pseudo loop
        Local $hWnd = WinGetHandle("classname=TrayNotifyWnd")
        If @error Then
            $error = 1
            ExitLoop
        EndIf

        Local $hControl = ControlGetHandle($hWnd, "", "Button1")

    ; We're on XP and the Hide Inactive Icons button is there, so expand it
        If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
            ControlClick($hWnd, "", $hControl)
            Sleep($nDelay)
        EndIf

        Local $posStart = MouseGetPos()
        Local $posWin = WinGetPos($hWnd)

        Local $y = $posWin[1]
        While $y < $posWin[3] + $posWin[1]
            Local $x = $posWin[0]
            While $x < $posWin[2] + $posWin[0]
                DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y)
                If @error Then
                    $error = 2
                    ExitLoop 3; Jump out of While/While/Do
                EndIf
                $x = $x + 8
            WEnd
            $y = $y + 8
        WEnd
        DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1])
    ; We're on XP so we need to hide the inactive icons again.
        If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
            ControlClick($hWnd, "", $hControl)
        EndIf
    Until 1

; Restore Opt settings
    Opt("WinTitleMatchMode", $oldMatchMode)
    Opt("WinSearchChildren", $oldChildMode)
    SetError($error)
EndFunc  ;==>_RefreshSystemTray

Always carry a towel.

Link to comment
Share on other sites

Load up the help and check out the function called _GUICtrlButton_GetState()

WBD

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...