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. C / C++ / MFC
  4. File Close Notification

File Close Notification

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 4 Posters 0 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.
  • A Offline
    A Offline
    Aamir Butt
    wrote on last edited by
    #1

    Hi Is there a way to get a notification when a file is closed by another program. e.g., I have a txt file in my app in which another program , say notepad, writes something. Is there a way to get to know immediately when that program closes the file. I know i can do it through polling mechanism but i'm looking for a Notification based solution if possible.

    "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

    R H 2 Replies Last reply
    0
    • A Aamir Butt

      Hi Is there a way to get a notification when a file is closed by another program. e.g., I have a txt file in my app in which another program , say notepad, writes something. Is there a way to get to know immediately when that program closes the file. I know i can do it through polling mechanism but i'm looking for a Notification based solution if possible.

      "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

      R Offline
      R Offline
      Rinu_Raj
      wrote on last edited by
      #2

      You may use the following code if you hav only that file in its directory if there is any other file in the directory a change in any of the file will signal the event. HANDLE hFileChangeHandle = FindFirstChangeNotification("C:\TestDir",TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE); // Wait until a file in the C:\TestDir is changed. if( WAIT_OBJECT_0 == WaitForSingleObject( hFileChangeHandle, INFINITE )) { // Do the action u want to do } RinuRaj

      A 2 Replies Last reply
      0
      • R Rinu_Raj

        You may use the following code if you hav only that file in its directory if there is any other file in the directory a change in any of the file will signal the event. HANDLE hFileChangeHandle = FindFirstChangeNotification("C:\TestDir",TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE); // Wait until a file in the C:\TestDir is changed. if( WAIT_OBJECT_0 == WaitForSingleObject( hFileChangeHandle, INFINITE )) { // Do the action u want to do } RinuRaj

        A Offline
        A Offline
        Aamir Butt
        wrote on last edited by
        #3

        Have you tried this? AFAIK, WaitForSingleObject doesnt work on Change Notification Handles. As per MSDN Documentation it works only on the following object handles. Event Mutex Semaphore Process Thread Anyway... I will give it a try and will let u know the result

        "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

        1 Reply Last reply
        0
        • R Rinu_Raj

          You may use the following code if you hav only that file in its directory if there is any other file in the directory a change in any of the file will signal the event. HANDLE hFileChangeHandle = FindFirstChangeNotification("C:\TestDir",TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE); // Wait until a file in the C:\TestDir is changed. if( WAIT_OBJECT_0 == WaitForSingleObject( hFileChangeHandle, INFINITE )) { // Do the action u want to do } RinuRaj

          A Offline
          A Offline
          Aamir Butt
          wrote on last edited by
          #4

          It works, Thanks But there is a little problem that it fires the notifcation event only if the file has changed. It wont do anything if someone just closes the file. That was what I needed precisely. But anyway.... Thanks a lot.

          "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

          R 2 Replies Last reply
          0
          • A Aamir Butt

            It works, Thanks But there is a little problem that it fires the notifcation event only if the file has changed. It wont do anything if someone just closes the file. That was what I needed precisely. But anyway.... Thanks a lot.

            "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

            R Offline
            R Offline
            Rinu_Raj
            wrote on last edited by
            #5

            you may check ReadDirectoryChangesW() use this flag..................FILE_NOTIFY_CHANGE_LAST_ACCESS RinuRaj

            A 1 Reply Last reply
            0
            • A Aamir Butt

              It works, Thanks But there is a little problem that it fires the notifcation event only if the file has changed. It wont do anything if someone just closes the file. That was what I needed precisely. But anyway.... Thanks a lot.

              "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

              R Offline
              R Offline
              Rinu_Raj
              wrote on last edited by
              #6

              hav u checked ReadDirectoryChangesW() please inform me if it was successfull RinuRaj

              1 Reply Last reply
              0
              • R Rinu_Raj

                you may check ReadDirectoryChangesW() use this flag..................FILE_NOTIFY_CHANGE_LAST_ACCESS RinuRaj

                A Offline
                A Offline
                Aamir Butt
                wrote on last edited by
                #7

                This function might work as it is stated but I already said that I dont want to do it through polling mechanism.

                "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

                D 1 Reply Last reply
                0
                • A Aamir Butt

                  This function might work as it is stated but I already said that I dont want to do it through polling mechanism.

                  "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Aamir Butt wrote:

                  ...I dont want to do it through polling mechanism.

                  ReadDirectoryChangesW() doesn't poll. It uses notification. Keep in mind, though, that Windows NT and Windows 2000 only update the LastAccessTime every hour for performance reasons.


                  "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

                  "Judge not by the eye but by the heart." - Native American Proverb

                  1 Reply Last reply
                  0
                  • A Aamir Butt

                    Hi Is there a way to get a notification when a file is closed by another program. e.g., I have a txt file in my app in which another program , say notepad, writes something. Is there a way to get to know immediately when that program closes the file. I know i can do it through polling mechanism but i'm looking for a Notification based solution if possible.

                    "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #9

                    See http://www.codeproject.com/file/filechange.asp[^] maybe it is some helpful to you

                    _**


                    **_

                    WhiteSky


                    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