Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API Print Problems...

Status
Not open for further replies.

Rhaegar

Programmer
Sep 28, 2002
19
US
Hi, I'm having a problem with the following code. What I would like it to do is to print out two lines of text. I use the characters' height (obtained from a call to GetTextMetrics) to place the second line of text below the first line. For some reason though, when it prints, the second line overlaps the first, partially obscuring it. One other thing, the code did work as expected when I didn't specify the height in the LOGFONT structure (lf.lfHeight = 35 / 2). I specified a new height because I wanted a smaller font. Well, I appreciate any response. Thanks.

PRINTER_INFO_5* pi;
unsigned long icNeeded, icReturned;
EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &icNeeded, &icReturned);
pi = (PRINTER_INFO_5*)malloc(icNeeded);
if (!EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, (BYTE*)pi, icNeeded, &icNeeded, &icReturned))
{
free(pi);
return 0;
}

HDC hdc;
if ((hdc = CreateDC(NULL, pi->pPrinterName, NULL, NULL)) == NULL)
{
free(pi);
return 0;
}
free(pi);

LOGFONT lf;
ZeroMemory(&lf, sizeof(LOGFONT));
lf.lfHeight = 35 / 2;
lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
memcpy((void*)lf.lfFaceName, "Courier New", strlen("Courier New") + 1);
SelectObject(hdc, CreateFontIndirect(&lf));

char szFaceName[100];
ZeroMemory(szFaceName, 100);
GetTextFace(hdc, 100, szFaceName);
GetTextMetrics(hdc, &tm);

DOCINFO dc;
ZeroMemory(&dc, sizeof(DOCINFO));
dc.cbSize = sizeof(DOCINFO);
dc.lpszDocName = "Printer Font Test";

if ((StartDoc(hdc, &dc) > 0) && (StartPage(hdc) > 0))
{
char szTextOut[100];
sprintf(szTextOut, "This font's name is %s and its height is %d.", szFaceName, tm.tmHeight);
TextOut(hdc, 0, 0, szTextOut, strlen(szTextOut));
TextOut(hdc, 0, tm.tmHeight, szTextOut, strlen(szTextOut));

if (EndPage(hdc) > 0)
EndDoc(hdc);
}

DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
DeleteDC(hdc);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top