Page 1 of 1

Closing the application in Windows

Posted: Thu Aug 23, 2007 3:33 pm
by andyh1234
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

Posted: Thu Aug 23, 2007 4:44 pm
by malte
Hi andy

on closeStack
if "dev" is in the environment then
answer "Normally your application would quit now!"
else
quit
end if
end closeStack

best,

Malte

Re: Closing the application in Windows

Posted: Thu Aug 23, 2007 6:15 pm
by Klaus
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....
Hi Andy,

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

Posted: Thu Aug 23, 2007 6:46 pm
by Mark
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

Posted: Thu Aug 23, 2007 7:25 pm
by Klaus
Hi Mark,

let me see if I understand this correctly:
If you make a (empty = one stack/window only?) standalone and close this one and only stack/window, the app does not quit on Windows?

Posted: Thu Aug 23, 2007 7:52 pm
by Mark
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

Posted: Thu Aug 23, 2007 7:55 pm
by Klaus
Hi Mark,

thanks a lot for this clarification, I was not aware of that.

Posted: Thu Aug 23, 2007 9:48 pm
by Garrett
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.
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.

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.

Posted: Sat Aug 25, 2007 7:53 pm
by andyh1234
Thanks everyone again, Maltes suggestion did the trick nicely.

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 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.

Posted: Sat Aug 25, 2007 8:24 pm
by Mark
Hi Andy1234,

As I explained earlier, your script is insufficient to correctly quit processes on Windows.

Best,

Mark

Posted: Sun Sep 02, 2007 9:52 am
by andyh1234
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

Posted: Sun Sep 02, 2007 12:01 pm
by Mark
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.

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

Posted: Sun Sep 02, 2007 5:41 pm
by andyh1234
Thanks Mark,

I only deleted the exe just to check everything had closed, if you cant delete it something is still locked / running!

It was just a quick check to see if it was quiting correctly, nothing technical!

Re:

Posted: Sat Dec 24, 2011 6:48 pm
by bangkok
Mark wrote: Here is a script that I use for almost all my projects.
Hello Mark,

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

Posted: Mon Feb 13, 2012 12:07 pm
by Mark
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

Code: Select all

send "quitMyProject" to stack "Your Standalone Mainstack" in 0 millisecs
It is important that the mainstack closes last, because scripts stop running when their stacks are deleted from memory.

Kind regards,

Mark