AutoItGal Posted October 12, 2007 Posted October 12, 2007 How to detect and disable a button if a user clicks it two or more times? I want to prevent multiple instances. Please help. Thank you.
Moderators SmOke_N Posted October 12, 2007 Moderators Posted October 12, 2007 AutoItGal said: How to detect and disable a button if a user clicks it two or more times?I want to prevent multiple instances. Please help.Thank you.Some code would be nice.. or are we to make the example for you? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
AutoItGal Posted October 12, 2007 Author Posted October 12, 2007 SmOke_N said: Some code would be nice.. or are we to make the example for you?A short example will be good. Thanks.I just want to prevent the user from clicking a button and executing it for multiple times at the same time.
Moderators SmOke_N Posted October 12, 2007 Moderators Posted October 12, 2007 AutoItGal said: A short example will be good. Thanks. I just want to prevent the user from clicking a button and executing it for multiple times at the same time.I'm not going to write the example out... you should have made a gui and had us show you from there. 1. make a global variable something like $nClickButtonCount = 0 2. make your gui 3. in your condition statement for the button, make another conditional statement If $nClickButtonCount = 0 Then ;Do your action $nClickButtonCount = 1 Else MsgBox(16, "Error", "I told you moron, only once!") ;Or you could do something and then say $nClickButtonCount = 0 EndIf jmosley708 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Richard Robertson Posted October 12, 2007 Posted October 12, 2007 (edited) In your code for when they click it, add a GUICtrlSetState($control, $GUI_DISABLE) at the top, and when you finish, add a GUICtrlSetState($control, $GUI_ENABLE). Of course, $control is the id of your button. Edit: Smoke posted before I finished reading. Edited October 12, 2007 by Richard Robertson KEHT 1
smashly Posted October 12, 2007 Posted October 12, 2007 (edited) Hi, expandcollapse popup#include <GUIConstants.au3> Opt("RunErrorsFatal", 0) Global $pID, $State $Gui = GUICreate("Disable Button", 290, 265, -1, -1, -1, $WS_EX_TOPMOST) $RunButton = GUICtrlCreateButton("Run Notepad", 10, 10, 80, 30) $KillButton = GUICtrlCreateButton("Kill Notepad", 100, 10, 80, 30) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $Gui) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE If ProcessExists($pID) Then ProcessClose($pID) Exit Case $msg = $RunButton $pID = Run(@SystemDir & "\notepad.exe") If Not @error Then GUICtrlSetState($RunButton, $GUI_DISABLE) GUICtrlSetState($KillButton, $GUI_ENABLE) $State = 1 EndIf Case $msg = $KillButton ProcessClose($pID) GUICtrlSetState($RunButton, $GUI_ENABLE) GUICtrlSetState($KillButton, $GUI_DISABLE) $State = 0 EndSelect If Not ProcessExists($pID) And $State = 1 Then GUICtrlSetState($RunButton, $GUI_ENABLE) GUICtrlSetState($KillButton, $GUI_DISABLE) $State = 0 EndIf WEnd Cheers Edited October 12, 2007 by smashly
RZLucian0127 Posted November 19, 2007 Posted November 19, 2007 smashly said: Hi, expandcollapse popup#include <GUIConstants.au3> Opt("RunErrorsFatal", 0) Global $pID, $State $Gui = GUICreate("Disable Button", 290, 265, -1, -1, -1, $WS_EX_TOPMOST) $RunButton = GUICtrlCreateButton("Run Notepad", 10, 10, 80, 30) $KillButton = GUICtrlCreateButton("Kill Notepad", 100, 10, 80, 30) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $Gui) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE If ProcessExists($pID) Then ProcessClose($pID) Exit Case $msg = $RunButton $pID = Run(@SystemDir & "\notepad.exe") If Not @error Then GUICtrlSetState($RunButton, $GUI_DISABLE) GUICtrlSetState($KillButton, $GUI_ENABLE) $State = 1 EndIf Case $msg = $KillButton ProcessClose($pID) GUICtrlSetState($RunButton, $GUI_ENABLE) GUICtrlSetState($KillButton, $GUI_DISABLE) $State = 0 EndSelect If Not ProcessExists($pID) And $State = 1 Then GUICtrlSetState($RunButton, $GUI_ENABLE) GUICtrlSetState($KillButton, $GUI_DISABLE) $State = 0 EndIf WEnd Cheers wow nice bro, but this is my question.. how can this script detect that the notepad.exe i running? and when it detected the running notepad, the button is disabled even they open another process the same with this application?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now