bool OnBeginPrinting( HDC hPrintingContext, HDC hPrinterContext, float Scale = OBP_USE_RESIZE_MODE );


hPrintingContext HDC of the device where we are going to print. This can be either device context handle of the screen window for print preview, or device context handle of printer.
hPrinterContext HDC of the printer
ScaleScale of the printed image. It can be either actual scale, or one of the following values. The scale has the same meaning as in SetScale method
OBP_USE_RESIZE_MODEthe current SetWindowResizingMode settings will be used to transformation for printing. If SetWindowResizingMode is set to WRM_KEEP_PICTURE, the printing transformation is set to ensure that all what is visible in the screen view will be printed. If SetWindowResizingMode is set to WRM_KEEP_SCALE, the same screen’s view scale will be used for printing.
OBP_KEEP_SCALEthe WRM_KEEP_SCALE mode will be used.

Return Values

true if success. false in case of error. Possible cause of error is wrong parameter, out of memory, or that OpenGL context compatible with printing device context cannot be created.


The OnBeginPrinting method prepares the printing context for printing on full printer’s paper area. The scheme of using the OnBeginPrinting method is the same as using OnBeginPrinting method of MFC’s CView class. The OnBeginPrinting method must be called before calling COpenGL::OnPrint. After printing is done, the OnEndPrinting method must be called.

When using with MFC, call this method in your CView-class-overridden-OnBeginPrinting method.

This method is available since ClassGL version 3.5


BOOL COpenGLView::OnPreparePrinting(CPrintInfo* pInfo)
  // default preparation
  return DoPreparePrinting(pInfo);
void COpenGLView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  // initialize the "print drawing done" flag
  m_PrintDrawingDone = false;
  // pass this call to the COpenGL class
  m_OpenGL.OnBeginPrinting( pDC->GetSafeHdc(), pInfo->m_pPD->m_pd.hDC );
  // set rendering context attributes for printing
void COpenGLView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
  // check whether we need to render the "print bitmap"
  if ( ! m_PrintDrawingDone )
     // draw the scene
     OnDraw( pDC );
     // set the "print drawing done" flag
     m_PrintDrawingDone = true;
  // pass this call to the COpenGL class
  m_OpenGL.OnPrint( pDC->GetSafeHdc(), true );
void COpenGLView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  // pass this call to the COpenGL class
void COpenGLView::SetupOpenGLContextForPrinting( void )
  // apply static settings as in ::OnCreate method
  // set default interaction mode

See Also

OnEndPrinting, OnPrint, SetMaxPrintResolution, GetMaxPrintResolution