Download source files - 39 Kb
<!-- Article Starts -->
This program provides a framework for a single page printing program. Its features include
- a WYSIWYG interface with Zooming capability: from 75% to 150% , with FitWidth and FitHeight mode
- Allowing user to set margins using the Page Setup Dialog
- Using double buffers to reduce flickering
- Automatically updating the page size when it is changed by the user using the Print Setup Dialog
- Rulers with markings that will change according to the scale and position of the paper
- 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:
- PaperRect : The paper rectangle in logical coordinates.
- PrintableRect : The region where your printer will print (This is slightly smaller than the paper rect).
- MarginsRect : The margin rectangle in logical coordinates. (This area is defined by the user, and you might choose to ignore it)
void CTextbmpView::DrawHere(CDC* pDC,CRect PaperRect,
CRect PrintableRect,CRect MarginsRect)
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
to create your drawing.
- The units are in twips (1 inch = 1440 twips), so to draw a 1 inch line, do the following:
- The y-values of most points are negative. The lower the point, the smaller/more negative is the y-value.
- 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 printable area is represented by the dotted rectangle.
- The paper rectangle is indicated by the white area in gray background.
- The margins are shown as the gray regions on the ruler.
- 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.
This program may not work with large paper size: e.g. A3 sized paper
Special thanks goes to Joe Ismert for providing the VC6.0 fix for the RulerBar.