CPrintDlg to appear with Landscape printing orientation

来源:互联网 发布:ug mac pro 编辑:程序博客网 时间:2024/05/21 18:12

Trying to get a CPrintDlg to appear with Landscape printing orientation
selected by default. I have tried to allocate a DEVMODE structure and fill
it but this did not work.

void ReportPrinter::PrintReport( BOOL bPrintLandscape )
{
HDC hdcPrn;
HANDLE hDevMode;
LPDEVMODE lpDevMode;


// Instantiate a CPrintDialog.
CPrintDialog *i_printDlg =
new CPrintDialog( FALSE, PD_ALLPAGES | PD_RETURNDC | PD_NOSELECTION
/*| PD_PRINTSETUP */| PD_RETURNDEFAULT, NULL );

// Get the default printer settings using the PD_RETURNDEFAULT flag.
PrintDlg( &( i_printDlg->m_pd ) );
hDevMode = i_printDlg->m_pd.hDevMode;

// Clear the PD_RETURNDEFAULT flag; we'll set flags to our preferences below
i_printDlg->m_pd.Flags &= ~( PD_RETURNDEFAULT );

if ( TRUE == bPrintLandscape )
{
// Set print orientation to 'Landscape'.
lpDevMode = (LPDEVMODE)GlobalLock( hDevMode );
lpDevMode->dmFields = DM_ORIENTATION;
lpDevMode->dmOrientation = DMORIENT_LANDSCAPE;
GlobalUnlock( hDevMode );
}

// Initialize some of the fields in PRINTDLG structure.
i_printDlg->m_pd.nMinPage = i_printDlg->m_pd.nMaxPage = 1;
i_printDlg->m_pd.nFromPage = i_printDlg->m_pd.nToPage = 1;

// Display Windows print dialog box.
if ( IDOK == i_printDlg->DoModal() )
{
// Obtain a handle to the device context.
hdcPrn = i_printDlg->GetPrinterDC();

if ( hdcPrn != NULL )
{
m_pDC = new CDC;
m_pDC->Attach( hdcPrn ); // attach a i_printer DC
m_pDC->StartDoc( m_strReportID.c_str() ); // begin a new i_print job
CalcPageSize( hdcPrn ); // Set the i_printing alignment
while ( m_bMoreData )
{
m_nPrinterYPos = 0;
m_pDC->StartPage(); // begin a new page
m_bMoreData = WriteReport(); // write a page
m_pDC->EndPage(); // end a page
}
m_pDC->EndDoc(); // end a i_print job
m_pDC->Detach(); // detach the i_printer DC
delete m_pDC;
}
}
delete i_printDlg;
}


原创粉丝点击