CView::OnPreparePrinting

virtual BOOL OnPreparePrinting( CPrintInfo* pInfo );

Return Value

Nonzero to begin printing; 0 if the print job has been canceled.

Parameters

pInfo

Points to a CPrintInfo structure that describes the current print job.

Remarks

Called by the framework before a document is printed or previewed. The default implementation does nothing.

You must override this function to enable printing and print preview. Call the DoPreparePrinting member function, passing it the pInfo parameter, and then return its return value; DoPreparePrinting displays the Print dialog box and creates a printer device context. If you want to initialize the Print dialog box with values other than the defaults, assign values to the members of pInfo. For example, if you know the length of the document, pass the value to the SetMaxPage member function of pInfo before calling DoPreparePrinting. This value is displayed in the To: box in the Range portion of the Print dialog box.

DoPreparePrinting does not display the Print dialog box for a preview job. If you want to bypass the Print dialog box for a print job, check that the m_bPreview member of pInfo is FALSE and then set it to TRUE before passing it to DoPreparePrinting; reset it to FALSE afterwards.

If you need to perform initializations that require access to the CDC object representing the printer device context (for example, if you need to know the page size before specifying the length of the document), override the OnBeginPrinting member function.

If you want to set the value of the m_nNumPreviewPages or m_strPageDesc members of the pInfo parameter, do so after calling DoPreparePrinting. The DoPreparePrinting member function sets m_nNumPreviewPages to the value found in the application’s .INI file and sets m_strPageDesc to its default value.

Example

The following is an override of OnPreparePrinting provided by AppWizard if you select the printing option when you create a set of starter files. This override is sufficient unless you want to initialize the Print dialog box.

BOOL CMyView::OnPreparePrinting( CPrintInfo *pInfo )
{
   return DoPreparePrinting( pInfo );
}

CView OverviewClass MembersHierarchy Chart

See Also   CPrintInfo, CView::DoPreparePrinting, CView::OnBeginPrinting, CView::OnPrepareDC, CView::OnPrint