0

If you open a file in notepad++, then modify it in another application. The notepad++ would remind you the file is modified outside, and you can reload it.

How do I fulfill such feature?

The only way I can figure out is to set a timer to check the file's modification time (rather than to check the file's content due to the performance reason.)

Is there any better method?

PS: I'm working on C++.

Zhang
  • 3,030
  • 2
  • 14
  • 31
  • It could just look at the file modification date / time which is simple for a single file. – drescherjm Jun 27 '19 at 01:42
  • 4
    There is also a winapi way to receive notifications of directory changes. https://learn.microsoft.com/en-us/windows/desktop/fileio/obtaining-directory-change-notifications – drescherjm Jun 27 '19 at 01:45
  • 1
    I usually get notifications of events like this when I change focus from one window to another, not as I type. I'd follow this thinking as I tend to get annoyed if I'm working on something and lose focus to a ing pop-up. – user4581301 Jun 27 '19 at 05:05
  • 1
    Notepad++ is open source, you can find it [here](https://github.com/notepad-plus-plus/notepad-plus-plus) – Jabberwocky Jun 27 '19 at 08:48
  • Anyway instead of checking modification time in a timer you could check it when your app is activated. Check the [`WM_ACTIVATEAPP`](https://learn.microsoft.com/en-us/windows/desktop/winmsg/wm-activateapp) message – Jabberwocky Jun 27 '19 at 08:50
  • @Jabberwocky, I forgot to note the scenario. When user manually changed our config file, I want it to take effect. So, check the focus or active state doesn't work here. – Zhang Jun 27 '19 at 09:01
  • @Zhang OK, that information belong _into_ the question. The second comment probably applies. – Jabberwocky Jun 27 '19 at 09:03
  • 2
    Duplicate of [link](https://stackoverflow.com/questions/931093/how-do-i-make-my-program-watch-for-file-modification-in-c) and explained all aspect. – Tom Tom Jun 27 '19 at 11:18

0 Answers0