A Framework for a Printing Application

Screen Shot

Environment: Visual C++ 5.0

This code demonstrates some of the things you will need to implement 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)

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: 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).
  4. 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

Downloads

Download Source: Textbmp.zip 37.5 KB

History



Comments

  • Great work

    Posted by Legacy on 02/06/2002 12:00am

    Originally posted by: ashutosh

    Great work done Jacob !
    

    I was trying this for some time and was getting problems....
    U made it very simple.....
    Thanx....

    With best wishes..

    Happy programming...
    ashutosh

    Reply
  • Excellent But What About .....

    Posted by Legacy on 01/14/2002 12:00am

    Originally posted by: Shah Khusro

    The work done is excellent. But these days I am working on the implementation of a Network Printing Management software and I need some help. I know that a large number of systems are available for this purpose but as a student assignment I have to implement the software and learn the concepts. Its capabilities should include:
    -> intercepting each print request
    -> examining the user, his rights and previllages
    -> assigning and checking page quota etc
    -> and based on this information making some decisions
    like allowing the print operation to complete.

    IF ANYBODY CAN HELP
    I WILL BE GREATFUL
    Thanks

    Reply
  • A problem with bitmap

    Posted by Legacy on 10/16/2001 12:00am

    Originally posted by: Anonymous

    This view supports simple drawing functions such as line, circle. When I put a bitmap into the DC ( in routine DrawHere), the picture appears in the view and preview, but does NOT the into the real printer. It seems to be a DC mode / reference frame problem.

    Reply
  • How to save the print information

    Posted by Legacy on 08/31/2001 12:00am

    Originally posted by: koundinya

    Hi,

    This is a good program .
    And I need some small code that saves the print information and later if we pass this information to the printer, it should able to print the information with out help of our application.

    I mean we have to implemet Print to file procedure.How can we implement that functionality


    Thanks
    Koundinya

    Reply
  • A small problem....

    Posted by Legacy on 02/08/2001 12:00am

    Originally posted by: Vasu

    First of all thanks to Jacob Boo for providing this wonderful sample. I used this code as a refernce for implementing my own zooming features. 
    
    

    But, I noticed one small problem in both my application and this sample application too.

    In the sample application, the text "This program demonstrate a simple printing program..." wraps around differently when the screen size is changed. For example: Set the zoom to "Fit Width" or "Fit Height" and keep resizing the window. The text wraps around differently for different sizes.

    The ZOOMing effect should not alter the output on the screen. Does anybody know why it is happening?

    In my application, I use GetTextExtent() function for calculating the string sizes. I found that the GetTextExtent() function returns differnt sizes(for the same string) when the window sizes are changed.

    Does anybody think that GetTextExtent() does not work properly with MM_ISOTROPIC mapmode.

    regards
    Vasu

    Reply
  • Wonderful ... but,

    Posted by Legacy on 10/05/2000 12:00am

    Originally posted by: Anonymous

    it'll be great if this can be integrated into a splitter view ... Anyone if ideas or sample solutions, kindly post them on this site :)

    Thanks!

    Reply
  • Printer's Escape

    Posted by Legacy on 04/14/2000 12:00am

    Originally posted by: QuangND

    Can U send me Escape string of LQ2080 to down load user font to printer.
    Thanks alot

    Reply
  • Great framework, what about multiple pages

    Posted by Legacy on 04/11/2000 12:00am

    Originally posted by: Allan Petersen

    This is a great framework for single page printing applications. What about a framework for a multiple page printing application?

    Reply
  • Good...but

    Posted by Legacy on 10/07/1999 12:00am

    Originally posted by: TLC

    Quite a pontential program! Can be extend to do lot more...However, the source code was really messy...

    Reply
  • VC 6.0 fix

    Posted by Legacy on 07/29/1999 12:00am

    Originally posted by: Joe Ismert

    I have never worked with these control bars before, but here is a fix in VC6.0. It seems that they have added an extra assert here to make sure that you have set m_dwStyle correctly. With this in mind the changes are minor but needed. In mainfrm.cpp replace the CreateRulerBar function with:
    
    

    BOOL CMainFrame::CreateRulerBar()
    {

    if (!m_wndRulerBarH.Create(this,
    CBRS_TOP|CBRS_HIDE_INPLACE, ID_VIEW_RULERH))
    {
    TRACE0("Failed to create ruler\n");
    return FALSE; // fail to create
    }

    if (!m_wndRulerBarV.Create(this,
    CBRS_LEFT|CBRS_HIDE_INPLACE, ID_VIEW_RULERV))
    {
    TRACE0("Failed to create ruler\n");
    return FALSE; // fail to create
    }

    return TRUE;

    }

    In each of the ruler.cpp and rulerv.cpp change the create function to the following:

    BOOL CRulerBar::Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID)
    {
    ASSERT_VALID(pParentWnd); // must have a parent

    //dwStyle |= WS_CLIPSIBLINGS;
    // force WS_CLIPSIBLINGS (avoids SetWindowPos bugs)
    m_dwStyle = dwStyle;
    dwStyle |= WS_CLIPSIBLINGS|WS_CHILD|WS_VISIBLE;
    // create the HWND
    CRect rect;
    rect.SetRectEmpty();
    LPCTSTR lpszClass = AfxRegisterWndClass(0, ::LoadCursor(NULL, IDC_ARROW),
    (HBRUSH)(COLOR_BTNFACE+1), NULL);

    if (!CWnd::Create(lpszClass, NULL, dwStyle, rect, pParentWnd, nID, NULL))
    return FALSE;
    // NOTE: Parent must resize itself for control bar to be resized

    return TRUE;
    }

    that is all!

    Joe

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds