changing printing to landscape first recognized the second time
Hi, I'm doing some printing issues with MFC in VS.NET 2003.
I want to change the format of printing to landscape. For that case I added these lines of code my OnBeginPrinting function:
Code:
// print this report in landscape
LPDEVMODE lpPr = (LPDEVMODE)(((CPrintDialog *)(pInfo->m_pPD))->GetDevMode());
lpPr->dmOrientation = DMORIENT_LANDSCAPE;
pwMain->OnBeginPrinting( this,pDC,pInfo,&m_pageGrid.m_wDataGrid,m_prtcols,&m_prtmap );
When I execute my programm and choose the printing option the first preview is still in potrait event though the lines of codes written above where executed. The second time the preview is shown correctly in landscape.
What do I make wrong?
Akademos
Re: changing printing to landscape first recognized the second time
Hi, I am having the same problem.
Did you find a solution?
Re: changing printing to landscape first recognized the second time
I think you may be setting the orientation too late. Try setting it in OnPrepareDC().
Re: changing printing to landscape first recognized the second time
this is the function for Lanscape:
Code:
void CIppiSampleApp::SetLandscape()
{
// Get default printer settings.
PRINTDLG pd;
pd.lStructSize = (DWORD) sizeof(PRINTDLG);
if (GetPrinterDeviceDefaults(&pd))
{
// Lock memory handle.
DEVMODE FAR* pDevMode =
(DEVMODE FAR*)::GlobalLock(m_hDevMode);
LPDEVNAMES lpDevNames;
LPTSTR lpszDriverName, lpszDeviceName, lpszPortName;
// HANDLE hPrinter;
if (pDevMode)
{
// Change printer settings in here.
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
// Unlock memory handle.
lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
lpszDriverName = (LPTSTR )lpDevNames + lpDevNames->wDriverOffset;
lpszDeviceName = (LPTSTR )lpDevNames + lpDevNames->wDeviceOffset;
lpszPortName = (LPTSTR )lpDevNames + lpDevNames->wOutputOffset;
// ::OpenPrinter(lpszDeviceName, &hPrinter, NULL);
// ::DocumentProperties(NULL,hPrinter,lpszDeviceName,pDevMode,
// pDevMode, DM_IN_BUFFER|DM_OUT_BUFFER);
// Sync the pDevMode.
// See SDK help for DocumentProperties for more info.
// ::ClosePrinter(hPrinter);
::GlobalUnlock(m_hDevNames);
::GlobalUnlock(m_hDevMode);
}
}
}
just call this function in ur button .. that will do ..
if a post helped then dont forget to "Rate this post"
Re: changing printing to landscape first recognized the second time
Moving my code from OnPreparePrinting into OnPrepareDC worked.
All that's required is:
Code:
void CMyView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
LPDEVMODE pDevMode=NULL;
if(pDC->IsPrinting())
{
pDevMode = pInfo->m_pPD->GetDevMode();
if(pDevMode)
{
pDevMode->dmOrientation = GetReportOrientation();
pDC->ResetDC(pDevMode);
}
}
CExView::OnPrepareDC(pDC, pInfo);
}
Where GetReportOrientation() returns:
DMORIENT_PORTRAIT or
DMORIENT_LANDSCAPE
Regards,
Will.