CPrintDlg to appear with Landscape printing orientation

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值