Jump to content

Recommended Posts

Posted

Well, I've always known that with AutoIt, in order to close your .exe while running it, it must not be in a loop.

Is it possible to have it completely terminate even while in a loop by pressing the X on the top right of the program?

Thanks.

Posted (edited)

I've always done this :

- Made a global Var = 0 ; ( $running = 0 )

- Used :

GUIRegisterMsg($WM_COMMAND,'command')

- In the Command Function done something like :

Func command($hwnd,$msg,$wparam,$lparam)

$nNotifyCode = BitShift($wparam, 16)
    $nID = BitAND($wparam, 0x0000FFFF)
    If $nID = $start Then
        If GUICtrlRead($start, 'Start') Then
            $running = 1
        EndIf
    EndIf 
    If $nID = $stop Then
        If GUICtrlRead($stop, 'Stop') Then
            $running = 0
        EndIf
    EndIf
EndFunc
Edited by Gui
  • Moderators
Posted

Gui,

Well, I've always known that with AutoIt, in order to close your .exe while running it, it must not be in a loop

Then you obviously do not know AutoIt very well - the only way AutoIt scripts (compiled or not) keep running on your machine is because they ARE in a loop! :(

Two examples to close the script via the [X]:

- OnEvent mode:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISetState()

; Enter an infinite loop
While 1
    Sleep(10)
WEnd

Func CLOSEClicked()
    Exit
EndFunc

-MessageLoop mode:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

GUISetState()

; Enter an infinite loop
While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

If you remove the loops, the script exits immediately - you need the loops to keep the scripts active. :)

All clear? :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Yeah, I know it quite well. Those methods I know of as well, it's different when you have a loop that's 1000 lines of code and more! Lol, so how do you explain closing while in that eh? You'd have to post

If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
every 5 lines? Lol.

Posted (edited)

Yeah, I know it quite well. Those methods I know of as well, it's different when you have a loop that's 1000 lines of code and more! Lol, so how do you explain closing while in that eh? You'd have to post

If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
every 5 lines? Lol.

Or everytime you enter a loop that might take a while to complete.

Btw:

Yeah, I know it quite well.

Based on your suggestion, you don't. Or better: you don't seem to understand any basic programming techniques. Edited by Kip
Posted

I already use Register Message. OnEvent mode can't work with buttons & $GUI_EVENT_CLOSE, it's odd. I don't like the way it works. I like GUIGetMsg() much better.

Posted

Or everytime you enter a loop that might take a while to complete.

Btw:

Based on your suggestion, you don't. Or better: you don't seem to understand any basic programming techniques.

Perhaps I know these techniques, I'm trying to find more efficient ones. Try not to assume.
  • Moderators
Posted

Gui

Those methods I know of as well, it's different when you have a loop that's 1000 lines of code and more!

That is "in a function" (or should be!), not "in a loop". :)

Lol, so how do you explain closing while in that eh?

Not quite the tone I would adopt if I wanted an answer :idea: , but................

If you use OnEvent mode, you can break into the running function:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState()

_Long_Function()

; Enter an infinite loop
While 1
    Sleep(10)
WEnd

Func _Long_Function()
    $iBegin = TimerInit()
    While TimerDiff($iBegin) < 10000
        ConsoleWrite(@SEC & @CRLF)
        Sleep(1000)
    WEnd
EndFunc

Func CLOSEClicked()
    Exit
EndFunc

If you use MessageLoop mode, you have a big problem. AutoIt will NOT interrupt a running function unless you use a HotKey. So if you have long function without a periodic check of some kind, you cannot break out. The best you can do is run a HotKey and set a flag which you check now and again. :(

M23

P.S. I agree with Kip - and I am not assuming, you are telling us. :)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

Gui,

My pleasure. :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Perhaps I know these techniques, I'm trying to find more efficient ones. Try not to assume.

If you already know those techniques, then why in gods name are you providing us such a "dumb" example?

And why do you literally ask:

it's different when you have a loop that's 1000 lines of code and more! Lol, so how do you explain closing while in that eh?

if you already know the answer?
Posted

No, I saw it. I just don't feel like arguing. It's hard to understand what I mean through the internet.

Simple, I mean it thanks for all your help. You wasted your time over my thread, so 'Thanks'.

Also, sorry. -Kip.

-Gui.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...