Thread: Files

  1. #1
    Registered User
    Join Date
    Sep 2002


    I created a text editor know I have 2 problems
    1. I want that when I close the program or the file the program ask me if I want to ave the file or not.
    2. When I've changed nothing he don't do that.

  2. #2
    Registered User
    Join Date
    Nov 2001
    One solution is MFC's SetModified(). Call that function in the document class.


  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    If your not using MFC, you can use the same idea. Have a boolean flag called "Changed" or similar.

    When you create a new file, then obviously, anything they type is new so they should be asked, hence, new file, set "Changed" to TRUE.

    When you open an existing file, they have not actually changed anything, so set it to FALSE. If, using your program they do anything to change the file, set "Changed" to TRUE.

    Now, when you come to exit, check the flag, if it is TRUE ask them if they want to save, if it is FALSE, don't bother.

    This is, of course, highly simplistic. It would not work if they change something, and then change it back again, but it will get you started.

    A way to get round the change/unchange problem is to calculate a file checksum when you open the file, and then recalculate the checksum when you do the save, if the checksums are the same, no save is necessary, if they are different, ask them.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ressources files
    By mikahell in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2006, 06:50 AM
  2. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM