Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / MFC

A Single Page Printing Framework

Rate me:
Please Sign up or sign in to vote.
3.82/5 (8 votes)
1 Feb 2000 115.4K   2K   31   16
A Single Page Printing Framework

Sample Image - singlepage.jpg

Introduction

This program provides a framework for a single page printing program. Its features include:

  1. A WYSIWYG interface with Zooming capability: from 75% to 150% , with FitWidth and FitHeight mode
  2. Allowing user to set margins using the Page Setup Dialog
  3. Using double buffers to reduce flickering
  4. Automatically updating the page size when it is changed by the user using the Print Setup Dialog
  5. Rulers with markings that will change according to the scale and position of the paper
  6. Scrolling of Text

To suit your drawing needs, edit the DrawHere method in the TextBmpView.cpp file. This function will pass 3 arguments to you:

  1. PaperRect: The paper rectangle in logical coordinates.
  2. PrintableRect: The region where your printer will print (this is slightly smaller than the paper rect).
  3. MarginsRect: The margin rectangle in logical coordinates. (This area is defined by the user, and you might choose to ignore it.)
C++
void CTextbmpView::DrawHere(CDC* pDC,CRect PaperRect, 
                            CRect PrintableRect,CRect MarginsRect) 
{ 
	/////////////////////////////////////////  
	//ADD Drawing code here!!!                 
}  

These 3 arguments will vary according to the paper size currently selected, but will not vary with respect to the current zoom mode. Your code will have to draw according to these dimensions, within the rectangular area given. You can use the MFC drawing functions like DrawText, LineTo, CreateFont etc. to create your drawing.

Units

  1. The units are in twips (1 inch = 1440 twips), so to draw a 1 inch line, do the following:
    C++
    pDC->MoveTo(0,-2000); pDC->LineTo(1440,-2000);
  2. The y-values of most points are negative. The lower the point, the smaller/more negative is the y-value.
  3. The origin (0,0) is located at the top-left of the dotted rectangle (printable area). Typical values for the PrintableRect of an A4 sized paper is top = 0, left = 0, right = 11568, bottom = -15876.

The Display

  1. The printable area is represented by the dotted rectangle.
  2. The paper rectangle is indicated by the white area in gray background.
  3. The margins are shown as the gray regions on the ruler.
  4. To convert a point clicked on the screen into a logical point on the paper, use the ScreenToPaper method. For an example, look at the CTextBmpView::OnLButtonDown method. There is another method PaperToScreen which will convert a point on the paper to a point on the screen.

Limitations

This program may not work with large paper size: e.g. A3 sized paper

Credits:

Special thanks goes to Joe Ismert for providing the VC6.0 fix for the RulerBar.

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found here.


Written By
Singapore Singapore
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow about doing a .NET C Sharp version of this Pin
RichardTrainer7-Jul-08 6:15
RichardTrainer7-Jul-08 6:15 
Generalcount printing pages Pin
ThangaDharma6-Oct-05 7:54
ThangaDharma6-Oct-05 7:54 
Generalzooming Pin
sreejith ss nair28-Apr-05 20:29
sreejith ss nair28-Apr-05 20:29 
GeneralCentering Pin
dejavusoft9-Jan-05 23:14
dejavusoft9-Jan-05 23:14 
GeneralPRB: wrong drawing on 1280x1024 display resolution Pin
Valentin Mocanu13-Oct-04 9:51
Valentin Mocanu13-Oct-04 9:51 
QuestionHow to select Landscape button as a default in PageSetupDialog Pin
pubududilena12-Jul-04 1:56
pubududilena12-Jul-04 1:56 
QuestionHow to migrate this solution to multipage project? Pin
robinswan26-Jul-03 8:30
robinswan26-Jul-03 8:30 
this is a cool framework!
but what should i do for multiView project with this framework?
GeneralLeters on the head when printing Pin
Andreas Glaubitz13-Jun-03 2:12
Andreas Glaubitz13-Jun-03 2:12 
Generalzoom/print preview Pin
Member 24167529-Apr-03 4:57
Member 24167529-Apr-03 4:57 
QuestionHow do you prevent font size change? Pin
Miguel Lopes18-Nov-02 12:56
Miguel Lopes18-Nov-02 12:56 
GeneralThanks Pin
supertedusa22-Jun-02 12:18
supertedusa22-Jun-02 12:18 
GeneralUpdated Version for Bitmap Printing Pin
James Archer16-Oct-01 18:06
James Archer16-Oct-01 18:06 
Generalthe region of thecutting down of page Pin
25-Sep-01 22:22
suss25-Sep-01 22:22 
Generalthe region of thecutting down of page Pin
25-Sep-01 22:20
suss25-Sep-01 22:20 
Generalwith splitter ?!! Pin
Anonymous4-Oct-00 22:33
Anonymous4-Oct-00 22:33 
Generalcool Pin
Member 185813-Aug-00 13:43
Member 185813-Aug-00 13:43 

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.