Jump to content

Start and Stop(exit) script with GUI, problem.


 Share

Recommended Posts

Hello,

I want to Start script and Exit script with GUI, but when I click Start, button Exit (X) not work.

how can I stop the running script?

I used OnEventmode.

It is sample code:

#include <GUIConstantsEx.au3>
Sleep(1000)

Opt("GUIOnEventMode", 1)

GUICreate("OnEvent test", 230, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitProgram")
$button = GUICtrlCreateButton("Start", 10, 40, 100)
GUICtrlSetOnEvent($button , "button")
GUISetState(@SW_SHOW)


While 1
sleep(40)
WEnd

Func button()
    sleep(20000)
    ;work...
    ;work...
    ;work firefox with FF, autologins, writes, sets other things...
endfunc

Func Exitprogram()
  MsgBox(0, "exit", "exit")
  Exit
EndFunc

thx

Edited by duzers
Link to comment
Share on other sites

duzers, I'm not sure what your attempting, and I'm no pro, but I think this is what your looking for. Try this

#include <GUIConstantsEx.au3>
Sleep(1000)

Opt("GUIOnEventMode", 1)

GUICreate("OnEvent test", 230, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitProgram")
$button = GUICtrlCreateButton("Start", 10, 40, 100)
GUICtrlSetOnEvent($button , "button")
GUISetState(@SW_SHOW)


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

Func button()
    sleep(20000)
    ;work...
    ;work...
    ;work firefox with FF, autologins, writes, sets other things...
endfunc
Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

Sorry, I forgot to take out the on event code stuff, this will work now:

#include <GUIConstantsEx.au3>
Sleep(1000)

GUICreate("OnEvent test", 230, 120)
$button = GUICtrlCreateButton("Start", 10, 40, 100)
GUISetState()


While 1
 $msg = GUIGetMsg()

 Select
    Case $msg = $button
    button()

    Case $msg = $GUI_EVENT_CLOSE
    Exit
 EndSelect
WEnd

Func button()
    sleep(20000)
    ;work...
    ;work...
    ;work firefox with FF, autologins, writes, sets other things...
endfunc
Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

  • Developers

Example that should work:

#include <GUIConstantsEx.au3>

Global $StartPressed = 0
Opt("GUIOnEventMode", 1)

GUICreate("OnEvent test", 230, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitProgram")
$button = GUICtrlCreateButton("Start", 10, 40, 100)
GUICtrlSetOnEvent($button, "ButtonPressed")
GUISetState(@SW_SHOW)
;
While 1
    If $StartPressed Then
        $StartPressed = 0
        Button()
    EndIf
    Sleep(10)
WEnd
;
Func ButtonPressed()
    $StartPressed = 1
EndFunc   ;==>ButtonPressed
;
Func button()
    Sleep(20000)
    ;work...
    ;work...
    ;work firefox with FF, autologins, writes, sets other things...
EndFunc   ;==>button

Func ExitProgram()
    Exit
EndFunc   ;==>ExitProgram
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This is it!. Many thanks.

This should be a standard feature in AutoIt.

It is, you just have to learn how to use it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Developers

Is there a sample way with this example to Pause/Go script with etc. button2 ?

Everything is possible when you set your mind to it.

Just think about how to get this done ... The hotkeys could be an option but also a button as long as you ensure you read the GUI messages.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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