Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How To Serailize collection class object

How To Serailize collection class object

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpwpfgraphicsdebugging
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adityarao31
    wrote on last edited by
    #1

    I have simple CLine class which has two member variables which store first and last point of line.I store set of drawn lines in CObArray .Now I want to save the set of lines which I have drawn on CView on save button. And Get All lines back on open button click. Means serialize and deserialize in and out of CObArray Collection class. I have tried as shown in code. but I get no values where I have mentioned in code.Thus enable to retrieve the saved drawing. Can any one help me on this issue? // Serialization3View.cpp : implementation of the CSerialization3View class // #include "stdafx.h" #include "Serialization3.h" #include "Serialization3Doc.h" #include "Serialization3View.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSerialization3View IMPLEMENT_DYNCREATE(CSerialization3View, CView) BEGIN_MESSAGE_MAP(CSerialization3View, CView) //{{AFX_MSG_MAP(CSerialization3View) ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_MOUSEMOVE() ON_COMMAND(ID_FILE_SAVE, OnFileSave) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSerialization3View construction/destruction CSerialization3View::CSerialization3View() { // TODO: add construction code here } CSerialization3View::~CSerialization3View() { } BOOL CSerialization3View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CSerialization3View drawing void CSerialization3View::OnDraw(CDC* pDC) { CSerialization3Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); int liCount = pDoc->GetLineCount(); if(liCount > 1) { int lipos; CLine* l; for(lipos = 0;lipos < liCount;lipos++) { l = pDoc->GetLine(lipos); l->Draw(pDC); } } // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CSerialization3View printing BOOL

    E 1 Reply Last reply
    0
    • A adityarao31

      I have simple CLine class which has two member variables which store first and last point of line.I store set of drawn lines in CObArray .Now I want to save the set of lines which I have drawn on CView on save button. And Get All lines back on open button click. Means serialize and deserialize in and out of CObArray Collection class. I have tried as shown in code. but I get no values where I have mentioned in code.Thus enable to retrieve the saved drawing. Can any one help me on this issue? // Serialization3View.cpp : implementation of the CSerialization3View class // #include "stdafx.h" #include "Serialization3.h" #include "Serialization3Doc.h" #include "Serialization3View.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSerialization3View IMPLEMENT_DYNCREATE(CSerialization3View, CView) BEGIN_MESSAGE_MAP(CSerialization3View, CView) //{{AFX_MSG_MAP(CSerialization3View) ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_MOUSEMOVE() ON_COMMAND(ID_FILE_SAVE, OnFileSave) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSerialization3View construction/destruction CSerialization3View::CSerialization3View() { // TODO: add construction code here } CSerialization3View::~CSerialization3View() { } BOOL CSerialization3View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CSerialization3View drawing void CSerialization3View::OnDraw(CDC* pDC) { CSerialization3Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); int liCount = pDoc->GetLineCount(); if(liCount > 1) { int lipos; CLine* l; for(lipos = 0;lipos < liCount;lipos++) { l = pDoc->GetLine(lipos); l->Draw(pDC); } } // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CSerialization3View printing BOOL

      E Offline
      E Offline
      Eugen Podsypalnikov
      wrote on last edited by
      #2

      Just prepare an instance of CArchive and call CObArray::Seraialize(CArchive&) :)

      Check your definition of Irrationality[^] :) 1 - Avicenna 5 - Hubbard 3 - Own definition

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups