Jump to content
Sign in to follow this  
fikri1979

how to change the start button to stop

Recommended Posts

fikri1979

hello....i'm beginner

I love to learn to use autoit

simply,how to make script?

when push the start button automatically run notepad then the start button turns into a stop button,

and when the start button changed to stop then i push the button automatically close notepad

post-81604-0-89051300-1377388965_thumb.j change to post-81604-0-97621300-1377389169_thumb.j

 

my script

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("LATIHAN BUTTON", 273, 124, 192, 144)
$START = GUICtrlCreateButton("STOP", 80, 40, 89, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
    If $msg=$START Then START()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func START()
    Run("notepad.exe")
EndFunc

Func STOP()
    WinClose("Untitled - Notepad")
EndFunc
Edited by fikri1979

Share this post


Link to post
Share on other sites
JohnOne

here is one example

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

Local $btext[2] = ['Start', 'Stop']
Local $btnflag = 0
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("LATIHAN BUTTON", 273, 124, 192, 144)
$START = GUICtrlCreateButton($btext[0], 80, 40, 89, 33)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
    If $Msg = $START Then
        START()
    EndIf
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func START()
    $btnflag = Not $btnflag
    GUICtrlSetData($START, $btext[$btnflag])
EndFunc   ;==>START

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
fikri1979

Spend more time on the helpfile, you won't ask crap questions on the forum.

sorry for my weakness and language errors, because I am not fluent english

Thank you for your attention

Edited by fikri1979

Share this post


Link to post
Share on other sites
fikri1979

 

here is one example

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

Local $btext[2] = ['Start', 'Stop']
Local $btnflag = 0
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("LATIHAN BUTTON", 273, 124, 192, 144)
$START = GUICtrlCreateButton($btext[0], 80, 40, 89, 33)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
    If $Msg = $START Then
        START()
    EndIf
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func START()
    $btnflag = Not $btnflag
    GUICtrlSetData($START, $btext[$btnflag])
EndFunc   ;==>START

Thank you very much...

Share this post


Link to post
Share on other sites
fikri1979

Thank you very much...

once again..

when it was changed to stop button, how to close the program using the change button?

Func START()
    $btnflag = Not $btnflag
    GUICtrlSetData($START, $btext[$btnflag])
    Run("notepad.exe")
EndFunc   ;==>START

Func STOP()
    WinClose("[CLASS:Notepad]", "")
EndFunc   ;==>STOP

Share this post


Link to post
Share on other sites
JohnOne

Here is one way.

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

Local $btext[2] = ['Start', 'Stop']
Local $btnflag = 0
Local $pid
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("LATIHAN BUTTON", 273, 124, 192, 144)
$START = GUICtrlCreateButton($btext[0], 80, 40, 89, 33)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
    If $Msg = $START Then
        START()
    EndIf
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func START()
    $btnflag = Not $btnflag
    If Not $btnflag Then
        ProcessClose($pid)
    Else
        $pid = Run("notepad.exe")
    EndIf
    GUICtrlSetData($START, $btext[$btnflag])
EndFunc   ;==>START
  • Like 2

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
FireFox

@fikri1979
I would like to apologize for the tone of my first reply, I was a in bad mood.

I didn't mean to attack you of course; see ya on the forum :)

Br, FireFox.

Edited by FireFox
  • Like 1

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  

×