print page size
GR> Can one get the size of the paper in device units (pixels)
GR> such that OnPrepareDC can set the viewport extent to be
GR> appropriate for the printer paper and not the screen?
The following will get the size of the *paper* in logical units (MM_HIENGLISH)
which can then be converted to device units via LPtoDP()…
// find out the physical page size
PRINTDLG pd;
CRect rectPaper;
if ( AfxGetApp()->GetPrinterDeviceDefaults( &pd ) )
{
ASSERT( pd.hDevMode != NULL );
LPDEVMODE ptrDevMode = ( LPDEVMODE )::GlobalLock( pd.hDevMode );
switch( ptrDevMode->dmPaperSize )
{
case 0:
// the dmPaperWidth & dmPaperLength are the width & height of
// a custom paper size expressed in 1/10's of a millimeter.
// convert to inches in MM_HIGHENGLISH…
rectPaper = CRect( 0, 0, ptrDevMode->dmPaperWidth * 4,
-ptrDevMode->dmPaperLength * 4 );
break;
case DMPAPER_LETTER:
case DMPAPER_LETTERSMALL:
case DMPAPER_NOTE:
rectPaper = (ptrDevMode->dmOrientation ==
DMORIENT_LANDSCAPE
? CRect( 0, 0, 11000, -8500 )
: CRect( 0, 0, 8500, -11000 )); //
8-1/2 x 11
break;
case DMPAPER_LEGAL:
rectPaper = ( ptrDevMode->dmOrientation ==
DMORIENT_LANDSCAPE
? CRect( 0, 0, 14000, -8500 )
: CRect( 0, 0, 8500, -14000 )); //
8-1/2 x 14
break;
default:
rectPaper = CRect( 0, 0, 0, 0 ); // handle other sizes, if
needed
break;
}
::GlobalUnlock( pd.hDevMode );
For some printers, the size of the paper and the size of the "display" (maximum
printable area) will be the same (the WinFAX driver, for example, is like
this). However others have a "hard clip" limit where tohe printer physically
cannot print. The printable area of the page can be obtained like this…
CPoint sizePrintableArea;
sizePrintableArea.x = m_pDC->GetDeviceCaps( HORZRES );
sizePrintableArea.y = m_pDC->GetDeviceCaps( VERTRES );
pDC->DPtoLP( &sizePrintableArea );
Hope this helps.
gc
Norman, Oklahoma USA
— "Is that a *real* poncho or is that a *Sears* poncho?"