serialize rich edit control problem

This is a discussion on serialize rich edit control problem within the Windows Programming forums, part of the Platform Specific Boards category; Okay, so i started a project with a rich edit view, richedit doc and such.. but I also create another ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    55

    serialize rich edit control problem

    Okay,

    so i started a project with a rich edit view, richedit doc and such..

    but I also create another Cricheditctrl object in this program. I'm trying to serialize it in Document class serialize function.

    is this even okay to do?


    Code:
    void CProject5Doc::Serialize(CArchive& ar)
    {
    	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
    	CFile *file = ar.GetFile();
      CString cname=file->GetFilePath();
      // I like seeing the full pathname as a title.
     
      SetTitle(cname); 
      if (cname.Right(4) == ".rtf")
      {
        // No change for rtf files
        //CRichEditDoc::Serialize(ar);
    	  pMainWnd->m_edit.Serialize(ar);
      }
      else
      {
        // Treat as flat text files
        CString cstr;
        // CRichEditDoc will only work with one CRichEditView 
        // class. 
        CView *pView = GetView();
        // GetView is equavalent to:
        // POSITION pos;
        //pos = GetFirstViewPosition();
        //CView *pView= GetNextView(pos);
        
        if (ar.IsStoring())
        {	
            // GetWindowText will grab all of the displayed text (no formatting)
            pView->GetWindowText(cstr);
            // Should probably have try ... catch logic
            file->Write(cstr, cstr.GetLength());
        }
        else
        {
            int nSize = file->GetLength();
            char *pBuff = new char[nSize+1];
            if (pBuff != NULL)
            {
               // The following should probably have TRY ... Catch logic
               file->Read(pBuff, nSize);
               pBuff[nSize] = 0;
               cstr = pBuff;
               // The following will update the display text on the screen
               //  again formatting is missing. 
               pView->SetWindowText(cstr);
               delete pBuff;
            }
        }
      }
    
    	//
    
    	/*
    	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
    	
    	if (ar.IsStoring())
    	{
    		pMainWnd->m_edit.Serialize(ar);
    		// TODO: add storing code here
    	}
    	else
    	{
    		// TODO: add loading code here
    	}
    
    	// Calling the base class CRichEditDoc enables serialization
    	//  of the container document's COleClientItem objects.
    	// TODO: set CRichEditDoc::m_bRTF = FALSE if you are serializing as text
    	CRichEditDoc::Serialize(ar);*/
    }
    as i said..

    pMainWnd->m_edit.Serialize(ar); the m_edit is a Cricheditctrl objct.

    what i have above is not working.. and i'm not sure why it's not.

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    55
    Actually.. m_edit is a CtermEdit object. which is derived from a Cricheditctrl..

    but.. the CtermEdit does not have any additional variables or anything. it just has a member function.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    55
    it seems like it's writting blanks to it.. cuase it actually writes over any that is in the file.. bleh..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 12:56 PM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  3. Dialog Edit Control and Enter Key
    By Quantrizi in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2004, 08:59 AM
  4. newbie to rich edit, cant get it to work
    By hanhao in forum Windows Programming
    Replies: 1
    Last Post: 03-24-2004, 10:54 PM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 03:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21