Sign in to follow this  
Followers 0
EmptySpace

How to make interrupt funcion more simply?

5 posts in this topic

#1 ·  Posted (edited)

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


Global $fInterrupt = 0


#Region ### START Koda GUI section ### Form=
$Interrupt = GUICreate("Interrupt", 316, 86, 192, 124)
$Stop = GUICtrlCreateButton("Stop", 9, 8, 63, 49)
$st = GUICtrlCreateLabel("", 84, 24, 180, 28)
$start = GUICtrlCreateButton("start", 8, 56, 67, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")



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


Func start()
GUICtrlSetData($st,"Sleeping...Zzz...")

While 1
Sleep(500)


;============================================
If $fInterrupt Then
Switch $fInterrupt
Case 1
GUICtrlSetData($st,"Stop button pressed..Stoping..")
$fInterrupt = 0
GUICtrlSetData($st,"Not working")
exitloop
Case 2
GUICtrlSetData($st,"Exiting directly...")
Exit
EndSwitch
Endif
;============================================


Wend
endfunc

;=====================================================================================================================================================================
; STOP FUNCTIONS
;=====================================================================================================================================================================
Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
; Stop was pressed so set the flag (GUI)
If BitAND($wParam, 0x0000FFFF) = $stop Then $fInterrupt = 1
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_COMMAND FOR BUTTON

Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)
; Closure [X} pressed
If BitAND($wParam, 0xFFF0) = 0xF060 Then ; $SC_CLOSE
$fInterrupt = 2
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>On_WM_SYSCOMMAND

In most of codes I use like this:

DO SOMETHING
;============================================
If $fInterrupt Then
         Switch $fInterrupt
             Case 1
                                 GUICtrlSetData($st,"Stop button pressed..Stoping..")
                 $fInterrupt = 0
                 GUICtrlSetData($st,"Not working")
                 exitloop
             Case 2
                 GUICtrlSetData($st,"Exiting directly...")
                 Exit
         EndSwitch
Endif
;============================================



DO SOMETHING

;============================================
If $fInterrupt Then
         Switch $fInterrupt
             Case 1
                                 GUICtrlSetData($st,"Stop button pressed..Stoping..")
                 $fInterrupt = 0
                 GUICtrlSetData($st,"Not working")
                 exitloop
             Case 2
                 GUICtrlSetData($st,"Exiting directly...")
                 Exit
         EndSwitch
Endif
;============================================

DO SOMETHING

So its looks very bad..

Putting it in func would be better but it wont work becouse exitloop works only in loop.

;Do something
interrupt()
;Do something
interrupt()
;Do something

It would be better..

Any ideas?

Edited by EdgarT

Share this post


Link to post
Share on other sites



Not sure of your question, but if you are in a Function, then you want to use Return to exit the function instead of exitloop. It will stop the execution of the remaining function. You can also return values e.g. Return $variable. Hope that helps.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

EdgarT,

Does this do what you want? :)

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

Global $fInterrupt = 0

$Interrupt = GUICreate("Interrupt", 316, 86, 192, 124)
$Stop = GUICtrlCreateButton("Stop", 9, 8, 63, 49)
$st = GUICtrlCreateLabel("", 84, 24, 180, 28)
$start = GUICtrlCreateButton("start", 8, 56, 67, 25)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

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

Func start()
    GUICtrlSetData($st, "Sleeping...Zzz...")

    While 1
        ; Do something
        GUICtrlSetData($st, "Doing something!")
        Sleep(1000)
        GUICtrlSetData($st, "Checking for interrupt" & @CRLF)
        Sleep(100)
        If _Interrupt() Then ExitLoop
        GUICtrlSetData($st, "Doing something!")
        Sleep(1000)
        GUICtrlSetData($st, "Checking for interrupt" & @CRLF)
        Sleep(100)
        If _Interrupt() Then ExitLoop
        Sleep(1000)
        GUICtrlSetData($st, "Doing something!")
        Sleep(1000)
        GUICtrlSetData($st, "Checking for interrupt" & @CRLF)
        Sleep(100)
        If _Interrupt() Then ExitLoop
    WEnd
EndFunc   ;==>start

;=====================================================================================================================================================================
; STOP FUNCTIONS
;=====================================================================================================================================================================
Func _Interrupt()
    If $fInterrupt Then
        Switch $fInterrupt
            Case 1
                GUICtrlSetData($st, "Stop button pressed..Stoping..")
                $fInterrupt = 0
                GUICtrlSetData($st, "Not working")
                Return True
            Case 2
                GUICtrlSetData($st, "Exiting directly...")
                Exit
        EndSwitch
    EndIf
    Return False
EndFunc   ;==>_Interrupt


Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    ; Stop was pressed so set the flag (GUI)
    If BitAND($wParam, 0x0000FFFF) = $Stop Then $fInterrupt = 1
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    ; Closure [X} pressed
    If BitAND($wParam, 0xFFF0) = 0xF060 Then ; $SC_CLOSE
        $fInterrupt = 2
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_SYSCOMMAND

Please ask if you have any questions - or I have misunderstood. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Ahh.. It was so easy.. Thank you melba!

Share this post


Link to post
Share on other sites

EdgarT,

Glad to see my crystal ball is still working as designed! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  
Followers 0