SDL printer lib

I’m developing a little library for printing with SDL

Now I’m writing a function to print a given SDL_Surface

In WIN32 I’ve written something like this:

#ifdef WIN32

HDC GetPrinterDC()
{
char szPrinter[80];
char *szDevice, *szDriver, *szOutput;
DEVMODE PrintDev;

GetProfileString(“windows”, “device”, “,” ,szPrinter, 80);

if (NULL != (szDevice = strtok (szPrinter, “,”)) &&
NULL != (szDriver = strtok (NULL, “,”)) &&
NULL != (szOutput = strtok (NULL, “,”))) {

  PrintDev.dmOrientation = DMORIENT_LANDSCAPE;
  return CreateDC(szDriver, szDevice, szOutput,&PrintDev);

}

return 0;
}

void PrintSurface (SDL_Surface* Surface)
{
HDC HdcPrinter;
static DOCINFO di = {sizeof (DOCINFO), “Prova”, NULL};
HdcPrinter = GetPrinterDC();

int lx = GetDeviceCaps(HdcPrinter,HORZRES);
int ly = GetDeviceCaps(HdcPrinter,VERTRES);

if (HdcPrinter != NULL) {
if (StartDoc (HdcPrinter, &di) > 0) {
if (StartPage(HdcPrinter) > 0) {

/* *************** I NEED SOME HELP HERE! *************** */

    StretchBlt(HdcPrinter, 0, 0, lx, (lx*Surface->h)/Surface->w,
               /* HOW I CAN OBTAIN THIS DC ? */,
               0, 0, Surface->w, Surface->h, SRCCOPY);

/* ******************************************************* */

    if (EndPage(HdcPrinter) > 0) {
       EndDoc (HdcPrinter);
    }
  }
}

}
}

#endif

I need to create a Device Context of a bitmap windows object
that contains surface data. What’s the best way to do this?

Thanks for any help.

Enzo.–
E-mail enzo.gupi at tiscalinet.it
Home page http://enzogupi.interfree.it

I need to create a Device Context of a bitmap windows object
that contains surface data. What’s the best way to do this?

ARRRGGGHHH!!! The best way is simply no to do like this.

Windows is not able to print colored bitmap with a device but only black
and white (monochrome) bitmap.
What you should do is to convert the bitmap you want to print to an
Device Independant Bitmap and after you will be able to send this new
bitmap in any Device Context (and specifically the printer device :slight_smile: )
whitout probleme.

I am on holiday until 1 July. When I will be back, I will send you a
snipet of code to convert Device Dependant Bitmap to Device Independant
Bitmap if you want. Ask me again after 1 July.–
Sincerely

Fred ~
? ?
/V
// \
/( )
^`~’^