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



Comments

  • A Lot of Compilation Warnings

    Posted by Legacy on 09/15/1999 12:00am

    Originally posted by: Stefano Modolo

    I try to compile CFileChangeEvent object with Visual C++ 6.0 but arise a lot of warning (using level 4) such as C4786, C4018, etc. And overall Why? Thank you for your reply.

    Reply
  • Missing FileChange.dsp?

    Posted by Legacy on 06/16/1999 12:00am

    Originally posted by: Janice Gallant

    This looks interesting but I can't open the project because there is no FileChange.dsp file. I can only view files individually.

    Reply
  • CFileChangeEvent Class

    Posted by Legacy on 05/11/1999 12:00am

    Originally posted by: Tim Walsh

    can it be made to watch a set of files on one server, and update a set of files on another server if there is a change?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • It's no secret what keeps CIOs up at night. Mobile, cloud, data, security, and social have become the "five imperatives," the drivers of business progress, innovation, and competitive differentiation. Business leaders around the world want to hear how other companies are succeeding. How are they applying the latest technologies? How did they get started? What outcomes are they achieving? Read this online magazine for success stories from organizations like the NBA, Pfizer, and San Jose State University as they …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds