Jump to content

Recommended Posts

  • Moderators
Posted

  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.

Posted

  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
Posted

  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

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.

Posted (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 by Richard Robertson
Posted (edited)

Hi,

#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 by smashly
  • 1 month later...
Posted

  smashly said:

Hi,

#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?

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
  • Recently Browsing   0 members

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