Sign in to follow this  
Followers 0
Victorique

Disable button for set time

5 posts in this topic

#1 ·  Posted (edited)

Hello
 
I have a program here, and i just want to disable the button (gray it out) for 5 seconds, but still have the rest of the program functional. i have tried for so long to try and get this to work, but never can find a way. can you possible help me on this?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#region ### START Koda GUI section ### Form=
$Loginform = GUICreate("Login", 285, 170, 846, 274)
$Login = GUICtrlCreateButton("Login", 8, 104, 129, 49); the button i want to Disable
$Cancel = GUICtrlCreateButton("Cancel", 144, 104, 129, 49)
$PasswordInput = GUICtrlCreateInput("Password", 56, 72, 217, 21, $ES_PASSWORD)
$Label1 = GUICtrlCreateLabel("Login form", 104, 8, 73, 23)
GUICtrlSetFont(-1, 12, 400, 0, "Calibri")
$UsernameInput = GUICtrlCreateInput("Username", 56, 40, 217, 21)
GUICtrlCreateLabel("Username:", 0, 40, 55, 17)
GUICtrlCreateLabel("Password:", 0, 72, 53, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Global $logintries = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Cancel
            Exit
        Case $Login
            _Crypt_Startup()
            $passwordKey = (StringTrimLeft(_Crypt_HashData(GUICtrlRead($PasswordInput), $CALG_SHA1), 2))
            $readInputUser = GUICtrlRead($UsernameInput)
            If $passwordKey == "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220" And $readInputUser == "Test" Then; if user is Test and pass is 1234 then allow
                MsgBox(0, "", "correct!")
            Else
                MsgBox(0, "", "Wrong Username/Password")
                $logintries += 1
                If $logintries >= 3 Then ; after 3 incorrect tries, disable button
                    GUISetState(@SW_DISABLE,$Loginform)
                    MsgBox(0, "To many fail login", "You have enterd the password or username more than 3 times, please wait 5 seconds before you can enter it again")
                    WinActivate($Loginform)
                    GUISetState(@SW_ENABLE,$Loginform)
                    GUICtrlSetState($Login,$GUI_DISABLE)
                    sleep(5000)
                    GUICtrlSetState($Login,$GUI_ENABLE)
                EndIf
            EndIf
            _Crypt_Shutdown()
    EndSwitch
WEnd

I have a button $Login, and I wish to disable it after 3 incorrect tries (If $logintries >= 3 Then)
 
at the moment, i have a 5 second sleep, but I don't want the whole program to stop, just that button.
 
any help would be good :)
 
Sorry if this sounds simple and I am jsut being stupid, I just can't figure it out :

Edited by Victorique

Share this post


Link to post
Share on other sites



GUICtrlSetState($Login, $GUI_DISABLE) and then AdlibRegister("", 5000). When you want to start the 5 seconds of disable. Create Func that has GUICtrlSetState($Login, $GUI_ENABLE) then AdlibUnRegister

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

GUICtrlSetState($Login, $GUI_DISABLE) and then AdlibRegister("", 5000). When you want to start the 5 seconds of disable. Create Func that has GUICtrlSetState($Login, $GUI_ENABLE) then AdlibUnRegister

 

Hello, thank you, it did work, I only have one question, as I never used Adlib before.

what does the UnRegister do? why does it need to be?

I have this;

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Cancel
            Exit
        Case $Login
            _Crypt_Startup()
            $passwordKey = (StringTrimLeft(_Crypt_HashData(GUICtrlRead($PasswordInput), $CALG_SHA1), 2))
            $readInputUser = GUICtrlRead($UsernameInput)
            If $passwordKey == "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220" And $readInputUser == "Test" Then
                MsgBox(0, "", "correct!")
            Else
                MsgBox(0, "", "Wrong Username/Password")
                $logintries += 1
                If $logintries >= 3 Then
                    MsgBox(0, "To many fail login", "You have enterd the password or username more than 3 times, please wait 5 seconds before you can enter it again")
                    GUICtrlSetState($Login, $GUI_DISABLE)
                    AdlibRegister("_enableButton", 5000)
                EndIf
            EndIf
            _Crypt_Shutdown()
    EndSwitch
WEnd

Func _enableButton()
    GUICtrlSetState($Login, $GUI_ENABLE)
EndFunc   ;==>_enableButton

and it works fine without the UnRegister :"O

Edited by Victorique

Share this post


Link to post
Share on other sites

Basically, AdlibRegister() registers a function to be called every X miliseconds. You create the button as disabled and then tell the function to enable the button to run once every 5 seconds. After it's first run, the "Run every 5 seconds" command is disabled, so the button is disabled, waits 5 seconds, and re-enabled. Your code works even though the unregister command is not there because every 5 seconds, it's still setting the button to be enabled.

If you were to put code to try to disable the button again, 5 seconds later (or less depending on the period of time that has passed) it would be re-enabled. again because the code is constantly being executed.

1 person likes this

Share this post


Link to post
Share on other sites

Basically, AdlibRegister() registers a function to be called every X miliseconds. You create the button as disabled and then tell the function to enable the button to run once every 5 seconds. After it's first run, the "Run every 5 seconds" command is disabled, so the button is disabled, waits 5 seconds, and re-enabled. Your code works even though the unregister command is not there because every 5 seconds, it's still setting the button to be enabled.

If you were to put code to try to disable the button again, 5 seconds later (or less depending on the period of time that has passed) it would be re-enabled. again because the code is constantly being executed.

Thank you, this makes sense :)

I just added the AdlibUnRegister("_enableButton") inside the function so when it is called, it will unregister it. thank you lots :)


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