Jon Lippincott
April 17th, 1999, 10:32 AM
I have to write a program to generate the schedules for all my classmates at school, and I don't know an awful lot about printing. I can print text with no problem, but as soon as I try to draw a line it doesn't work. I'm in MM_TEXT mode, but that shouldn't prevent me from drawing lines, should it? Here is the code I have. It looks very ugly, mind you. I know for a fact that all the schedules are to be on one page, so I don't need any loops or anything, I don't think. Here's the code:
CDC dc;
CPrintDialog printDlg(FALSE);
CRect r;
// ask the user to select a printer
if (printDlg.DoModal() == IDCANCEL)
return;
// Attach a printer DC
dc.Attach(printDlg.GetPrinterDC());
dc.m_bPrinting = TRUE;
// use Textmappingmode, that's easiest to map the fontsize
dc.SetMapMode(MM_TEXT);
// setup font specifics
LOGFONT LogFont;
CFont aFont, *oldFont;
LogFont.lfHeight = -MulDiv(10, GetDeviceCaps(dc, LOGPIXELSY), 72);
LogFont.lfWidth = 0;
LogFont.lfEscapement = 0;
LogFont.lfOrientation = 0;
LogFont.lfWeight = 0;
LogFont.lfItalic = false;
LogFont.lfUnderline = 0;
LogFont.lfStrikeOut = 0;
LogFont.lfCharSet = ANSI_CHARSET;
LogFont.lfOutPrecision = OUT_TT_PRECIS;
LogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
LogFont.lfQuality = DEFAULT_QUALITY;
LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
lstrcpy (LogFont.lfFaceName, "MS Sans Serif");
dc.SetBkMode(OPAQUE);
aFont.CreateFontIndirect ( &LogFont );
// ok, we've build the font, now use it
oldFont = dc.SelectObject( &aFont );
CPrintInfo Info;
Info.m_rectDraw.SetRect(10, 10,
dc.GetDeviceCaps(HORZRES),
dc.GetDeviceCaps(VERTRES));
dc.MoveTo(10,100);
dc.LineTo(50, 100);
DOCINFO di;
::ZeroMemory(&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
// application title appears in the spooler view
di.lpszDocName = "Names";
dc.StartDoc(&di);
dc.StartPage();
dc.DrawText("Your momma\tblahblah\r\n\r\nhi", Info.m_rectDraw, DT_WORDBREAK|DT_NOCLIP|DT_EXPANDTABS);
dc.EndPage();
dc.EndDoc();
dc.SelectObject(oldFont);
dc.Detach();
CDC dc;
CPrintDialog printDlg(FALSE);
CRect r;
// ask the user to select a printer
if (printDlg.DoModal() == IDCANCEL)
return;
// Attach a printer DC
dc.Attach(printDlg.GetPrinterDC());
dc.m_bPrinting = TRUE;
// use Textmappingmode, that's easiest to map the fontsize
dc.SetMapMode(MM_TEXT);
// setup font specifics
LOGFONT LogFont;
CFont aFont, *oldFont;
LogFont.lfHeight = -MulDiv(10, GetDeviceCaps(dc, LOGPIXELSY), 72);
LogFont.lfWidth = 0;
LogFont.lfEscapement = 0;
LogFont.lfOrientation = 0;
LogFont.lfWeight = 0;
LogFont.lfItalic = false;
LogFont.lfUnderline = 0;
LogFont.lfStrikeOut = 0;
LogFont.lfCharSet = ANSI_CHARSET;
LogFont.lfOutPrecision = OUT_TT_PRECIS;
LogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
LogFont.lfQuality = DEFAULT_QUALITY;
LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
lstrcpy (LogFont.lfFaceName, "MS Sans Serif");
dc.SetBkMode(OPAQUE);
aFont.CreateFontIndirect ( &LogFont );
// ok, we've build the font, now use it
oldFont = dc.SelectObject( &aFont );
CPrintInfo Info;
Info.m_rectDraw.SetRect(10, 10,
dc.GetDeviceCaps(HORZRES),
dc.GetDeviceCaps(VERTRES));
dc.MoveTo(10,100);
dc.LineTo(50, 100);
DOCINFO di;
::ZeroMemory(&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
// application title appears in the spooler view
di.lpszDocName = "Names";
dc.StartDoc(&di);
dc.StartPage();
dc.DrawText("Your momma\tblahblah\r\n\r\nhi", Info.m_rectDraw, DT_WORDBREAK|DT_NOCLIP|DT_EXPANDTABS);
dc.EndPage();
dc.EndDoc();
dc.SelectObject(oldFont);
dc.Detach();