pickzy.com

C  |  C++  |  Objective-C  |  VC++  |  Win32  |  MFC  |  Java  |  Php  |  Delphi  |  Visual Basic  |  .Net  |  Networking  |  General  |  Games  |  Jobs  |  Javascript  |  




Menu

pickSourcecode.com


        

 




 

VCpp > Articles

 

VC++ - Line Drawing using Document / view Architecture

/*
The  view  class  should  access  this  data  and  draw  a  line  in  the  view  window.
Here  is  the  program  which  achieves  this..
*/


//    cline.h
struct cline 

{

CPo
int startpt ;
CPo
int endpt ;
} ;


//    myapp.h
class myapp : public CWinApp

{

private :


CRuntimeClass *d, *f, *v ;


public :


BOOL InitInstance( ) ;

} ;


//  myapp.cpp
#include <afxwin.h>
#include "cline.h"
#include "mydoc.h"
#include "myframe.h"
#include "myview.h"
#include "myapp.h"

#include "resource.h"

myapp a ;


BOOL myapp::InitInstance( )

{

d = RUNTIME_CLASS ( mydoc ) ;

f = RUNTIME_CLASS ( myframe ) ;

v = RUNTIME_CLASS ( myview ) ;


CSingleDocTemplate *t ;

t = new CSingleDocTemplate ( IDR_MAINFRAME, d,  f, v ) ; 


AddDocTemplate ( t ) ;

OnFileNew( ) ;


return TRUE ;



//  mydoc.h  

class mydoc : public CDocument

{

DECLARE_DYNCREATE ( mydoc )


private :


cline line ;


public :

 

mydoc( ) ;

cline getline( ) ;

} ;


//  mydoc.cpp
#include <afxwin.h>
#include "cline.h"
#include "mydoc.h"

IMPLEMENT_DYNCREATE ( mydoc, CDocument ) 


mydoc::mydoc( )

{

line.startpt.x = 10 ;

line.startpt.y = 10 ;


line.endpt.x = 100 ;

line.endpt.y = 100 ;

}


cline mydoc::getline( )

{

return line ;

}


//  myframe.h
class myframe : public CFrameWnd

{

DECLARE_DYNCREATE ( myframe )

} ;


//  myframe.cpp
#include <afxwin.h>
#include "myframe.h"

IMPLEMENT_DYNCREATE ( myframe, CFrameWnd ) 


//  myview.h
class myview : public CView

{

DECLARE_DYNCREATE ( myview )

 

public :


void OnDraw ( CDC *p ) ;
} ;


//  myview.cpp
#include <afxwin.h>
#include "cline.h"
#include "mydoc.h"
#include "myview.h"

IMPLEMENT_DYNCREATE ( myview, CView ) 


void myview::OnDraw ( CDC *p ) 

mydoc *doc = ( mydoc * ) GetDocument( ) ;


cline printline ;

printline = doc -> getline( ) ;


p -> MoveTo ( printline.startpt ) ;

p -> LineTo ( printline.endpt ) ;

}


Output:

 
Privacy Policy | About Us