The answer is both. OnLastWindow close will fire for both since the action of quitting the program will try to gracefully exit your database before exiting the application.
This will NOT however be the case if the application crashes or is force quit, then the answer is neither, since the program is interrupted before the OnLastWindow action can fire.
What you might want to do is open all of your windows without a close option so "close window" is only allowed programmatically via a button you fire. You can then check for last window using the WindowNames design function:
Basically you don't use the OnLastWindow action, and you script all of your window closes via your own buttons to get complete control.