Solved

OnPrint Does not get called from CFormView

Posted on 2013-01-02
6
722 Views
Last Modified: 2013-01-03
I am working on MDI Application which has all views as CFormView Derived.
On one of view there is graph displayed which needs to be printed.
I overridden all necessary functions like OnBeginPrinting,OnPrint etc.
But these functions did not get called.Please Help
0
Comment
Question by:enthurao
  • 3
  • 2
6 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38735912
This might give you a hint (it appears when you create the project):
No Print for FormView

If you want the MFC printing support do not use CFormView based classes.
0
 
LVL 32

Accepted Solution

by:
sarabande earned 500 total points
ID: 38736616
the print functions were provided by CView baseclass. so they were available also in class derived from CFormView which is derived from CScrollView which is derived from CView.

However you need to enable printing by overriding YourFormView::OnPreparePrinting(). See below sample code snippet from msdn:

BOOL CExampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
   //The document has 2 pages.
   pInfo->SetMaxPage(2);
   return CView::DoPreparePrinting(pInfo);
}

Open in new window


the CView::DoPreparePrinting would return non-zero while the CView::OnPreparePrinting returns zero (thus disabling further printing calls).

Sara
0
 

Author Closing Comment

by:enthurao
ID: 38739787
Thank you very much it worked
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 32

Expert Comment

by:sarabande
ID: 38739935
you are welcome.

No printing support will be available by CFormView

the meaning of the statement is that CFormView itself neither enables printing by an override of OnPreparePrinting nor has an implementation for the other printing member functions which would bring the formview's layout and data to paper.

Sara
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38739944
And the final sentance was:
If you want the MFC printing support do not use CFormView based classes.


A rough translation of the no print support is that you have to code it all yourself wheras most other CView based classes can use the same code for display to screen or print to paper.
0
 
LVL 32

Expert Comment

by:sarabande
ID: 38740529
MFC (VS2010) supports printing for

- CEditView
- CHTMLEditView
- COleDocObjectItem

the ColeDocObjectItem is for active-x data. the printing support is only an interface to "callback" functions of the active-x (which you have to provide).

the edit view is not more than an edit field "pushed" to a view and print support only would print plain text.

the html edit view uses the print function of the web browser.

if you enable printing by overriding OnPreparePrinting the implementation  of the CView::OnPrint would call the OnDraw function of your view class virtually (passing a device context for the printing device) such that all drawing you made for the screen also would be made for the printer (see comment of Andy Ainscow). that doesn't work for form views cause the controls would draw themselves rather than been drawn by the parent formview.

in summary, mfc supports only a framework for printing.

Sara
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now