MFC -> Non MFC File Handling

Started by
4 comments, last by necreia 20 years, 6 months ago
Hello, I''m working on a Level editor now for my game, however having some trouble. The main project uses normal C++ and DirectX, whereas the level editor was built in MFC. The issue I am having is I want to save the levels (in MFC level editor) in a format that I can extract and levels in the normal C++ application. Before it wasn''t an issue because my first level editor was based in core C++ and I was using iostream. But I really like the MFC built-in Save/Open windows and would like to ''avoid'' creating those dialog''s myself just so I can use iostream on the file string instead of ar. When I save a Serialization in MFC it won''t yank out properly in iostream (within the game, and I wouldn''t expect it to work). So when I get down to it here is the question for anyone who has had this problem. Can I : 1) Just get the file string returned from the MFC Open/Save built-in Dialog boxes or 2) Override the virutal ::Serialize(CArchive& ar) and replace it with an iostream port or 3) plug-in just the ::Serialize(CArchive& ar) portion of MFC into a non-MFC project. or 4) Am I overlooking a very simple work-around and I''m going straight the wrong way? For example purposes I''ll use a 2D map class I wish to save-retrieve, this isn''t even close to what I''m using but it can help with examples struct MAP_TILE { short int MapFileX; short int MapFileY; short int Show; }; struct MAP_FILE { short int PlayerStartX; short int PlayerStartY; MAP_TILE BackTile[128][128]; }; class CMapFile { CMapFile(); ~CMapFile(); public: MAP_FILE m_Map; }; Since I have a lot of my map file broken into small structures that plug into structures and into classes, best if I demostrate it that way.. any help?
Advertisement
I've not used MFC much, but if I understand correctly, your problem is just that you want the file open / save dialogs without having to create them yourself?? If that's the case, try taking a look at the "CreateFile()" function and the related File IO functions included in the platform SDK.

Edit: Sorry, I'm talking rubbish. The actual functions you're interested in are "GetOpenFileName()" and "GetSaveFileName()". Stay off the drugs, Hinchy-boy!

[edited by - hinch on October 14, 2003 12:10:13 PM]
Just override OnSaveDocument. There you have the path the user wants to save, and don''t call the base class, so it won''t call serialize. The same for OnLoadDocument. Voila! just put your code serialization there.

Good Luck!
Daniel.
Hahahaha, man I knew it was something as easy as that but I just wasn''t seeing it. Thanks a ton I''ll give it a shot now, I tried looking for what functions to override in MSDN but you know how finding information there can be..
Having a problem finding where to override those functions, any tips? I hate MSDN library.
Nevermind, found it, was a subclass of Document::. thanks for the prompt help guys! Alright time to get back to work.

This topic is closed to new replies.

Advertisement