|
-
January 14th, 2004, 07:49 AM
#1
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
-
October 6th, 2005, 07:54 AM
#2
Re: changing printing to landscape first recognized the second time
Hi, I am having the same problem.
Did you find a solution?
-
October 6th, 2005, 08:00 AM
#3
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().
Gort...Klaatu, Barada Nikto!
-
October 6th, 2005, 10:57 PM
#4
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"
It takes seconds for rating…that actually compensates the minutes taken for giving answers
The biggest guru-mantra is: Never share your secrets with anybody. It will destroy you.
Regards, Be generous->Rate people
Jayender!!
-
October 7th, 2005, 02:49 AM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|