Thread: Question about document/view app in MFC

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    72

    Question about document/view app in MFC

    Hello,
    I have a real general question, but can post specific code if it helps illustrate my question. When I create a document/view app with the app wizard in VC++ 6.0, it automatically sets up the visual aspect of the File - Open, File -Save, etc options.
    I am trying to write an app that will load a simple text (ASCII) document in the window. To do this, I know that I have to add code to the Serialize function. What I do is something similar to the following:

    Code:
    void CTestDoc::Serialize(CArchive& ar)
    {
    	if (ar.IsStoring())
    	{
    		ar << mStr ;
    		// TODO: add storing code here
    	}
    	else
    	{
    		ar >> mStr;
    		// TODO: add loading code here
    	}
    }
    In the above example, mStr is a CString. When I do this and compile it and attempt to open an ASCII file, I only see the first line of the file and it seems to cut off the first letter of the line as well. I figure it has something to do with putting the value of ar into a CString rather than a better storage container, but I am not sure which storage container to use. Should I be usiing a character array or something? I think that once I know which storage container works best for my needs, it'll work just fine.

    Any nudges in the right direction would be great!
    Thanks as always!

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Serialization is one feature in Doc/View architecture. However, you are not locked on it. You can implement C++'s ifstream if you wanted to.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    72
    Thanks for the response. If I opted to try and do this with serialization, is there a way to load a multiline ASCII document into an MFC app? Honestly, I've never really used ifstream previously, so I suspect that might be more involved...

    I just wonder if there's a way to store the value of the ar (CArchive object) into something bigger than a CString (like an array or linked list or other data structure).

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC check box question
    By MyglyMP2 in forum Windows Programming
    Replies: 2
    Last Post: 03-09-2009, 05:47 PM
  2. MFC Dialog App Screen Refresh Question
    By Scotth10 in forum Windows Programming
    Replies: 2
    Last Post: 10-18-2002, 02:07 PM
  3. GUI App Question ??
    By aumfc in forum Windows Programming
    Replies: 9
    Last Post: 10-17-2002, 02:56 AM
  4. VS.net mfc dialog app
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 05-15-2002, 05:23 PM
  5. MFC Document/View - New Milestone :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 03:14 PM