Jump to content

GUI checkbox question


automatic
 Share

Recommended Posts

hi all,

i am writing a script where the script woud keep testing for the condition of the checkbox, perform a task when checkbox is CHECKED and vice versa. the problem i have encountered is that i have to CLICK on the checkbox for it to test for the condition of the checkbox. How can i make it so it will keep automatically check for the condition of the checkbox without the user clicking on it?

my code is listed below,

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <GuiConstantsEx.au3>

#include <WindowsConstants.au3>

#include <TreeViewConstants.au3>

_Main()

Func _Main()

Local $hGUI,$msg,$box1info

Local $box1

; Create GUI

$hGUI = GUICreate("checkbox test", 150, 100)

GUISetState()

GuiCtrlCreateGroup("checkbox", 5, 5)

$box1 = GUICtrlCreateCheckbox("checkbox1", 20, 60, 100)

Do

$msg = GUIGetMsg()

Select

case $msg = $box1

$box1info = guictrlread($box1)

if $box1info = $GUI_CHECKED then

run("notepad")

sleep(500)

send("x")

elseif $box1info = $GUI_UNCHECKED then

run("notepad")

sleep(500)

send(y)

endif

EndSelect

Until GUIGetMsg() = $GUI_EVENT_CLOSE

Endfunc

Link to comment
Share on other sites

But be careful, this way the script will open up notepad instances on and on... thats why i added a timerdiff check to limit execution to every 5 secs and set the gui to topmost :)...

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>

_Main()

Func _Main()
    Local $hGUI, $msg, $box1info
    Local $box1

    ; Create GUI
    $hGUI = GUICreate("checkbox test", 150, 100, Default, Default, Default, $WS_EX_TOPMOST)
    GUISetState()
    GUICtrlCreateGroup("checkbox", 5, 5)
    $box1 = GUICtrlCreateCheckbox("checkbox1", 20, 60, 100)

    $begin = TimerInit()
    
    Do
        $msg = GUIGetMsg()

        If TimerDiff($begin) > 5000 Then
            $begin = TimerInit()
            If GUICtrlRead($box1) = $GUI_CHECKED Then
                Run("notepad")
                Sleep(500)
                Send("x")
            ElseIf GUICtrlRead($box1) = $GUI_UNCHECKED Then
                Run("notepad")
                Sleep(500)
                Send("y")
            EndIf
        EndIf

        Sleep(10)

    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main
Edited by KaFu
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...