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

 

vcpp - A simple printing Application


In this application we would draw a circle and a rectangle, display
some text and then try to pr
int it on the printer. We would also
provide support 
for print previewing and print setup. The 'File' menu 
would contain items like 'Print','Pr
int preview' and 'Print Setup'. On selecting 
the 'Print' menu item a 'Print' dialog box would popup. In this dialog the user can
specify printing options like printer type, starting and ending page numbers and the 
number of copies.

Selecting 'Pr
int Preview' option would put the application in the print preview mode such that
the user can see exactly how the printed output would look like be
fore it is sent to the printer.

//  Myapp.h
class myapp : public CWinApp

{

private :


CRuntimeClass *d, *f, *v ;


public :


BOOL InitInstance( ) ;


DECLARE_MESSAGE_MAP( )

} ;


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

#include "resource.h"

myapp a ;


BEGIN_MESSAGE_MAP ( myapp, CWinApp )

ON_COMMAND ( ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup ) 

END_MESSAGE_MAP( )


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 ) ;


CCommandLineInfo str ;

ParseCommandLine ( str ) ;


if ( !ProcessShellCommand ( str ) )
return FALSE ;


return TRUE ;



//  mydoc.h
class mydoc : public CDocument

{

DECLARE_DYNCREATE ( mydoc )

} ;


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

IMPLEMENT_DYNCREATE ( mydoc, CDocument ) 


//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 CScrollView

{

DECLARE_DYNCREATE ( myview )


public :


virtual 
void OnInitialUpdate( ) ;
void OnDraw ( CDC *p ) ;
virtual BOOL OnPreparePrinting ( CPrintInfo *p ) ;

void OnPrepareDC ( CDC *p, CPrintInfo *info ) ;

DECLARE_MESSAGE_MAP( )

} ;


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

IMPLEMENT_DYNCREATE ( myview, CScrollView ) 


BEGIN_MESSAGE_MAP ( myview, CScrollView )


ON_COMMAND ( ID_FILE_PRINT, CScrollView::OnFilePr
int
ON_COMMAND ( ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview ) 


END_MESSAGE_MAP( )


void myview::OnInitialUpdate( ) 
{

CScrollView::OnInitialUpdate( ) ;

SetScrollSizes ( MM_LOENGLISH, CSize ( 827, 1169 ) ) ;

}


void myview::OnDraw ( CDC *p ) 

CPen mypen ;

CBrush mybrush ;

CFont myfont ;


mypen.CreatePen ( PS_SOLID, 3, RGB ( 0, 0, 255 ) ) ;

mybrush.CreateSolidBrush ( RGB ( 255, 0, 0 ) ) ;

myfont.CreatePointFont ( 300, "Arial", p ) ;


CPen* prevpen = p -> SelectObject ( &mypen ) ;

CBrush* prevbrush = p -> SelectObject ( &mybrush ) ;

CFont* prevfont = p -> SelectObject ( &myfont ) ;


p -> Ellipse ( 100, -10, 300, -200 ) ;

p -> Rectangle ( 300, -300, 500, -500 ) ;

p -> TextOut ( 100, -600, "Hello", 5 ) ;


p -> SelectObject ( prevpen ) ;

p -> SelectObject ( prevbrush ) ;

p -> SelectObject ( prevfont ) ;

}


BOOL myview::OnPreparePrinting ( CPrintInfo *info )

{

info -> SetMaxPage ( 1 ) ;

return DoPreparePrinting ( info ) ;

}


void myview::OnPrepareDC ( CDC *p, CPrintInfo *info )
{

CScrollView::OnPrepareDC ( p, info ) ;

if ( p -> IsPrinting( ) )
{

int n = info -> m_nCurPage ;
}

}


//  Output

 
Privacy Policy | About Us