Click here to Skip to main content
15,921,371 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to get icons of all opened windows? Pin
dabs31-Oct-02 13:03
dabs31-Oct-02 13:03 
GeneralSaving with MFC Pin
dinner@628-Oct-02 11:30
dinner@628-Oct-02 11:30 
GeneralRe: Saving with MFC Pin
Christian Graus28-Oct-02 11:34
protectorChristian Graus28-Oct-02 11:34 
GeneralRe: Saving with MFC Pin
valikac28-Oct-02 11:37
valikac28-Oct-02 11:37 
GeneralRe: Saving with MFC Pin
dinner@628-Oct-02 11:59
dinner@628-Oct-02 11:59 
GeneralRe: Saving with MFC Pin
valikac28-Oct-02 12:12
valikac28-Oct-02 12:12 
GeneralRe: Saving with MFC Pin
Christian Graus28-Oct-02 13:25
protectorChristian Graus28-Oct-02 13:25 
GeneralRe: Saving with MFC Pin
ian mariano28-Oct-02 17:38
ian mariano28-Oct-02 17:38 
You're basically overriding the overall Document/View architecture in MFC if you write your own archiving streams. CArchive is an already opened archive stream, wired up by MFC, CDocument and CFileDialog (to get the file name to save to.) All you have to do in Serialize is use the C++ insertion/extraction operators to get data into and out of the file:

void CMy_newDoc::Serialize(CArchive& ar)
{
  //  buffer is assumed to be a CString
  if (ar.IsStoring())
  {
    //  write to stream
    ar << buffer;
  }
  else
  {
    //  read from stream
    ar >> buffer;
  }
}


If your data is stored in a class, you can derive it from CObject, and override the Serialize method to store class-specific data. That way you can use the C++ insertion/extraction operators on an object instance:

//  myobject.h  example class to store a couple numbers and a string
class CMyObject : public CObject
{
protected:  // data
  int  m_nOne;
  float  m_fTwo;
  CString  m_strData;

public:
  CMyObject() : m_nOne(0), m_fTwo(0.0)  {  }

  int      GetOne(void) const  {  return m_nOne;  }
  void     SetOne(int n)  {  m_nOne = n;  }
  float    GetTwo(void) const  {  return m_fTwo;  }
  void     SetTwo(float f)  {  m_fTwo = f;  }
  LPCTSTR  GetData(void) const  {  return m_strData;  }
  void     SetData(LPCTSTR s)  {  m_strData = s;  }

  DECLARE_SERIAL(CMyObject)

  virtual void Serialize(CArchive& ar)
  {
    if (ar.IsStoring())
    {
      ar << m_nOne << m_fTwo << m_strData;
    }
    else
    {
      ar >> m_nOne >> m_fTwo >> m_strData;
    }
  }
};  //  class CMyObject

//  myobject.cpp
IMPLEMENT_SERIAL(CMyObject, CObject, VERSIONABLE_SCHEMA | 1)

//  my_newDoc.cpp
void CMy_newDoc::Serialize(CArchive& ar)
{
  //  m_oMyObj is a class member instance of CMyObject
  if (ar.IsStoring())
  {
    //  write to stream
    ar << m_oMyObj;
  }
  else
  {
    //  read from stream
    ar >> m_oMyObj;
  }
}


There you go. CDocument's OnSaveDocument() and OnOpenDocument() (which you don't have to mess with) end up calling CDocument's base class CObject::Serialize. CObject reference[^] Here's an MFC Object Serialization referance[^]

-- ian



http://www.ian-space.com/
GeneralCImage -- Can't get it working Pin
nde_plume28-Oct-02 11:26
nde_plume28-Oct-02 11:26 
GeneralRe: CImage -- Can't get it working Pin
Christian Graus28-Oct-02 11:31
protectorChristian Graus28-Oct-02 11:31 
GeneralStrange Problem. Pin
Anonymous28-Oct-02 10:25
Anonymous28-Oct-02 10:25 
GeneralRe: Strange Problem. Pin
Maximilien28-Oct-02 10:35
Maximilien28-Oct-02 10:35 
GeneralRe: Strange Problem. Pin
Anonymous28-Oct-02 11:08
Anonymous28-Oct-02 11:08 
GeneralQuestion concerning bitmaps Pin
Steven M Hunt28-Oct-02 10:22
Steven M Hunt28-Oct-02 10:22 
GeneralRe: Question concerning bitmaps Pin
Christian Graus28-Oct-02 10:29
protectorChristian Graus28-Oct-02 10:29 
GeneralMFC/Win32 MicroPhone Mute Pin
Moshe Bergman28-Oct-02 10:01
sussMoshe Bergman28-Oct-02 10:01 
GeneralRe: MFC/Win32 MicroPhone Mute Pin
ian mariano28-Oct-02 17:43
ian mariano28-Oct-02 17:43 
GeneralSending Keyboard Events to a Window Pin
Abin28-Oct-02 9:31
Abin28-Oct-02 9:31 
GeneralRe: Sending Keyboard Events to a Window Pin
Christian Graus28-Oct-02 10:17
protectorChristian Graus28-Oct-02 10:17 
GeneralThank you, and gimme more... Pin
Abin28-Oct-02 15:43
Abin28-Oct-02 15:43 
GeneralRe: Thank you, and gimme more... Pin
Christian Graus28-Oct-02 16:49
protectorChristian Graus28-Oct-02 16:49 
GeneralRe: Thank you, and gimme more... Pin
Abin29-Oct-02 11:07
Abin29-Oct-02 11:07 
GeneralMCI control Pin
devvvy28-Oct-02 9:18
devvvy28-Oct-02 9:18 
GeneralGrid Printing Pin
Anthony988728-Oct-02 9:05
Anthony988728-Oct-02 9:05 
GeneralMFC hinstances Pin
will138328-Oct-02 8:25
will138328-Oct-02 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.