B
Bryan
I am having a problem where if I try to specify more than one point size in
a device context, it does not work. Please look at the following code and
let me know what I am doing wrong... I'm about at my wits end!..
All I am trying to do is print one line with a point size of 10, and the
next line with a point size of 8. In my code, what happens is that both
lines end up printing with a point size of 8...???!!! Changing the weight
of the font seems to work ok, so I'm stumped as to why I can't change the
point size...
Thanks for any help!..
[snip]
PRINTDLG pDdlg;
DEVMODE *mode = NULL;
CDC dcPrint;
DOCINFO myPrintJob;
CFont font;
// Get Printer
CPrintDialog dlgPrint(FALSE, PD_ALLPAGES,NULL);
if(AfxGetApp()->GetPrinterDeviceDefaults(&pDdlg))
{
mode = (DEVMODE *) GlobalLock(pDdlg.hDevMode);
GlobalUnlock(pDdlg.hDevMode);
}
dlgPrint.m_pd.hDevMode = mode;
if(dlgPrint.DoModal() == IDOK)
{
dcPrint.Attach(dlgPrint.GetPrinterDC());
myPrintJob.cbSize = sizeof(myPrintJob);
myPrintJob.lpszDocName = "MyTestDocument";
myPrintJob.lpszOutput = NULL;
myPrintJob.fwType = NULL;
} else {
// They canceled...
return 0;
}
if (dcPrint.StartDoc(&myPrintJob) < 0)
{
AfxMessageBox(_T("Printer would not initialize!"));
return 0;
}
int PointSize = 10;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -MulDiv(PointSize, dcPrint.GetDeviceCaps(LOGPIXELSY), 72);
strcpy(lf.lfFaceName, "Courier New");
lf.lfWeight = FW_NORMAL;
if (!font.CreateFontIndirect(&lf))
{
AfxMessageBox("Failed Creating Font!..");
return 0;
}
/////////////////////// HERE IS THE PROBLEM /////////////////////
CString szTV = "Hello World!";
int dVcntr = 0;
dcPrint.SelectObject(&font[x]);
dcPrint.TextOut(0, dVcntr, szTV);
dVcntr += (PointSize * 10);
// Change our font attributes...
PointSize = 8;
lf.lfHeight = -MulDiv(PointSize, dcPrint.GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_BOLD;
if (!font.CreateFontIndirect(&lf))
{
AfxMessageBox("Failed Creating Font!..");
return 0;
}
dcPrint.TextOut(0, dVcntr, szTV);
///////////////////////////////////////////////////////////////////
dcPrint.EndPage();
dcPrint.EndDoc();
dcPrint.Detach();
font.DeleteObject();
a device context, it does not work. Please look at the following code and
let me know what I am doing wrong... I'm about at my wits end!..
All I am trying to do is print one line with a point size of 10, and the
next line with a point size of 8. In my code, what happens is that both
lines end up printing with a point size of 8...???!!! Changing the weight
of the font seems to work ok, so I'm stumped as to why I can't change the
point size...
Thanks for any help!..
[snip]
PRINTDLG pDdlg;
DEVMODE *mode = NULL;
CDC dcPrint;
DOCINFO myPrintJob;
CFont font;
// Get Printer
CPrintDialog dlgPrint(FALSE, PD_ALLPAGES,NULL);
if(AfxGetApp()->GetPrinterDeviceDefaults(&pDdlg))
{
mode = (DEVMODE *) GlobalLock(pDdlg.hDevMode);
GlobalUnlock(pDdlg.hDevMode);
}
dlgPrint.m_pd.hDevMode = mode;
if(dlgPrint.DoModal() == IDOK)
{
dcPrint.Attach(dlgPrint.GetPrinterDC());
myPrintJob.cbSize = sizeof(myPrintJob);
myPrintJob.lpszDocName = "MyTestDocument";
myPrintJob.lpszOutput = NULL;
myPrintJob.fwType = NULL;
} else {
// They canceled...
return 0;
}
if (dcPrint.StartDoc(&myPrintJob) < 0)
{
AfxMessageBox(_T("Printer would not initialize!"));
return 0;
}
int PointSize = 10;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -MulDiv(PointSize, dcPrint.GetDeviceCaps(LOGPIXELSY), 72);
strcpy(lf.lfFaceName, "Courier New");
lf.lfWeight = FW_NORMAL;
if (!font.CreateFontIndirect(&lf))
{
AfxMessageBox("Failed Creating Font!..");
return 0;
}
/////////////////////// HERE IS THE PROBLEM /////////////////////
CString szTV = "Hello World!";
int dVcntr = 0;
dcPrint.SelectObject(&font[x]);
dcPrint.TextOut(0, dVcntr, szTV);
dVcntr += (PointSize * 10);
// Change our font attributes...
PointSize = 8;
lf.lfHeight = -MulDiv(PointSize, dcPrint.GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_BOLD;
if (!font.CreateFontIndirect(&lf))
{
AfxMessageBox("Failed Creating Font!..");
return 0;
}
dcPrint.TextOut(0, dVcntr, szTV);
///////////////////////////////////////////////////////////////////
dcPrint.EndPage();
dcPrint.EndDoc();
dcPrint.Detach();
font.DeleteObject();