Article View: borland.public.cppbuilder.nativeapi
Article #14695Re: how to print a string directly to a printer using "fprintf" or "printf" ?
From: Richard Yu
Date: Wed, 06 Aug 2003 22:37
Date: Wed, 06 Aug 2003 22:37
83 lines
3370 bytes
3370 bytes
yes, page printer, I have tried adding > fprintf(Printer,"\f"); > fclose(Printer); still no reaction, I don't have a local printer like LPT1, I think the setting PortName="IP_192.168.0.55 "; for the net printer may cause that. "Bob Gonder" <notbg@notmindspring.invalid> wrote in message news:4ms2jvgakhv47j1giukpjalfbinm5e1m5n@4ax.com... > Richard Yu wrote: > > >My printer is a network printer, I tried this code, > > > >char *PortName="IP_192.168.0.55 "; > > FILE *Printer=fopen(PortName,"wb"); > > fprintf(Printer,"Text:\r\n\n","test string "); > > > >it didn't do any thing , don't know why. > > Is it a Page printer? (Laserjet/multifunction type) > Try adding > fprintf(Printer,"\f"); > fclose(Printer); > > I use one of 3 methods to print (depending on the type of printer), > all Win32 API. > > 1) Essentially "DOS" mode > CreateFile > WriteFile > CloseHandle > Usually write a form-feed(12) before closing the handle. > > 2) Simple "raw" mode > OpenPrinter > StartDocPrinter > StartPagePrinter > WritePrinter > EndPagePrinter > EndDocPrinter > ClosePrinter > I think EndPagePrinter causes a form-feed. But I always take care of > it myself. > > 3) Full Windows DC mode > OpenPrinter > > num_bytes=DocumentProperties(NULL,printerHandle,&printerfile_port,NULL,NULL, 0); > // allocate the memory > > DevMode=(DEVMODE*)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,num_bytes); > // call DocumentProperties() again, to get the devmode. > > DocumentProperties(NULL,printerHandle,&printerfile_port,DevMode,NULL,DM_OUT_ BUFFER); > printerDC = CreateDC( NULL, &printerfile_port, NULL, DevMode); > GlobalFree(DevMode); > printerJob=StartDoc(printerDC,&lpdi); > > StartPage(printerDC); > SetTextAlign(printerDC,TA_LEFT+TA_TOP+TA_NOUPDATECP); > SetBkMode (printerDC, TRANSPARENT); > ExtTextOut(printerDC,printerDx*x,printerDy*y, > 0, // text-output options > (RECT*)NULL, // optional clipping and/or opaquing > str, // points to string > z, // number of characters in string > (INT *)NULL ); // pointer to array of intercharacter > EndPage(printerDC); > EndDoc(printerDC); > DeleteDC(printerDC); > ClosePrinter(printerHandle); > >
Technical Details
Message-ID:
<3f3183ed$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f314de8@newsgroups.borland.com> <3f315101$1@newsgroups.borland.com> <3f316dd1$3@newsgroups.borland.com> <4ms2jvgakhv47j1giukpjalfbinm5e1m5n@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ff83352b6b456ff2 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-06 16:05:44 PST From: "Richard Yu" <richard@colorselector.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f314de8@newsgroups.borland.com> <3f315101$1@newsgroups.borland.com> <3f316dd1$3@newsgroups.borland.com> <4ms2jvgakhv47j1giukpjalfbinm5e1m5n@4ax.com> Subject: Re: how to print a string directly to a printer using "fprintf" or "printf" ? Date: Wed, 6 Aug 2003 15:37:16 -0700 Lines: 85 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 24.207.7.224 Message-ID: <3f3183ed$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1060209645 24.207.7.224 (6 Aug 2003 15:40:45 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail