How do I check to see if any running applications have unsaved documents?
-
I have seen other people's solution to the rather small, obscured 'power off' button in Windows 10 - by making a link to shutdown.exe. Unfortunately, as far as I can see, shutdown.exe will not check to see if there are any unsaved documents and will close the computer whether data is saved or not. Also, although you can delay shutdown.exe - this, I think, is made almost completely pointless by the fact that there is no way to cancel it (that I can see). My idea is to write a small program which will call shutdown.exe after a delay but which can be cancelled. This bit, I'm pretty sure I can do. The part I have no idea how to do is to check to see if there are any unsaved documents so I can give the user the option to quit shut down. Is it possible to check to see if there are unsaved documents? How would I do this? Thanks.
-
I have seen other people's solution to the rather small, obscured 'power off' button in Windows 10 - by making a link to shutdown.exe. Unfortunately, as far as I can see, shutdown.exe will not check to see if there are any unsaved documents and will close the computer whether data is saved or not. Also, although you can delay shutdown.exe - this, I think, is made almost completely pointless by the fact that there is no way to cancel it (that I can see). My idea is to write a small program which will call shutdown.exe after a delay but which can be cancelled. This bit, I'm pretty sure I can do. The part I have no idea how to do is to check to see if there are any unsaved documents so I can give the user the option to quit shut down. Is it possible to check to see if there are unsaved documents? How would I do this? Thanks.
-
That is almost impossible, since each application will have its own way of keeping track of whether open documents need to be saved.
I thought there would be some way of centrally registering if a document is unsaved. After all, doesn't then main 'Power Off' button in Windows prompt you with an 'You have unsaved data. Are you sure you want to close down?' type message? - which suggests that this is the case for at least some applications.
-
I thought there would be some way of centrally registering if a document is unsaved. After all, doesn't then main 'Power Off' button in Windows prompt you with an 'You have unsaved data. Are you sure you want to close down?' type message? - which suggests that this is the case for at least some applications.
Ben Aldhouse wrote:
I thought there would be some way of centrally registering if a document is unsaved.
No. You simply keep a dirty-flag somewhere in your application.
Ben Aldhouse wrote:
'You have unsaved data. Are you sure you want to close down?' type message?
It will say that some applications aren't responding and that you might lose data if you close them anyway. In WinForms you get a closing-event that is fired when Windows shuts down; the application should then shut down, but some applications show a dialog asking the user whether or not to shut down. Meaning Windows asks them to close, and they simply refuse and hang around. Next question from Windows; do you want to terminate the applications that did not shut down?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
I have seen other people's solution to the rather small, obscured 'power off' button in Windows 10 - by making a link to shutdown.exe. Unfortunately, as far as I can see, shutdown.exe will not check to see if there are any unsaved documents and will close the computer whether data is saved or not. Also, although you can delay shutdown.exe - this, I think, is made almost completely pointless by the fact that there is no way to cancel it (that I can see). My idea is to write a small program which will call shutdown.exe after a delay but which can be cancelled. This bit, I'm pretty sure I can do. The part I have no idea how to do is to check to see if there are any unsaved documents so I can give the user the option to quit shut down. Is it possible to check to see if there are unsaved documents? How would I do this? Thanks.
Thanks for your replies Richard and Eddy. I think I may have discovered a 'feature' of Windows 10 here. I have just done some experiments with Notepad++ v6.7.7 and Inkscape v0.91. Notepad is so advanced that an unsaved document gets saved anyway and opened up next time you open Notepad++. I think Visual Studio tends towards this level of foolproofness, too. It will give a message when you open it up asking if you would like to 'recover' unsaved files from the last session. Inkscape, however, will lose what you were working on if you haven't saved it. When I try and close Inkscape with an unsaved document it will produce a dialog asking me if really want to close it. However, when I close Windows 10 with an unsaved Inkscape document the document is lost. I think that this dialog would have caused the shutdown process to ask for user feedback in older versions of Windows. Not so in the current version of 10. Is it Windows policy now that all applications should save documents on the fly or users be more careful? Is it an oversight in Windows 10? May be it will be fixed soon and I won't have to write my little program...
-
Thanks for your replies Richard and Eddy. I think I may have discovered a 'feature' of Windows 10 here. I have just done some experiments with Notepad++ v6.7.7 and Inkscape v0.91. Notepad is so advanced that an unsaved document gets saved anyway and opened up next time you open Notepad++. I think Visual Studio tends towards this level of foolproofness, too. It will give a message when you open it up asking if you would like to 'recover' unsaved files from the last session. Inkscape, however, will lose what you were working on if you haven't saved it. When I try and close Inkscape with an unsaved document it will produce a dialog asking me if really want to close it. However, when I close Windows 10 with an unsaved Inkscape document the document is lost. I think that this dialog would have caused the shutdown process to ask for user feedback in older versions of Windows. Not so in the current version of 10. Is it Windows policy now that all applications should save documents on the fly or users be more careful? Is it an oversight in Windows 10? May be it will be fixed soon and I won't have to write my little program...
When you close an application (Inkscape for instance), it will receive a WM_CLOSE[^] message form the OS and as response to it it will ask you to save (or not to save) the unsaved documents... When you close the whole OS the messages to send is WM_QUERYENDSESSION[^] and WM_ENDSESSION[^]. If those messages are not handled the application will lost data... So it is entirely up to the application... However you may replace the standard shutdown process with your own, where before any other messages you send a WM_CLOSE to each (top-level) window...If the window returns 0 (means, it handled the message), you continue to the next, but if not you can pop a message to alert the user and bring the window to focus...If you got to the end of the list, you can shut down the OS...
Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.
-
Thanks for your replies Richard and Eddy. I think I may have discovered a 'feature' of Windows 10 here. I have just done some experiments with Notepad++ v6.7.7 and Inkscape v0.91. Notepad is so advanced that an unsaved document gets saved anyway and opened up next time you open Notepad++. I think Visual Studio tends towards this level of foolproofness, too. It will give a message when you open it up asking if you would like to 'recover' unsaved files from the last session. Inkscape, however, will lose what you were working on if you haven't saved it. When I try and close Inkscape with an unsaved document it will produce a dialog asking me if really want to close it. However, when I close Windows 10 with an unsaved Inkscape document the document is lost. I think that this dialog would have caused the shutdown process to ask for user feedback in older versions of Windows. Not so in the current version of 10. Is it Windows policy now that all applications should save documents on the fly or users be more careful? Is it an oversight in Windows 10? May be it will be fixed soon and I won't have to write my little program...
Ben Aldhouse wrote:
Notepad is so advanced that an unsaved document gets saved anyway and opened up next time you open Notepad++.
That is not exactly advanced, just a choice. One usually copies the document to the temp-folder and have the user edit that, saving each edit. Or when the application shuts down - without blocking that process, if it does, it will be terminated and all data will be lost.
Ben Aldhouse wrote:
Is it an oversight in Windows 10?
Probably more a reaction to applications blocking/preventing Windows from shutting down.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
Ben Aldhouse wrote:
Notepad is so advanced that an unsaved document gets saved anyway and opened up next time you open Notepad++.
That is not exactly advanced, just a choice. One usually copies the document to the temp-folder and have the user edit that, saving each edit. Or when the application shuts down - without blocking that process, if it does, it will be terminated and all data will be lost.
Ben Aldhouse wrote:
Is it an oversight in Windows 10?
Probably more a reaction to applications blocking/preventing Windows from shutting down.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
Eddy Vluggen wrote:
Probably more a reaction to applications blocking/preventing Windows from shutting down.
Windows not closing down is actually useful to me, though, seeing as I am often daft enough to try and close down my computer before I have saved my work!
-
When you close an application (Inkscape for instance), it will receive a WM_CLOSE[^] message form the OS and as response to it it will ask you to save (or not to save) the unsaved documents... When you close the whole OS the messages to send is WM_QUERYENDSESSION[^] and WM_ENDSESSION[^]. If those messages are not handled the application will lost data... So it is entirely up to the application... However you may replace the standard shutdown process with your own, where before any other messages you send a WM_CLOSE to each (top-level) window...If the window returns 0 (means, it handled the message), you continue to the next, but if not you can pop a message to alert the user and bring the window to focus...If you got to the end of the list, you can shut down the OS...
Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.
This looks interesting. May be I'll get around to having a look at what is going on with these messages eventually. It would be an interesting exercise. However, now I have seen that it isn't just short cuts to shutdown.exe that cause Windows to close down in a way that can cause unsaved work to be lost I've come to the conclusion that this is a possible oversight by Microsoft and I'll probably leave it for a while to see if they change it back themselves before I attempt to write my own fix. Oh for just a little bit more time per day to get things done...