1. Starting and Stopping an Automated Process in Win32Lib
- Posted by euphoric (admin) Jan 27, 2012
- 1817 views
I want to be able to click a button which starts an automated process (within the same program/window), but also have a "Stop" button that will stop it.
Can somebody (like Derek) put together a small sample of how I might accomplish that? Or point to a demo that does this already?
Thanks in advance!
2. Re: Starting and Stopping an Automated Process in Win32Lib
- Posted by m_sabal Jan 27, 2012
- 1738 views
Depends on what's running the process. If you have a Windows service that you want to control via a GUI app, you can use a shell command to execute "sc start|stop ServiceName". If the process is part of the same program as the GUI, have the button handlers set a global variable, and have the payload loop quit if that variable is set to a stop value. You may have to include a command to process events within the payload loop so the button click actually gets handled. I'm not sure if it's still that way in the latest Win32Lib or not.
3. Re: Starting and Stopping an Automated Process in Win32Lib
- Posted by DerekParnell (admin) Jan 28, 2012
- 1732 views
I want to be able to click a button which starts an automated process (within the same program/window), but also have a "Stop" button that will stop it.
Can somebody (like Derek) put together a small sample of how I might accomplish that? Or point to a demo that does this already?
Thanks in advance!
I'm not quite sure what you are asking for, sorry.
I'm guessing you want to click a button to start an independent thread within the current process, and press a button to signal that thread to stop. Depending on how independent you wish the thread to be, it could be done quite simply. Here is one suggestion ...
include win32lib.ew include std/filesys.e include std/text.e integer hmainwin integer hstartpath integer hdirresult integer hbutton integer hwriter integer startstop constant STOPPED = 0, STARTED = 1 function ShowFile(sequence path, sequence dirent) if startstop = STARTED then -- keep showing files. if find('d', dirent[D_ATTRIBUTES]) then addItem(hdirresult, '[' & path & SLASH & dirent[D_NAME] & ']' ) else addItem(hdirresult, path & SLASH & dirent[D_NAME]) end if setIndex(hdirresult, -1) -- allow other events to occur before getting the next file to show. doEvents(0) return 0 else -- Something has told me I have to tell walk_dir to stop. return 1 end if end function procedure Click_Button(integer id, integer event, sequence parms) sequence path if startstop = STOPPED then path = getText(hstartpath) if length(path) = 0 then return end if startstop = STARTED setText(hbutton, "Stop") eraseItems(hdirresult) setFocus(hwriter) -- Just to show user they can type stuff here now. if length(getText(hwriter)) = 0 then setText(hwriter, "Begin typing here now.") setIndex(hwriter, {1,0}) end if -- begin showing files. walk_dir(path, routine_id("ShowFile"), 1) startstop = STOPPED setText(hbutton, "Start") else startstop = STOPPED setText(hbutton, "Start") end if end procedure procedure closer(integer id, integer event, sequence parms) if startstop = STARTED then -- Thus walk_dir is currently running so I have to signal it to stop. startstop = STOPPED doEvents(0) -- give walk_dir a chance. end if end procedure procedure main() startstop = STOPPED hmainwin = create(Window, "The Window", 0, 0, 0, 800, 600, 0) setHandler(hmainwin, w32HClose, routine_id("closer")) create(LText, "Path:", hmainwin, 5, 10, 40, 18, 0) hstartpath = create(EditText, "", hmainwin, 50, 10, 400, 18, 0) create(LText, "Files", hmainwin, 5, 30, 40, 18, 0) hdirresult = create(ListBox, "", hmainwin, 5, 50, 500, 500, 0) hbutton = create(Button, "Start", hmainwin, 5, 530, 70, 22, 0) setHandler(hbutton, w32HClick, routine_id("Click_Button")) hwriter = create(MleText, "", hmainwin, 515, 10, 200, 400, 0) WinMain( {hmainwin, hstartpath}, Normal) end procedure main()
This program gets the file names from the starting path and adds them to the list. While it is doing that, you are free to use the other controls ... eg. write in the textbox and press the stop button.
4. Re: Starting and Stopping an Automated Process in Win32Lib
- Posted by euphoric (admin) Jan 31, 2012
- 1583 views
I want to be able to click a button which starts an automated process (within the same program/window), but also have a "Stop" button that will stop it.
Can somebody (like Derek) put together a small sample of how I might accomplish that? Or point to a demo that does this already?
Thanks in advance!
I'm not quite sure what you are asking for, sorry.
No, you figured it out perfectly.
I'm guessing you want to click a button to start an independent thread within the current process, and press a button to signal that thread to stop. Depending on how independent you wish the thread to be, it could be done quite simply. Here is one suggestion ...
Yes, perfect.
Thank you, Derek! I'm going to try to adapt my current program to use this paradigm. Let's see what happens...
5. Re: Starting and Stopping an Automated Process in Win32Lib
- Posted by BRyan Feb 02, 2012
- 1488 views
Why couldn't you use the Euphoria built-in task functions ?