Jump to content

Button problem


Go to solution Solved by DatMCEyeBall,

Recommended Posts

:/ Why manage the buttons in autoit is hard... Or i don't know how do this..

it doesn't work..

I want to create in my program something like this:

I have 3 buttons and 3 functions: Start, Pause, Exit

1. When i click Pause i cant click Start but i can click exit

2. When i unclick pause i can click start and exit

3. When i click start i can click pause and exit

i dont know how to do that;/

For now i dont have only third step

Link to comment
Share on other sites

  • Solution

I started this recursion mess, so I'll fix it.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ; Switch to event mode

Global $fRunning = True
Global $fPaused = False
Global $fCounting = False
Global $iCount = 0

$Form1 = GUICreate("Form1", 310, 437, 345, 194)
$Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Exit", 80, 70, 75, 25, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Count", 80, 95, 75, 25, $WS_GROUP)

; Register events
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlSetOnEvent($Button2, "_Pause")
GUICtrlSetOnEvent($Button3, "_Exit")
GUICtrlSetOnEvent($Button4, "_Count")

HotKeySet("p", "_Pause")

GUISetState(@SW_SHOW)

Global $hTimer = TimerInit()
While $fRunning
    If Not $fPaused Then ;Only do other stuff when we are not paused
        If $fCounting And TimerDiff($hTimer) >= 1000 Then
            $hTimer = TimerInit()
            $iCount += 1
            ToolTip("Time: " & $iCount, 0, 0)
        EndIf
    EndIf
    Sleep(100) ; Sleep to avoid high CPU usage
WEnd

Func _Pause()
    $fPaused = Not $fPaused
    If Not $fPaused Then
        _ShowTip("Program is running", 0, 0)
        GUICtrlSetData($Button2, "Pause")
    Else
        _ShowTip("Program is paused", 0, 0)
        GUICtrlSetData($Button2, "Run")
    EndIf
EndFunc   ;==>_Pause

Func _Count()
    If _CheckIfPaused() Then Return ; Checks if the fPaused flag is set, and returns if so
    $fCounting = Not $fCounting
    If Not $fCounting Then
        _ShowTip("Counting stopped")
    EndIf
EndFunc   ;==>_Count

Func _Exit()
    ; Uncomment if you want the user to be able to exit if the script is paused
;~  If _CheckIfPaused() Then Return
    $fRunning = False
EndFunc   ;==>_Exit

Func _CheckIfPaused()
    If $fPaused Then
        _ShowTip("", 0, 0)
        ToolTip("You can't run script while the program is paused", 0, 0)
        Return True
    EndIf
    Return False
EndFunc   ;==>_CheckIfPaused

Func _ShowTip($sText, $iX, $iY, $iTime = 2000)
    ToolTip($sText, $iX, $iY)
    AdlibRegister("_CloseTips", $iTime)
EndFunc   ;==>_ShowTip

Func _CloseTips()
    AdlibUnRegister("_CloseTips")
    ToolTip("")
EndFunc   ;==>_CloseTips

If you want me to explain any line in the above code, then please do so by commenting.

Edited by DatMCEyeBall

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

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...