Ask user to save changes

This is a discussion on Ask user to save changes within the Windows Programming forums, part of the Platform Specific Boards category; Hi, Iím creating a windows notepad clone using C++, no MFC. Basically the application is just a window with a ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    Ask user to save changes

    Hi, Iím creating a windows notepad clone using C++, no MFC. Basically the application is just a window with a rich edit control. If the user wants to create a new document or exit the application I want to carry out a check to see if any changes have been made since the last save and alert the user. A global Variable (bool saved) will be set to true after a save was complete but I am having trouble finding a way to detect when a change has been made so I can set saved to false.

    I expect that there will be a message sent to the parent window if a change has been made but I have had no luck finding what it might be. If anybody could enlighten me of how this is carried out that would be great.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Numerous approaches possible.

    Sending an EM_GETMODIFY is easy if you are happy with messages. Probably the easiest.

    If the file you are editing are not very large, you could calculate a checksum when the file is loaded, then again when you want to test for changes, checksums are equal, no changes - just be careful with your checksumming algorithm. If it is really small, you could keep a memory copy before you load it into the box and directly compare it.

    Another way would be to sub-class the edit control so you can see what messages it is getting. If you see something like WM_CHAR or another that obviously changes the contents, then it is reasonable to assume there has been a change, so set the "changed flag" and then just pass the message unchanged on to your edit box.

    There are other ways depending upon many factors. Do either of these approaches sound good? They have the adavntage of being relatively simple.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    2
    Thank you the EM_GETMODIFY was exactly what I was looking for. My first thought was keeping a copy in memory and simply comparing it but I thought that with a large file it would be a waste of resources if I simpler method existed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help managing user input
    By JayDiddums10 in forum C Programming
    Replies: 2
    Last Post: 11-19-2006, 04:01 PM
  2. [C] Best way to save matrix counters
    By Nazgulled in forum C Programming
    Replies: 7
    Last Post: 03-24-2006, 04:02 PM
  3. save webpage? some save some not
    By kryptkat in forum Tech Board
    Replies: 3
    Last Post: 06-07-2005, 09:21 AM
  4. A bullet-proof fgets wrapper?
    By n7yap in forum C Programming
    Replies: 15
    Last Post: 12-16-2004, 04:19 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21