Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Development
  4. How do I check to see if any running applications have unsaved documents?

How do I check to see if any running applications have unsaved documents?

Scheduled Pinned Locked Moved Windows Development
questiontutorial
9 Posts 3 Posters 51 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Ben Aldhouse
    wrote on last edited by
    #1

    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.

    L B 2 Replies Last reply
    0
    • B Ben Aldhouse

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      That is almost impossible, since each application will have its own way of keeping track of whether open documents need to be saved.

      B 1 Reply Last reply
      0
      • L Lost User

        That is almost impossible, since each application will have its own way of keeping track of whether open documents need to be saved.

        B Offline
        B Offline
        Ben Aldhouse
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • B Ben Aldhouse

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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)

          1 Reply Last reply
          0
          • B Ben Aldhouse

            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.

            B Offline
            B Offline
            Ben Aldhouse
            wrote on last edited by
            #5

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

            Kornfeld Eliyahu PeterK L 2 Replies Last reply
            0
            • B Ben Aldhouse

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

              Kornfeld Eliyahu PeterK Offline
              Kornfeld Eliyahu PeterK Offline
              Kornfeld Eliyahu Peter
              wrote on last edited by
              #6

              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.

              "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

              B 1 Reply Last reply
              0
              • B Ben Aldhouse

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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                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)

                B 1 Reply Last reply
                0
                • L Lost User

                  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)

                  B Offline
                  B Offline
                  Ben Aldhouse
                  wrote on last edited by
                  #8

                  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!

                  1 Reply Last reply
                  0
                  • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                    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.

                    B Offline
                    B Offline
                    Ben Aldhouse
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups