Jump to content
Sign in to follow this  
duzers

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

Recommended Posts

duzers

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

Share this post


Link to post
Share on other sites
Realm

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.  

Share this post


Link to post
Share on other sites
duzers

No, It's not this. I want exit even if sleep(20000) work.

Share this post


Link to post
Share on other sites
Realm

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.  

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
duzers

This is it!. Many thanks.

This should be a standard feature in AutoIt.

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
duzers

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

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  

×