Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

OnPrint Does not get called from CFormView

Posted on 2013-01-02
6
Medium Priority
?
799 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
[X]
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
  • 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 35

Accepted Solution

by:
sarabande earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 35

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 35

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

721 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