I have created a few applications in MFC.
But I want to start saving the contents of them to files(just like word,guitar pro or paint).
I tried serialization provided by MFC but I didn't like it that much because I couldn't check anything that was saved at all.
So,I wrote my own xml saving class,using which I can both read an write.

Now,where do I put the saving code and the loading code in my project?
(Like,How do I know when a file(created by my application) is opened?)
How do you do the saving part of an application in MFC(tell me where you put the code)?


Please help me out.

Depends. Does your application have a File-->Save and File-->Open menus? Then put that code in the event handlers for those two functions.

Otherwise you could put the read code in OnNewDocument() and the save code when the application exists.

Thank You.
I am clear with what you said.So,I put code in Event handlers like you said.

Lets say I create a file with my application,using File->Save,and

1.then I do File->Open and open the saved file.Then it will load.

On the other hand,
2. I open the file by double-clicking it.
Then the File->Open Event handler code won't be called,so it will load nothing at all!
So what do you think I should do about this?

open is used by programs such as word which is multiple documents and what you are describing would require the intialisation method that could call open()

I think it is normally onInit() but you need to be confident that your design of saving the files this way is the right choice for your application

The class wizard places:

//TODO add your own intialisation here

method to be used and you would also need to associate your file extension to open with your .exe in you OS , I guess this must be windows as you are using the MFC

open is used by programs such as word which is multiple documents and what you are describing would require the intialisation method that could call open()

I think it is normally onInit() but you need to be confident that your design of saving the files this way is the right choice for your application

The class wizard places:

//TODO add your own intialisation here

method to be used and you would also need to associate your file extension to open with your .exe in you OS , I guess this must be windows as you are using the MFC

Thank You tetron.
But please be more clear with 'OnInIt()'I could not find it anywhere to override.
Can you tell me in which class I have override it?
You also spoke of this being the right choice or not,and so what other choices do I have?
I am new to this,so please help me out.

Sorry, I 'm tired today should have been InitInstance

Thank You tetron.
But please be more clear with 'OnInIt()'I could not find it anywhere to override.
Can you tell me in which class I have override it?
You also spoke of this being the right choice or not,and so what other choices do I have?
I am new to this,so please help me out.

This article has been dead for over six months. Start a new discussion instead.