VC++ - Line Drawing, Shapes and saving, using Document / view Architecture
Share
/*
The cline Class
Our program stores the information about the lines thar are drawn in an array of cline objects. The cline
class is publicly derived from CObject. This makes it easy for us to add serialization support to the cline
class. so that the entire drawing can be saved or restored with just a few lines of code.
*/
// cline.h
class cline : public CObject
{
DECLARE_SERIAL ( cline )
private :
CPoint startpt ;
CPoint endpt ;
public :
cline( ) ;
cline ( CPoint from, CPoint to ) ;
void Serialize ( CArchive &ar ) ;
void draw ( CDC *p ) ;
} ;
// cline.cpp
#include <afxwin.h>
#include "cline.h"
IMPLEMENT_SERIAL ( cline, CObject, 1 )
cline::cline( )
{
}
cline::cline ( CPoint from, CPoint to )
{
startpt = from ;
endpt = to ;
}
void cline::Serialize ( CArchive &ar )
{
CObject::Serialize ( ar ) ;
if ( ar.IsStoring( ) )
ar << startpt << endpt ;
else
ar >> startpt >> endpt ;
}
void cline::draw ( CDC *p )
{
p -> MoveTo ( startpt ) ;
p -> LineTo ( endpt ) ;
}
// Output
Comments:
|
Submitted By:
Prof: Software Engineer
Tech: C ,Cpp
|