Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CProgrammer

Simple MFC question(or is it?)

This topic is 5396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a CDocument derived class. All the saving and loading code is setup. How can I make my MFC app call the Load part of Serialize if someone opens the app with a file. Like in Dos myapp.exe myfile Oh and the loading procedure should be called after the window was created. Is that doable. -CProgrammer

Share this post


Link to post
Share on other sites
Advertisement
Perhaps you should read up in Serialization seeing as how your questions just made my head hurt.

Serialization requires a few changes in ur code, it doesn''t just miraculously work. Possibley re-phrase ur q for a better answer.

"Arguing on the Internet is like winning in the Special Olympics, in the end, you''''re still retarded"

Share this post


Link to post
Share on other sites
Alright i''ll rephrase the question:
When opening my MFC-app with a file it calls the serialize function before creating the window. How can I change this, elegantly, so that the project is loaded after the window is initialized.
Reason: The Serialize function initializes data that needs a handle to the window.
Hope this helps, any replys are greatly appreciated.
-CProgrammer

Share this post


Link to post
Share on other sites
If i understand correctly ---

If your new window has its own class (which it should) you have to overwrite Serialize() in that class.

However, if you did that and I just can''t read, serialization is cool and all but you could just overwrite file open and use FStreams. I''m not sure exactly WHAT you''re trying to accomplish still, but i hope this helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
create a hidden window?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
and then post a user-defined window message to do psuedo-window initialization, before SW_SHOW.

Share this post


Link to post
Share on other sites
quote:
Original post by CProgrammer
Reason: The Serialize function initializes data that needs a handle to the window.
-CProgrammer


That violates the Document-View architecture. You should move the code that needs access to the view''s window handle to your view-derived class and set those data elements there (like in the OnUpdate method).

Share this post


Link to post
Share on other sites
According to all the post the following idea seems feasable:
I use a boolean in the CDocument derived class to save wether the programm was opened with a file. In OnUpdate or so in CView I then chack that value and load. I could use fstream for that, but isnt there a command like ''Load(char *file)'' to recall the Serizlize function and tell it to load the file?
-CProgrammer

Share this post


Link to post
Share on other sites
Any class derived from CObject has the Serialize() function which you can call anywhere in your code. It takes in a CArchive&, which you will have to set up. First, using the filename you have, you need to create an instance of a CFile. Then, using that CFile, you need to create a CArchive, with the nMode flag set to CArchive::load. You can dig through the MSDN library for the exact function prototypes and stuff, it shouldn''t be too hard to find. Hope this helps!

Share this post


Link to post
Share on other sites
I can call Serialize in the CView derived class. I didnt know that thanks.
I do however still have one problem. Since the file to load is stored in the CDocument derived class I still need to access that class. I tried static variable, but it wont work, since CView accesses static members of CDocument and the other way around.

-CProgrammer

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!