Jump to content

Buttons dont work :S


Recommended Posts

This is my first GUI work. If i press close first program closes. But if i press Start program doesnt work. After pressing Start, close button doesnt work too. Here is my code:

#include <GUIConstants.au3>
Global $Pause
Global $ClientName
Global $Time
Global $Start
Global $Stop
Global $msg
GUICreate("Auto Login",180,100)
GUICtrlCreateLabel("Client Name",5, 0)
$ClientName = GUICtrlCreateInput("SRO_Client",5,15,100,20)
GUICtrlCreateLabel("Time",130,0)
$Time= GuiCtrlCreateInput("5",130,15,30,20)
$Start=GUICtrlCreateButton("Start", 5, 50,80,30)
$Stop=GUICtrlCreateButton("Stop", 95, 50,80,30)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
        EndIf
    If $msg = $Start Then
        Start()
        EndIf
    If $msg = $Stop Then
        Stop()
        EndIf
Wend
Func Stop()
$Pause = NOT $Pause
While $Pause
sleep(50)
WEnd
EndFunc
Func Start()
While 1
    If Not WinActive($ClientName,"") Then
        WinActivate($ClientName,"")
        EndIf
Send("{ENTER}")
Sleep($Time*1000)
Wend
EndFunc
Link to comment
Share on other sites

ok I understand the problem, this:

If Not WinActive($ClientName,"") Then
        WinActivate($ClientName,"")
        EndIf

should be:

If Not WinActive(GuiCtrlRead($ClientName),"") Then
        WinActivate(GuiCtrlRead($ClientName),"")
        EndIf
Link to comment
Share on other sites

ok I understand the problem, this:

If Not WinActive($ClientName,"") Then
        WinActivate($ClientName,"")
        EndIf

should be:

If Not WinActive(GuiCtrlRead($ClientName),"") Then
        WinActivate(GuiCtrlRead($ClientName),"")
        EndIf
Thxxxx it works now :D

Can u tell me the difference? Im really new at autoit scripting :D

Link to comment
Share on other sites

look at this:

$ClientName = GUICtrlCreateInput("SRO_Client",5,15,100,20)

$ClientName holds the ID of the control not the text "SRO_Client" or whatever is typed in, to get the text of the control you have to use GuiCtrlRead in order to do the check for the existence of the window. I hope I was clear... you should look also in the help file for more informations :D

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