Jump to content
Sign in to follow this  
DrGamut

Toggling a function from a GUI button.

Recommended Posts

I can't figure out how to toggle from a function loop to the main loop using a GUI button. I've created a function that begins by using the NOT operator on a variable, and continuing into a while loop which evaluates that variable. Now, if I call the function with a GUI button once, it goes into the function loop as expected. But, if I press the button again, nothing happens, I can't escape the function loop. However, if I use a hotkey as opposed to a GUI button, it exits the loop just fine. What gives? I've tried both GUIGetMessage and the OnEvent methods.

Can anyone give me an example script with a GUI button that calls a function loop, and when pressed again escapes the function loop? Thanks!

Share this post


Link to post
Share on other sites

I can't figure out how to toggle from a function loop to the main loop using a GUI button. I've created a function that begins by using the NOT operator on a variable, and continuing into a while loop which evaluates that variable. Now, if I call the function with a GUI button once, it goes into the function loop as expected. But, if I press the button again, nothing happens, I can't escape the function loop. However, if I use a hotkey as opposed to a GUI button, it exits the loop just fine. What gives? I've tried both GUIGetMessage and the OnEvent methods.

Can anyone give me an example script with a GUI button that calls a function loop, and when pressed again escapes the function loop? Thanks!

<{POST_SNAPBACK}>

Take a Look at this;
#include <GUIConstants.au3>

GUICreate("Custom Msgbox", 210, 80)

$Label = GUICtrlCreateLabel("Please click a button!", 10, 10)
$YesID  = GUICtrlCreateButton("Yes", 10, 50, 50, 20)
$NoID   = GUICtrlCreateButton("No", 80, 50, 50, 20)
$ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20)

GUISetState(); display the GUI

Do
    $msg = GUIGetMsg()
   
    Select
        Case $msg= $YesID
            MsgBox(0,"You clicked on", "Yes")
        Case $msg= $NoID
            MsgBox(0,"You clicked on", "No")
        Case $msg= $ExitID
            MsgBox(0,"You clicked on", "Exit")
        Case $msg= $GUI_EVENT_CLOSE
            MsgBox(0,"You clicked on", "Close")
    EndSelect
Until $msg = $GUI_EVENT_CLOSE or $msg = $ExitID

Its from the exsamples file that came with autoit 3

Here is a script that has alot of notes to learn from

; AutoIt Version: 3.0
; Language: English
; Platform: Win98 2nd edition, Win XP and May work on other windows
; In order to work under Windows NT 4.0, requires the file
; PSAPI.DLL (included in the AutoIt installation directory).
; Author: Quick_sliver007
; Script Name: Process Blocker
; version: 1.3
; Script Function: To Block unwanted processes like spyware and adware
; fixed : Made block process list view clear before loading file,
; resized gui, cleaned up script with functions, added fade function,
; added shortcut keys and added annotation
#include <GuiConstants.au3>
#include <Array.au3>
#include <file.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; START OF GUI CREATION
$GUI = GUICreate("Process Blocker", 565, 419, (@DesktopWidth - 565) / 2, (@DesktopHeight - 409) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Process_List_View = GUICtrlCreateListView("Processes", 1, 30, 220, 370)
$Block_List_view = GUICtrlCreateListView("Block", 344, 30, 220, 370)
$Label_Process = GUICtrlCreateLabel("Process List", 10, 10, 220, 20)
$Label_Block = GUICtrlCreateLabel("Block List", 340, 10, 220, 20)
$Label_Add = GUICtrlCreateLabel("Add To Block List", 240, 30, 90, 20)
$Button_Add = GUICtrlCreateButton("&Add", 240, 50, 90, 30)
$Button_Delete = GUICtrlCreateButton("&Delete", 240, 130, 90, 30)
$Label_Delete = GUICtrlCreateLabel("Delete From List", 240, 110, 90, 20)
$Button_Reset = GUICtrlCreateButton("&Reset", 240, 270, 90, 50)
$Button_Block = GUICtrlCreateButton("&Block", 240, 190, 90, 50)
$Button_Exit = GUICtrlCreateButton("&Exit", 240, 350, 90, 50)
$Menu = GUICtrlCreateMenu("&File")
$Save = GUICtrlCreateMenuItem("&Save", $Menu)
$Load = GUICtrlCreateMenuItem("&Load", $Menu)
$Button_Donate = GUICtrlCreateButton("&Donate", 240, 10, 90, 20)
GUISetState(); END OF GUI CREATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; IN THE HELP FILE IT SENDS ProcessList() TO A MESSAGE BOX.....
; I HAD THE IDEAL TO SEND IT TO A LIST VIEW
Func _processlist()
    Dim $LVM_DELETEITEM = 0x1008
    $Process = ProcessList()
    For $i = 1 To $Process[0][0]
        $items = GUICtrlCreateListViewItem($Process[$i][0], $Process_List_View)
    Next
EndFunc  ;==>_processlist
_processlist()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Global $break = 0
; USE THIS FUNCTION TO EXIT THE RUN LOOP
; THANKS GOES TO erifash
Func _break()
    $break = 1
EndFunc  ;==>_break
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; USE THIS FUNCTION TO OPEN AN URL ON THE DEFAULT BROWSER
; THANKS TO Ejoc AND SlimShady FOR THIS FUNCTIONS
Func _GoToWebPage($URL)
    Run(@comspec & ' /c START "" "' & $URL & '"', @SystemDir, @SW_HIDE)
EndFunc  ;==>_GoToWebPage
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;THANKS TO bshoenhair FOR POINTING TO "http://www.autoitscript.com/forum/index.php?showtopic=7026&hl="
;USE THIS FUNCTION TO MOVE SELECTED ITEM BETWEEN LIST VIEWS
Func _Move_Selected_Item_To_Another_List_View($Source_List_View, $destination_List_view)
    Dim $LVM_DELETEITEM, $a, $ItemCount, $Source_Title
;COPY SELCTED ITEM FROM SOURCE LIST VIEW AND PASTE IT TO THE DESTINATION LIST VIEW
    GUICtrlCreateListViewItem(GUICtrlRead(GUICtrlRead($Source_List_View)), $destination_List_view)
; THIS NUMBER IS USED TO DELETE AN ITEM FROM A LIST VIEW, SOME TYPE OF...
; MICROSOFT STANDARD CONTROL NUMBER, I JUST KNOW IT WORKS
    $LVM_DELETEITEM = 0x1008
    $ItemCount = ControlListView("", "", $Source_List_View, "GetItemCount")
    For $a = 0 To $ItemCount - 1
        If ControlListView("", "", $Source_List_View, "IsSelected", $a) Then
        ;DELETES THE SELECTED ITEM FROM THE SOURCE LIST VIEW
            GUICtrlSendMsg($Source_List_View, $LVM_DELETEITEM, $a, 0)
        EndIf
    Next
EndFunc  ;==>_Move_Selected_Item_To_Another_List_View
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; USE THIS FUNCTION TO CLEAR ALL ITEMS IN A LIST VIEW
Func _clearlistview($List_View)
    #cs
    Do
        Dim $LVM_DELETEITEM, $a, $ItemCount
        $LVM_DELETEITEM = 0x1008
        $ItemCount = ControlListView("", "", $List_View, "GetItemCount")
        For $a = 0 To $ItemCount - 1
            GUICtrlSendMsg($List_View, $LVM_DELETEITEM, $a, 0)
        Next
;DO UNTIL ALL ITEMS ARE CLEARED 
    Until $ItemCount = 0
    #ce
; I FOUND A BETTER WAY, THANKS TO Gary Frost AUTHOR OF CFCCodeWizard
; AS YOU CAN SEE THERE IS MORE THEN ONE WAY AND HIS WAY IS THE CORRECT.
    Local $LVM_DELETEALLITEMS = 0x1009
   GUICtrlSendMsg($LIST_VIEW, $LVM_DELETEALLITEMS, 0, 0)
EndFunc  ;==>_clearlistview
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; THANKS TO Lazycat FOR THE Fade FUNCTION
; AUTHOR OF Quick Notepad v0.5
; CAUSES THE GUI TO FADE IN OR OUT
; I BELIEVE $nStart AND $nEnd ARE BACKARDS
; $nEnd = HOW TRANSPARENT THE WINDOW STARTS, RANGE 0 - 255
; $nStart = HOW TRANSPARENT THE WINDOW ENDS, RANGE 0 - 255
; $hWnd IS THE WINDOW NAME
; $nStep IS HOW FAST
Func Fade($hWnd, $nStart, $nEnd, $nStep)
    If not $nStep Then Return
    For $t = $nStart to $nEnd step $nStep * ($nEnd - $nStart)/Abs($nEnd - $nStart)
        WinSetTrans ($hWnd, "", $t)
    Next
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While 1
    Dim $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_Add
        ; ADD ITEM FROM $Process_List_View TO $Block_List_view
            _Move_Selected_Item_To_Another_List_View($Process_List_View, $Block_List_view)
        Case $msg = $Button_Delete
        ; MOVE ITEM BACK TO $Process_List_View
            _Move_Selected_Item_To_Another_List_View($Block_List_view, $Process_List_View)
        Case $msg = $Button_Block
        ; THIS WHOLE AREA IS THE CORE OF THE SCRIPT
        ; THIS AREA IS WHERE PROCESSES ARE BLOCKED
            Fade($gui, 100, 0, 10)
            GUISetState(@SW_HIDE, $GUI)
            HotKeySet("{ESC}", "_break")
            While 1
                Dim $count_items, $Get_text, $b
            ;COUNT ITEMS IN THE $Block_List_view
                $count_items = ControlListView("Process Blocker", "", $Block_List_view, "GetItemCount")
                For $b = 0 To $count_items - 1
                ; GET ALL OF THE ITEMS IN THE $Block_List_view
                    $Get_text = ControlListView("Process Blocker", "", $Block_List_view, "GetText", $b)
                ; CLOSE ALL OF THE ITEMS IN THE $Block_List_view UNTIL THE LOOP IS BROKEN
                    ProcessClose($Get_text)
                Next
            ; USED TO BREAK THE LOOP
                If $break = 1 Then
                    HotKeySet("{ESC}")
                    $break = 0
                    GUISetState(@SW_SHOW, $GUI)
                    Fade($gui, 0,250, 3)
                    ExitLoop
                EndIf
            WEnd
        Case $msg = $Button_Reset
        ; RESET ALL OF THE LIST VIEWS AND ENABLE THE BUTTONS IF THE....
        ; BUTTONS WERE DISABLED FROM LOADING THE SAVE FILE
            _clearlistview($Process_List_View)
            _clearlistview($Block_List_view)
            _processlist()
            GUICtrlSetState($Button_Add, $GUI_ENABLE)
            GUICtrlSetState($Button_Delete, $GUI_ENABLE)
        Case $msg = $Save
            Dim $count_items, $b
            If FileExists("BlockProcessesSave.txt") Then
            ;DELETE THE OLD FILE BEFORE WRITING A NEW ONE SO THAT THE LAST SAVE IS REPLACED
                FileDelete("BlockProcessesSave.txt")
                $count_items = ControlListView("Process Blocker", "", $Block_List_view, "GetItemCount")
                For $b = 0 To $count_items - 1
                    Dim $Get_text[$count_items]
                    $file = FileOpen("BlockProcessesSave.txt", 1)
                ;SET ALL ITEMS IN THE $Block_List_view TO AN ARRAY
                    $Get_text[$b] = ControlListView("Process Blocker", "", $Block_List_view, "GetText", $b)
                    Do
                    ; GIVE TIME FOR THE FILE TO BE OPENED/CREATED BEFORE WRITING FILE
                        Sleep(1000)
                    Until FileExists("BlockProcessesSave.txt")
                ;WRITE ALL ITEMS IN THE ARRAY TO THE FILE
                    FileWrite($file, $Get_text[$b] & @CRLF)
                    FileClose($file)
                Next
            ElseIf Not FileExists("BlockProcessesSave.txt") Then
                $count_items = ControlListView("Process Blocker", "", $Block_List_view, "GetItemCount")
                For $b = 0 To $count_items - 1
                    Dim $Get_text[$count_items]
                    $file = FileOpen("BlockProcessesSave.txt", 1)
                    $Get_text[$b] = ControlListView("Process Blocker", "", $Block_List_view, "GetText", $b)
                    Do
                        Sleep(1000)
                    Until FileExists("BlockProcessesSave.txt")
                    FileWrite($file, $Get_text[$b] & @CRLF)
                    FileClose($file)
                Next
            EndIf
        Case $msg = $Load
        ; CLEAR ALL ITEMS BEFORE LOADING
            _clearlistview($Block_List_view)
            _clearlistview($Process_List_View)
            Dim $aRecords
            If Not _FileReadToArray("BlockProcessesSave.txt", $aRecords) Then
                MsgBox(4096, "Error", "Make Sure You Have A Saved List")
                Exit
            EndIf
            For $x = 1 To $aRecords[0]
            ; $aRecords[$x] IS AN ARRAY THAT CONTAINS THE ITEMS FROM THE SAVE FILE
            ; SET THE $Block_List_view ITEMS TO THE ITEMS STORED IN THE ARRAY
            ; THE STRING TRIM IS TO CUT OUT THE LAST CHARACTER ,A SQUARE SHAPED CHARACTER
            ; I BELIEVE THE SQUARE IS FROM LINE BREAKS I USED IN WRITING THE SAVE FILE
                GUICtrlCreateListViewItem(StringTrimRight($aRecords[$x], 1), $Block_List_view)
            Next
        ; DISABLE BUTTONS TO AVOID ERRORS
            GUICtrlSetState($Button_Add, $GUI_DISABLE)
            GUICtrlSetState($Button_Delete, $GUI_DISABLE)
            GUICtrlCreateListViewItem("Click reset to reload list.", $Process_List_View)
        Case $msg = $Button_Donate
        ; EVERY DOLLAR COUNTS AND
        ; EVERY PENNY COUNTS TOO, LOL
            _GoToWebPage("https://www.paypal.com/xclick/business=quick_sliver007%40yahoo%2ecom&no_shipping=0&no_note=1&tax=0&currency_code=USD")
        Case $msg = $Button_Exit
            Exit
    EndSelect
WEnd
#cs
    I HOPE I DIDN'T GO OVER KILL WITH THE ANNOTATION. I ALL WAYS WANTED WELL ANNOTATED SCRIPTS
    TO LEARN FROM WHEN I HAD JUST STARTED TO LEARN AUTOLT 3. THE ONES I DID FIND WERE FAR AND FEW BETWEEN.
    SO I JUST WANTED TO ADD ONE TO THE PILE OF WELL ANNOTATED SCRIPTS FOR PEOPLE TO LEARN FROM. I KNOW
    I STILL HAVE A LOT MORE TO LEARN IN AUTOLT 3 BUT I WOULD LIKE TO HELP GIVE PEOPLE THAT ARE NEW
    SOMETHING MORE TO LEARN FROM. FOR NOW AM DONE WITH THIS SCRIPT. IF YOU FIND A BUG, FEEL FREE TO
    LET ME KNOW. I GIVE MANY THANKS TO ALL OF THE PEOPLE ON THE AUTOLT FORUM THAT HAVE HELPED ME LEARN
    THIS LANGUAGE.
    P.S.
    FEEL FREE TO DONATE.
#CE

I hope this helps.

Edited by quick_sliver007

.

Share this post


Link to post
Share on other sites

Okay...but it doesn't contain any functions with loops in them external to the body of the script. So I don't see how it bears relevance on my issue. :)

Share this post


Link to post
Share on other sites

Okay...but it doesn't contain any functions with loops in them external to the body of the script. So I don't see how it bears relevance on my issue. :)

<{POST_SNAPBACK}>

I am sorry, I miss Read. Look at my last reply again, I added to it.

.

Share this post


Link to post
Share on other sites

Hmm, you used a "_break" function to escape the loop, and assigned it to a hotkey. I havn't had any issues getting hotkeys to trigger the function (multiple times), but the GUI buttons won't. So, is it possible to retrigger the same function while it's already running with a GUI button, or do I have no choice but to use a second function? I don't understand why my hotkey can recall the function that's being processed and force it to toggle, but the GUI button cannot. Is the fact that my function is looping preventing the program from receiving my button press? I thought using OnEvent would fix that.

Share this post


Link to post
Share on other sites

Hmm, you used a "_break" function to escape the loop, and assigned it to a hotkey. I havn't had any issues getting hotkeys to trigger the function (multiple times), but the GUI buttons won't. So, is it possible to retrigger the same function while it's already running with a GUI button, or do I have no choice but to use a second function? I don't understand why my hotkey can recall the function that's being processed and force it to toggle, but the GUI button cannot. Is the fact that my function is looping preventing the program from receiving my button press? I thought using OnEvent would fix that.

<{POST_SNAPBACK}>

If it is in a loop it has to have something to break the loop before it can do something else. I don't think you can get messages from GUI controls while in a loop other then a loop for checking GUI controls. As for OnEvent mode I never worked with it before, but from what I have seen. You have to finish an event before you start another.

.

Share this post


Link to post
Share on other sites

Darn, well I guess if I can't fork the function loop from the GUI loop I'm gonna have to rely on the hotkey alone.

Share this post


Link to post
Share on other sites

? this might work if both GUIs were "child" windows of a main? - maybe, as in CDC code wizard by Gary Frost - the List GUI and the right Window buttons are all active at once? In programming, the loop might be able to include "onEvent"s from both each time?

What do you think? -ask Gary?

Randall

cf "close GUI from func" as you may need to do that?

Close Gui from func

Edited by randallc

Share this post


Link to post
Share on other sites

Woops - I think I see what you want to do at last! But to monitor a button, that GUI must still have focus, so I think they will both need to be a "child" window, and the buttons monitored within the same loop (or even 1 loop calling 2 loop checking functions). Perhaps you had already got there?

Here is a "Toggle button" for the left window in an altered menu GUI which incidentally calls Gary's Dual child window;

(I have put the "_leftsidewindow()" into a function which draws the child initially, then re-draws during the loop as needed)

(See post in scraps)Gradient and colour change on the fly

Toggle in CFCWiz

Case $msg = $TOGGLE; TOGGLE LEFT WINDOW
            If WinGetState($TEST_WINDOW)  = 0 Then
                _leftsidewindow()
                GUISetState(@SW_SHOW, $TEST_WINDOW)
            Else
                GUIDelete($TEST_WINDOW)
            EndIf
Edited by randallc

Share this post


Link to post
Share on other sites

OK, I got it, thanks to the master!

Master

Can you tell me why you cannot find it by yourself so I can improve the documentation if needed? 

AutoIt'Gui'ment votre

JP

[My answer is that i don't know how to "search" the help or the forum well enough, perhaps? - But I have not found examples using "AND" and arrays in the loop? (EDIT - now I have inn the Help - but perhaps if it had come up under "GUIgetMsg" with F1 I might have found it! -not sure; at least prehaps cross-reference to the general GUI usage area?)

#Include <GUIConstants.au3>
#Include <Array.au3>
Global $SecondGUI, $Message2button, $msg1, $msg2, $GUI
$GUI=GUICreate("GUI",200,200)
$TOGGLEbutton = GUICtrlCreateButton("Toggle GUI",30,30,100,40)
GUISetstate(@SW_SHOW)

_2ndGUI();DRAW the 2nd Window with the function
GUISetstate(@SW_SHOW)
GUIDelete($SecondGUI)

Func _2ndGUI()
$SecondGUI = GUICreate("Second GUI",200,200,100,100)
$Message2button = GUICtrlCreateButton("Message &2 button",30,30,140,40)
GUISetBkColor (0x3D589C)    
GUISetState(@SW_SHOW)    
EndFunc

While 1
    $msg_array = GUIGetMsg(1)
    $msg = $msg_array[0] 
    $winActive = $msg_array[1] 
;_ArrayDisplay ($msg_array,"array")
Select
    Case $msg = $Message2button;AND $winActive = $SecondGUI  
    MsgBox(4096,"$msg_array="&$msg_array,"From 2nd window button",5)
    Case $msg = $TOGGLEbutton  ;AND $winActive = $GUI  
            If WinGetState($SecondGUI)  = 0 Then
            _2ndGUI();DRAW the 2nd Window with the function
            GUISetState(@SW_SHOW, $SecondGUI)
            Else
                GUIDelete($SecondGUI)
            EndIf
            $msg_array[0] =0            
    case ($msg = $GUI_EVENT_CLOSE) AND $winActive = $SecondGUI  
    GUIDelete($SecondGUI)
    case ($msg = $GUI_EVENT_CLOSE)  AND $winActive = $GUI  
    ExitLoop    
 EndSelect
WEnd

We really have to have an "AND" to check (in ONE loop) if "msg" is reading from the appropriate window's event (Are there other events we need to check with"AND" apart from close, which might be the same number from each GUI?) ; perhaps re-write the separate loops using the return arrays would work too? _ Could you please post it if you get it working?

Best, Randall

Posted Image

Edited by randallc

Share this post


Link to post
Share on other sites

Here it is with the loop in the func as well; I guess "GUI-Switch" is useful for these issues too; do you have it all going now?

#Include <GUIConstants.au3>

#Include <Array.au3>

Global $SecondGUI, $Message2button, $msg1, $msg2, $GUI

$GUI=GUICreate("GUI",200,200)

$TOGGLEbutton = GUICtrlCreateButton("Toggle GUI",30,30,100,40)

GUISetstate(@SW_SHOW)

_2ndGUI();DRAW the 2nd Window with the function

GUISetstate(@SW_SHOW)

GUIDelete($SecondGUI)

Func _2ndGUI()

$SecondGUI = GUICreate("Second GUI",200,200,100,100)

$Message2button = GUICtrlCreateButton("Message &2 button",30,30,140,40)

GUISetBkColor (0x3D589C)   

GUISetState(@SW_SHOW)

While 1

    $msg_array = GUIGetMsg(1)

    $msg = $msg_array[0]    $winActive = $msg_array[1]

;_ArrayDisplay ($msg_array,"array")

Select

    Case $msg = $Message2button

    MsgBox(4096,"$msg_array="&$msg_array,"From 2nd window button and in func",5)

    ;GUIDelete($SecondGUI)

;_2ndGUI()

Case $msg = $TOGGLEbutton 

            If WinGetState($SecondGUI)  = 0 Then

            _2ndGUI();DRAW the 2nd Window with the function

            GUISetState(@SW_SHOW, $SecondGUI)

            Else

                GUIDelete($SecondGUI)

            EndIf

    MsgBox(4096,"$msg_array="&$msg_array,"From 2nd window button and in func",5)

            $msg_array[0] =0           

    case ($msg = $GUI_EVENT_CLOSE) AND $winActive = $SecondGUI 

    GUIDelete($SecondGUI)

    case ($msg = $GUI_EVENT_CLOSE)  AND $winActive = $GUI 

    Exit   

EndSelect

WEnd

EndFunc

While 1

    $msg_array = GUIGetMsg(1)

    $msg = $msg_array[0]

    $winActive = $msg_array[1]

;_ArrayDisplay ($msg_array,"array")

Select

    Case $msg = $Message2button

    MsgBox(4096,"$msg_array="&$msg_array,"From 2nd window button",5)

    GUIDelete($SecondGUI)

_2ndGUI()

    Case $msg = $TOGGLEbutton 

            If WinGetState($SecondGUI)  = 0 Then

            _2ndGUI();DRAW the 2nd Window with the function

            GUISetState(@SW_SHOW, $SecondGUI)

            Else

                GUIDelete($SecondGUI)

            EndIf

            $msg_array[0] =0           

    case ($msg = $GUI_EVENT_CLOSE) AND $winActive = $SecondGUI 

    GUIDelete($SecondGUI)

    case ($msg = $GUI_EVENT_CLOSE)  AND $winActive = $GUI 

    ExitLoop   

EndSelect

WEnd

Share this post


Link to post
Share on other sites

Maybe this simple way. Just make it set a global variable

and let the main loop check this variable.

This works, I hope its what you meant.

It does something wich is looped (looped in the main loop) and started from a function. Also other buttons stil react during the counting.

#include <GUIConstants.au3>

Func blah()
  if $carrot then 
     $carrot = 0
  else
    $carrot = 1
  endif
endfunc

func closeme()
  exit
endfunc

Opt("GUIOnEventMode", 1)

global $carrot=0

guiCreate("doggy")
$weirdbutton =  guictrlcreatebutton("bummer",1,1,60,22)
Guictrlsetonevent($weirdbutton,"blah")
GUISetOnEvent($GUI_EVENT_CLOSE, "closeme")
guisetstate()


$count=1

while 1;main loop
    if $carrot then 
     GUICtrlSetPos ( $weirdbutton, 1, 1 , 150 , 22 )
     GUICtrlSetdata($weirdbutton,"push me to stop counter => " & $count)
     $count += 1
   else
      $count = 1
      GUICtrlSetPos ( $weirdbutton, 1, 1 , 60 , 22 )
      GUICtrlSetdata($weirdbutton,"bummer")
   endif
   sleep(500)
wend

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...