🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8520

Re: Printing using windows API

#8520
From: Ray
Date: Wed, 20 Oct 2004 14:10
76 lines
3449 bytes
Simon

There's a bit more to it than this

You have to use OpenPrinter() and fill a DEVMODE structure with printer
details. To print out a graphic I use

   DOCINFO di;
   HDC PrnDC;
   LPDEVMODE devm;
   LONG devModeSize;
   HANDLE hPrinter;
   char PDevice[100], PDriver[100], PPort[100];

  if(OpenPrinter((LPTSTR)PDevice,phP,NULL))
   {
    devModeSize=DocumentProperties(NULL,hPrinter,
(LPSTR)PDevice,NULL,NULL,0);
  if(devModeSize!=0)
      {
       devm=(DEVMODE*) new char[devModeSize];
       DocumentProperties(NULL,hPrinter,NULL,devm,NULL,DM_OUT_BUFFER);
         if(!flPort)  // flag for landscape
     {
          devm->dmFields|=DM_ORIENTATION;
      devm->dmOrientation=DMORIENT_LANDSCAPE;
     }
     devm->dmFields|=DM_PAPERSIZE;
         devm->dmFields|=DM_PRINTQUALITY;
         devm->dmFields|=DM_YRESOLUTION;
         devm->dmPaperSize=DMPAPER_A4;
         devm->dmPrintQuality=300;
         devm->dmYResolution=300;

     memset(&di,0,sizeof(DOCINFO));
     di.cbSize = sizeof(DOCINFO);
     PrnDC= CreateDC(PDriver, PDevice, NULL, devm);
       }

then you can do

       if(StartDoc(PrnDC,&di)!=SP_ERROR)
      {
                  StartPage(PrnDC);
                  BitBlt(PrnDC,Xfact,Yfact,XP,YP,*drw->DCP,0,0,SRCCOPY);
                  EndPage(PrnDC);
                  EndDoc(PrnDC);
      }

Don't forget to cleanup on exit

Ray

"Simon Elliott" <Simon at ctsn.co.uk> wrote in message 
news:41766513@newsgroups.borland.com...
> I'm doing this to print directly via windows:
>
> OpenPrinter(printer, &handle, NULL);
> StartDocPrinter(handle, 1, (LPBYTE)&DocInfo);
> StartPagePrinter(handle);
> WritePrinter(handle, (void*)buff, count, &dwBytesWritten);
> EndPagePrinter(handle);
> EndDocPrinter(handle);
>
> The returns from the functions are always OK, but it only works
> properly on certain printers. On a networked HP Colour LaserJet 2550LN
> it prints correctly, but then prints gobbledygook and the printer has
> an incorrect paper size error. Jaws PDF creator seems to interpret the
> text being printed as a series of (invalid) commands. It works fine on
> an Epson dot matrix printer.
>
> Is there any way I can get the above to work on all printers? If not,
> what's my best option? To get a device context and use TextOut?
>
> -- 
> Simon Elliott    http://www.ctsn.co.uk 
Technical Details
Message-ID: <417671f2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41766513@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,18e3c388aee13f92
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ray" <someone@someisp.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41766513@newsgroups.borland.com>
Subject: Re: Printing using windows API
Date: Wed, 20 Oct 2004 15:10:08 +0100
Lines: 78
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 62.56.16.81
Message-ID: <417671f2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1098281458 62.56.16.81 (20 Oct 2004 07:10:58 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail