CFileChangeEvent Class | CodeGuru

CFileChangeEvent Class

This article is based on another article found here on Codeguru : Alerting the user when an open file has been changed by another application (from Bernd Wib ler). This article showed us how a CDocument-class can be notified when the file is changed by another application. My problem is that my CDocument-class is like […]

Written By
CodeGuru Staff
CodeGuru Staff
May 17, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This article is based on another article found here on Codeguru : Alerting the user when
an open file has been changed by another application (from Bernd Wib ler).
This article showed us how a CDocument-class can be notified when the file is changed by another application.
My problem is that my CDocument-class is like a projectfile: It has a collection of files. I want my
CDocument-class to be notified if one of these files is changed.

I’ve created a new class called CFileChangeEvent. This class has following methodes :

void addFile(const std::string &sFileName)


Use this method when you want to be notified of changes of a file. When the notification thread is running it will be stopped and restarted.


void removeFile(const std::string &sFileName)

Use this method when you don’t want to be notified anymore. When the notification thread is running it will be stopped and restarted.


void startWatch(void)

This method starts the notification thread.


void stopWatch(void)

This method stops the notification thread. It’s also called in the destructor, so you the thread will allways stop.


virtual void OnFileAlarm(FileAlarm nAlarm, const std::string &sFileName)

Override this method. This method is called when a file is changed or deleted. FileAlarm is an enum with following attributes : FA_CHANGED, FA_REMOVED.


How to use this class ?


Derive a class (for example your CDocument-class) from CFileChangeEvent and override the OnFileAlarm. That’s all.


Download demo project – 37 KB


Download source – 4 KB

Date Last Updated: May 17, 1999

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.