| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | pm print sample 2/2 |
static int Print(void)
{
HDC hdc;
HPS hps;
DEVOPENSTRUC dos;
APIRET rc;
ULONG cReturned;
ULONG cTotal;
ULONG cbNeeded;
PRQINFO3 *prq3;
unsigned i, defq = 0;
char *p;
SIZEL sizel;
int yChar;
long yTop; // top of page (size of page in PELs)
FONTMETRICS *pfm = NULL;
LONG cForms;
HCINFO hci; // info on current form.
SIZEF sizef;
LONG caps[2];
/*
* 1.find default printer
*/
// count queues & get number of bytes needed for buffer
rc = SplEnumQueue(NULL, 3, NULL, 0L, &cReturned, &cTotal, &cbNeeded,
NULL);
if (!(rc == ERROR_MORE_DATA || rc == NERR_BufTooSmall))
return 1; // error
prq3 = malloc(cbNeeded);
// enum the queues
rc = SplEnumQueue(NULL, 3, prq3, cbNeeded, &cReturned, &cTotal,
&cbNeeded, NULL);
// search for default queue;
for (i = 0; i < cReturned; i++) {
if (prq3[i].fsType & PRQ3_TYPE_APPDEFAULT) {
defq = i;
break;
}
}
/*
* 2.create printer device context
*/
memset(&dos, 0, sizeof(dos));
p = strrchr(prq3[defq].pszDriverName, '.');
if (p)
*p = 0; // del everything after '.'
dos.pszLogAddress = prq3[defq].pszName;
dos.pszDriverName = prq3[defq].pszDriverName;
dos.pdriv = prq3[defq].pDriverData;
dos.pszDataType = "PM_Q_STD";
hdc = DevOpenDC(gHab, OD_QUEUED, "*", 4L, (PDEVOPENDATA)
& dos, 0);
pmassert(DEV_ERROR != hdc);
free(prq3);
/*
* So that we can calculate a meaningful Character Cell (GpiSetCharBox),
* query the resolution of the device. It is returned in pels per inch.
*/
DevQueryCaps(hdc, CAPS_HORIZONTAL_FONT_RES, 2, caps);
/*
* 3.Find default FORM, so we know its dimensions (in pels)
*
*/
cForms = DevQueryHardcopyCaps(hdc, 0L, 0L, &hci); // Get form count
pmassert(cForms != 0);
for (i = 0; i < cForms; i++) {
rc = DevQueryHardcopyCaps(hdc, i, 1L, &hci); // Get info for this
// form
if (rc == 1) { // Got info
if (hci.flAttributes & HCAPS_CURRENT) { // Have current form
printf("form=%s\n", hci.szFormname);
break;
}
}
}
pmassert(i != cForms); // ie: there wasn't a default form
/*
* 4.create presentation space
*/
sizel.cx = 0;
sizel.cy = 0;
hps = GpiCreatePS(gHab, hdc, &sizel,
PU_PELS | GPIA_ASSOC | GPIT_NORMAL);
pmassert(hps != GPI_ERROR);
/*
* 5. Select Font.
*/
Font(hps);
// important: we must do a STARTDOC before we use the printer HPS.
DevEscape(hdc, DEVESC_STARTDOC, strlen("Doc Title"),
"Doc Title",
0L, 0L);
/* use black color for text */
GpiSetColor(hps, CLR_BLACK);
GpiSetCharSet(hps, 0);
pmassert(GPI_ERROR != GpiCreateLogFont(hps, NULL, 1, &gFontDlg.fAttrs));
GpiSetCharSet(hps, 1);
/*
* 6. Figure out size of font.
*/
sizef.cx = MAKEFIXED((caps[0] * FIXEDINT(gFontDlg.fxPointSize)) / 72, 0);
sizef.cy = MAKEFIXED((caps[1] * FIXEDINT(gFontDlg.fxPointSize)) / 72, 0);
GpiSetCharBox(hps, &sizef);
pfm = malloc(sizeof(*pfm));
GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), pfm);
yChar = (int) pfm->lMaxBaselineExt; // height of a line
yTop = hci.yPels + pfm->lMaxDescender; // top of page
free(pfm);
/*
* 7.Draw some text.
*/
gputs(hps, yChar, yTop, 1, "Get warped");
gputs(hps, yChar, yTop, 2, "Don not delay");
gputs(hps, yChar, yTop, 3, "Get warped today");
/*
* 8. Cleanup
*/
DevEscape(hdc, DEVESC_ENDDOC, 0L, 0L, 0, NULL);
GpiAssociate(hps, NULLHANDLE);
GpiDestroyPS(hps);
DevCloseDC(hdc);
return 0;
}
--- Maximus/2 3.00
* Origin: Sol 3 * Toronto * V.32 * (905)858-8488 (1:259/414)SEEN-BY: 270/101 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407 SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809 @PATH: 259/414 400 99 229/2 3615/50 396/1 270/101 712/515 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.