Jump to content

When a GUI button triggers a loop, can other functions be called from buttons?


batfastad
 Share

Recommended Posts

Hi everyone

I've got a GUI which is a wrapper to run a command line utility multiple times for batch processing.

I have a button which triggers a loop over an array and depending on how many files the user has selected, this batch operation can take some time.

I'm hoping I can have the button be a sort of start/stop, so once the loop has started, the button captions changes to Stop (already done) and the loop exits at the next possible point.

The command line utility is triggered by ShellExecuteWait()

But while my script is looping and ShellExecuteWait()ing, can other GUI buttons trigger any other functions/actions?

Or am I limited because scripts are single-threaded?

Such as aborting the process started by ShellExecuteWait()?

Cheers, B

Link to comment
Share on other sites

You won't be able to use the buttons if you're using ShellExecuteWait, because that causes the script to wait until the process started by it has finished before it continues the rest of the script.

As to interrupting a running function, try the information in this link.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I've just tried one of the methods in that wiki article and I have a question.

I'm using OnEvent mode and trying to trigger a function abort from a GUI button, not an Accelerator or HotKey.

I've got the following code to interrupt Windows messages and it triggers the _WM_COMMAND function to set the abort flag. The abort flag is then checked in my batch loop at the start and end of each iteration.

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
...
Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
If BitAND($wParam, 0x0000FFFF) = $ButtonStartStop Then $abortflag = True
Return
EndFunc

The GUI button is designed to be a start/stop button.

When my looping function (the function I want to be able to abort) has started, the button text is changed to "Stop".

Also when my script starts, this button is disabled. The user has to use a browse button to select a valid directory, then the Start button is enabled to the user.

So at various points in my script I am enabling/disabling the Start/Stop button like this...

GUICtrlSetState($ButtonStartStop, $GUI_ENABLE)
...
GUICtrlSetState($ButtonStartStop, $GUI_DISABLE)

Will the action of me enabling/disabling the Start/Stop button from elsewhere in my script, cause the Windows message handler function _WM_COMMAND to be invoked?

Cheers, B

EDIT: I have actually got this running just the way I want by using the method mentioned at the top of the article. Indirectly triggering my main batch loop within the GUI idling loop, then checking an abort flag at various stages.

However I would still like to know if the above is true.

Edited by batfastad
Link to comment
Share on other sites

It should be easy enough for you to check this with something like a ConsoleWrite that's invoked whenever the WM_COMMAND function is jumped to.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

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