YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
XD++ Library
DocVizor
TFC Library
Free Products
Technical Support
UCanCode.net


Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


MFC Topics: Printing and Print Preview Fundamentals

 
 

Fundamentals of Printing

 
 

Introduction

 

To make it possible to print from a document, that is, from a CDocument object, the MFC provides printing at the CView level. Since CView is the common ancestor to the view-based classes, the derived objects inherit this functionality, using the Document/View architecture.

WYSIWYG Not Exactly

 

When introducing the process of creating a new project, we saw that you could use the MFC Application wizard to generate a semi-ready made application equipped with a view. When studying GDI, we saw that you could use the OnDraw() event of the view to draw something on the monitor (of course, if you manually create your application and apply the document/view architecture, you can still implement this event on your own).


If you use the MFC Application to create a view-based application, the wizard would give you to option to support printing:

If you accept this default to provide printing in your application, the wizard would create a ready-made menu:

Notice that the toolbar is also equipped with a button that displays a printer. This indicates that you should be able to print something you would have drawn using the OnDraw() event.

For example, you can draw a picture or bitmap to display to the user. Consider the following image:

Here is a way of displaying this picture in a view:

void CDecorationView::OnDraw(CDC* pDC)
{
	CDecorationDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CBitmap bmpFlower;
	CDC memDCFlower;

	bmpFlower.LoadBitmap(IDB_FLOWER1);
	memDCFlower.CreateCompatibleDC(pDC);
	CBitmap *bmpPrevious = memDCFlower.SelectObject(&bmpFlower);

	pDC->BitBlt(10, 10, 450, 563, &memDCFlower, 0, 0, SRCCOPY);

	pDC->SelectObject(bmpPrevious);
	// TODO: add draw code for native data here
}

This would produce:

Decoration

To print this, on the main menu, you would click File -> Print… and you would notice that only a small picture prints

This indicates that, when it comes to default printing, What You See on the monitor is not exactly What You Get on the Printer.

 

 

Copyright ?1998-2005 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net