Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

OnPrint Does not get called from CFormView

Posted on 2013-01-02
6
759 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:ADITYA RAO
  • 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 33

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:ADITYA RAO
ID: 38739787
Thank you very much it worked
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

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 33

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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