Closing the application in Windows
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Closing the application in Windows
Ive done a dew searches for this one, and cannot seem to find an answer.
When you close a windows app with the x button in the top corner, it just closes the stack, and the application continues to run.
If you put 'quit' in on preclosestack then it closes the application, but every time I close the stack in the IDE, it shuts the whole of revolution down!
Is there any way to get an application to quit when you press the x button, but only in compiled applications.
Thanks
Andy
When you close a windows app with the x button in the top corner, it just closes the stack, and the application continues to run.
If you put 'quit' in on preclosestack then it closes the application, but every time I close the stack in the IDE, it shuts the whole of revolution down!
Is there any way to get an application to quit when you press the x button, but only in compiled applications.
Thanks
Andy
Re: Closing the application in Windows
Hi Andy,andyh1234 wrote:...
When you close a windows app with the x button in the top corner, it just closes the stack, and the application continues to run....
are you sure? I know this exactly the other way round!
If you close the last window of a Mac app, the app does NOT quit because of the omnipresent Mac menubar.
But on windwos the app will quit when you close its last window.
Or am I missing something?
Best
Klaus
Hi Klaus,
No, if you make an empty standalone --or just with a very simple script--, it is the other way around: on Mac it quits and on Win it keeps running.
Best,
Mark
No, if you make an empty standalone --or just with a very simple script--, it is the other way around: on Mac it quits and on Win it keeps running.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Hi Klaus,
I'll be more precise.
A completely empty stack quits on Mac, after you click in the close box. On Windows, this is also supposed to happen, but there are versions of Revolution where this doesn't work. If a stack is not entirely empty, the stack will probably not close correctly on Windows. Btw, there is also a version of Revolution that doesn't quit properly on Mac.
If you have had scripts running, you have to make sure that you close all windows, stop all externals, close all databases, stop all pending messages, and issue the quit command to quit a stack correctly on Windows.
Best,
Mark
I'll be more precise.
A completely empty stack quits on Mac, after you click in the close box. On Windows, this is also supposed to happen, but there are versions of Revolution where this doesn't work. If a stack is not entirely empty, the stack will probably not close correctly on Windows. Btw, there is also a version of Revolution that doesn't quit properly on Mac.
If you have had scripts running, you have to make sure that you close all windows, stop all externals, close all databases, stop all pending messages, and issue the quit command to quit a stack correctly on Windows.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
This is just good practice to use also. This isn't something limited to Rev, I've used other languages that also are suppose to close the entire app down, but do not. So it's become a habit for me to always close open files, exit external calls and forcible close my own app down when an exit call has been made to it.Mark wrote:If you have had scripts running, you have to make sure that you close all windows, stop all externals, close all databases, stop all pending messages, and issue the quit command to quit a stack correctly on Windows.
And yes, Rev at least has that nice thing called "environment" which allows to see if you are in the IDE. That allows you to things like Malte noted up there, which would not close your app while you are in the IDE, but will close it when run outside of the IDE.
Thanks everyone again, Maltes suggestion did the trick nicely.
I modified it a little as follows:
The first kills the app nicely if the user hits the x button, but saves the IDE from closing.
The second code is needed to save shutting the IDE from quit commands issued in the script.
I modified it a little as follows:
Code: Select all
on CloseStackRequest
if the environment is "development" then
answer "Development mode - quit aborted to save IDE!"
else
if the platform is "MacOS" then
Pass CloseStackRequest -- The mac quits OK anyway!
else
quit
end if
end if
end CloseStackRequest
Code: Select all
on ShutDownRequest
if the environment is "development" then
answer "Development mode - quit aborted to save IDE!"
else
pass ShutDownRequest
end if
end ShutDownRequest
The second code is needed to save shutting the IDE from quit commands issued in the script.
Hi Andy1234,
As I explained earlier, your script is insufficient to correctly quit processes on Windows.
Best,
Mark
As I explained earlier, your script is insufficient to correctly quit processes on Windows.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Im not sure what you mean Mark.
Without the script if you close an application, and then try to delete the exe file, you cant as its still in use.
With the script in place you can close the application, and then delete the application exe, so I assumed it had all closed.
If thats not the case, what would I need to add to close everything?
Thanks
Andy
Without the script if you close an application, and then try to delete the exe file, you cant as its still in use.
With the script in place you can close the application, and then delete the application exe, so I assumed it had all closed.
If thats not the case, what would I need to add to close everything?
Thanks
Andy
Hi Andy,
Why would you delete the exe file?
If you have had scripts running, you have to make sure that you close all windows, stop all externals, close all databases, stop all pending messages, and issue the quit command to quit a stack correctly on Windows.
Apparently, your stack doesn't use any special features. However, when your project advanced, you will be unpleasantly surprised to find out that your application no longer quits correctly.
Evidently, if you don't have any database drivers included in your project, you don't need to close any databases. If you don't use externals, there is no need to stop them. You probably want to stop pending messages, even if you don't use them, because Revolution may create them by itself, such as the uTickle message.
Here is a script that I use for almost all my projects.
I adjust this script to meet the requirements of my individual projects. For example, if I use Revolution's speech capabilities, I will have to add the revUnloadSpeech command.
I recommend having a close look at this script and copying what you need.
Best,
Mark
Why would you delete the exe file?
If you have had scripts running, you have to make sure that you close all windows, stop all externals, close all databases, stop all pending messages, and issue the quit command to quit a stack correctly on Windows.
Apparently, your stack doesn't use any special features. However, when your project advanced, you will be unpleasantly surprised to find out that your application no longer quits correctly.
Evidently, if you don't have any database drivers included in your project, you don't need to close any databases. If you don't use externals, there is no need to stop them. You probably want to stop pending messages, even if you don't use them, because Revolution may create them by itself, such as the uTickle message.
Here is a script that I use for almost all my projects.
Code: Select all
on quitMyProject
lock messages
-- MySql
put revOpenDatabases() into myDatabases
repeat for each item myBase in myDatabases
revCloseDatabase myBase
end repeat
-- stop using stacks
put the stacksInUse into myStacks
repeat for each line myStack in myStacks
stop using stack myStack
end repeat
-- stacks
put the openStacks into myStacks
put "message box,home,tool,Message Box,revTools,revMenubar" & comma & the short name of me into myDontClose
repeat for each line myStack in myStacks
if myStack is not among the items of myDontClose then close stack myStack
end repeat
-- messages
put the pendingmessages into myMsgs
repeat for each line myMsg in myMsgs
cancel item 1 of myMsg
end repeat
close me
if the environment is not "development" then
quit
end if
end quitMyProject
I recommend having a close look at this script and copying what you need.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re:
Hello Mark,Mark wrote: Here is a script that I use for almost all my projects.
I use your script to quit properly.
But I have one question : where to put it exactly ?
In a CloseStack ?
In a CloseStackRequest ?
If I put it in a "Quit" button, that's perfect. But what about a user who would click on the "x" on the Windows app ?
Re: Closing the application in Windows
Hi Bkk,
Personally, I put the quitMyProject script into the stack script of your mainstack, where the mainstack is the one that's embedded in the standalone. You can call the handler from any handler that ultimately closes your application. Normally this is a shutDownRequest handler, sometimes it is a closeStackRequest handler and sometimes it is just in a mouseUp handler in a button with the label Quit.
If you have multiple mainstacks, i.e. several that are not part of your standalone, and you want to call the handler from another mainstack, perhaps you should do something like
It is important that the mainstack closes last, because scripts stop running when their stacks are deleted from memory.
Kind regards,
Mark
Personally, I put the quitMyProject script into the stack script of your mainstack, where the mainstack is the one that's embedded in the standalone. You can call the handler from any handler that ultimately closes your application. Normally this is a shutDownRequest handler, sometimes it is a closeStackRequest handler and sometimes it is just in a mouseUp handler in a button with the label Quit.
If you have multiple mainstacks, i.e. several that are not part of your standalone, and you want to call the handler from another mainstack, perhaps you should do something like
Code: Select all
send "quitMyProject" to stack "Your Standalone Mainstack" in 0 millisecs
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode