Click to See Complete Forum and Search --> : Default Printing


June 3rd, 1999, 10:36 AM
Ok, I posted this question on the MFC newsgroup, and I THINK someone from this site posted a piece of code for me. But I just can't get it to work. My problem is I need to get my MFC application to default to printing landscape, NOT portrait. I wrote in the code that was posted to the newsgroup, but my application still prints in portrait. I am getting desperate and I have no clue how to make this happen.


void CAlertSortView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
int i, nStart, nEnd, nHeight;
int Asize; // how big the array is
long Increment = 30; // how far down the page to print each line
CFont font; // create a CFont object
TEXTMETRIC tm;
CPoint point(100, -100);
CString CSFooter;


*********** here is the piece of code that was posted and is supposed to make
my app print in landscape **************


CPrintDialog dlg(FALSE);


// if (dlg.DoModal()==IDCANCEL)
dlg.GetDefaults();


LPDEVMODE lp = (LPDEVMODE) ::GlobalLock(dlg.m_pd.hDevMode);
ASSERT(lp);
lp->dmOrientation = DMORIENT_LANDSCAPE;
::GlobalUnlock(dlg.m_pd.hDevMode);
::GlobalFree(dlg.m_pd.hDevMode);
ResetDC(dlg.m_pd.hDC,lp);
**************** here is where it ends *************************
pDC->SetMapMode(MM_TWIPS);

CAlertSortDoc* pDoc = GetDocument();

m_Page = pInfo->m_nCurPage; // get the current page

CSFooter.Format("Page %d", m_Page);

// please note that the number 35 is howe many lines are to printed to each
// page. These 2 numbers must be the same and must be the same as the number
// in OnPreparePrinting() to make the MaxPage number;

nStart = (m_Page -1) * 35; // where in our array to we grab lines for printing
nEnd = nStart + 35; // where to end

font.CreateFont(-210, 0, 0, 0, 400, FALSE, FALSE, // create our trutype font
0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_MODERN, "Courier New");

CFont *pOldFont = (CFont*) (pDC->SelectObject(&font)); // print with the new font

pDC->GetTextMetrics(&tm);

nHeight = tm.tmHeight + tm.tmExternalLeading;

Asize = pDoc->CSAText.GetSize(); // get our array size

for(i=nStart;i<nEnd;i++) // start outputting lines to the page
{
if( i > Asize-1)
{
break;
}

point.y -= nHeight;

pDC->TextOut(point.x, point.y, pDoc->CSAText.GetAt(i));
Increment += 300;
}

pDC->TextOut(2850, 2300, CSFooter);



}