Using the serialization mechanism in the document view structure Using the OLE clipboard

zhaozj2021-02-08  276

Using the serialization mechanism in the document view structure Using the OLE clipboard

FMD (http://www.fmdstudio.net)

Using the serialization mechanism in the document view structure Using the OLE clipboard

First, serialization support

From the COBJECT derived object to add a serialized support by adding a specific macro statement in class declarations and implementation

DECLARE_SERIAL (CsomeObject)

Implement_serial (csomeObject, csomebase, 1)

Rebate the SERIALIZE member function, writing object's storage and reading procedure.

OLE copy of the two objects

// Establish a memory file

CsharedFile File;

// Establish a document object for writing

CARCHIVE AR (& File, Carchive :: Store);

// For Ar, serialization functions for objects

Somobjects.Serialize (ar);

ar.close ();

COLEDATASOURCE * PDATASOURCE = NULL;

Try

{

// Establish an OLE data source

PDataSource = New ColedataSource;

/ / Specify the memory file to the data source

PDataSource-> CacheglobalData (m_cfdraw, file.detach ());

// Setting a clipboard

PDataSource-> setClipboard ();

}

Catch_all (e)

{

DELETE PDATASOURCE;

Throw_last ();

}

END_CATCH_ALL

Third, the OLE paste

// Establish an OLE data object

COLEDATAOBJECT DATAOBJECT;

/ / Connect the clipboard

DataObject.attachClipboard ();

IF (DataObject.isdataavailable / / Determine if the specified format exists

{

// Get memory file pointer

Cfile * pfile = DataObject.getfileData (m_cfdraw);

IF (pfile! = null)

{

// Establish a document object for reading

CARCHIVE AR (Pfile, Carchive :: Load);

Try

{

// For Ar, call the serialization function of the object.

Graphylist.serialize (ar);

}

Catch_all (e)

{

ar.close ();

DELETE PFILE;

Throw_last ();

}

END_CATCH_ALL

ar.close ();

DELETE PFILE;

}

}

Fourth, about format

When using the OLE clipboard, you need to register your own format.

Declare and define a static structure in a suitable place (following the document CGRAPHDRAWDOC)

Static ClipFormat M_cfdraw;

Clipformat cgraphdrawdoc :: m_cfdraw = NULL;

/ / Registration format when program initialization

CgraphdrawDoc :: m_cfdraw = (clipformat) RegisterClipboardFormat (_T ("fMD graphdraw"));

转载请注明原文地址:https://www.9cbs.com/read-3128.html

New Post(0)