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