Jump to content

Recommended Posts

Posted (edited)

I need some help with this button. As you can see if you press the button once the label change to "Stop" but if you press it again nothing happen, or well it does, it change the label to "Stop" again but you won't notice anything. I want it to change back to "Start".

#include <GUIConstants.au3>

$Form1 = GUICreate("Status", 250, 150, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUICtrlCreateLabel ("STATUS: ", 50, 50)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$status= GUICtrlCreateLabel("OFF", 62, 80, 100)
GUICtrlSetColor(-1,0xff0000)    ; Red
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$button = GUICtrlCreateButton ("START", 165, 25, 75, 100, 0)

GUISetState(@SW_SHOW)

While 1 
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit 

Case $button 
start()
EndSwitch
WEnd

Func start()
while 1

GUICtrlSetData ($button, "STOP")
GUICtrlSetData ($status, "ON")
GUICtrlSetFont($status, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor ($status, 0x00A400)     ;Green

Sleep(500)

WEnd
EndFunc
Edited by Pain
Posted

Is this what your after?

#include <GUIConstants.au3>

$Form1 = GUICreate("Status", 250, 150, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUICtrlCreateLabel ("STATUS: ", 50, 50)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$status= GUICtrlCreateLabel("OFF", 62, 80, 100)
GUICtrlSetColor(-1,0xff0000)   ; Red
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")


Global $buttonText = "START"
$button = GUICtrlCreateButton ($buttonText, 165, 25, 75, 100, 0)

GUISetState(@SW_SHOW)

While 1 
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit 

Case $button 
start()
EndSwitch
WEnd

Func start()

    If $buttonText = "START" then 
        $buttonText = "STOP"
        GUICtrlSetData ($button, $buttonText)
        GUICtrlSetData ($status, "ON")
        GUICtrlSetFont($status, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor ($status, 0x00A400) ;Green
    Else
        $buttonText = "START"
        GUICtrlSetData ($button, $buttonText)
        GUICtrlSetData ($status, "OFF")
        GUICtrlSetFont($status, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor ($status, 0xff0000) ;Red
    EndIf


EndFunc
Posted (edited)

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

$Form1 = GUICreate("Status", 250, 150, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUICtrlCreateLabel("STATUS: ", 50, 50)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$status = GUICtrlCreateLabel("OFF", 62, 80, 100)
GUICtrlSetColor(-1, 0xff0000) ; Red
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$button = GUICtrlCreateButton("START", 165, 25, 75, 100, 0)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $button
            start()
    EndSwitch
WEnd

Func start()
    ;While 1
    If GUICtrlRead($button) = "START" Then
        GUICtrlSetData($button, "STOP")
        GUICtrlSetData($status, "ON")
        GUICtrlSetColor($status, 0x00A400) ;Green
    Else
        GUICtrlSetData($button, "START")
        GUICtrlSetData($status, "OFF")
        GUICtrlSetColor(-1, 0xff0000) ; Red
    EndIf
    Return
    ;Sleep(500)

    ;WEnd
EndFunc   ;==>start

...........Way too slow!!!... :)

8)

Edited by Valuater

NEWHeader1.png

Posted

Valuater try click on the button 2 or 3 times and you will see that the button will become weird, just like it's always pressed...

Posted

Valuater try click on the button 2 or 3 times and you will see that the button will become weird, just like it's always pressed...

Sorry, I missed that one..

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

$Form1 = GUICreate("Status", 250, 150, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUICtrlCreateLabel("STATUS: ", 50, 50)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$status = GUICtrlCreateLabel("OFF", 62, 80, 100)
GUICtrlSetColor(-1, 0xff0000) ; Red
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$button = GUICtrlCreateButton("START", 165, 25, 75, 100, 0)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $button
            start()
    EndSwitch
WEnd

Func start()
    ;While 1
    If GUICtrlRead($button) = "START" Then
        GUICtrlSetData($button, "STOP")
        GUICtrlSetData($status, "ON")
        GUICtrlSetColor($status, 0x00A400) ;Green
    Else
        GUICtrlSetData($button, "START")
        GUICtrlSetData($status, "OFF")
        GUICtrlSetColor($status, 0xff0000) ; Red
    EndIf
    Return
    ;Sleep(500)

    ;WEnd
EndFunc   ;==>start

8)

NEWHeader1.png

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
×
×
  • Create New...