typedef struct _CARD
{
// ----------------
HDC hDC; // Graphical context
HANDLE hPrinter; // Destination Printer
// ----------------
// this will be set up with the openCard function
int height; // of the card (see CR80 dimensions)
int width; // idem
// ----------------
BOOL bNewFontCreated; // Font management
HFONT prevFont;
HFONT currFont;
// ----------------
BOOL bNewPenCreated; // Pen management
HPEN prevPen;
HPEN currPen;
// ----------------
DWORD dwLastError; // Error Management
int bOnError;
} Card, * PCard;
BOOL DriverPrint_OpenCard ( PCard pCard, LPTSTR pPrinterName )
{
pCard->bNewPenCreated = FALSE;
pCard->currPen = NULL;
pCard->prevPen = NULL;
pCard->bNewFontCreated = FALSE;
pCard->currFont = NULL;
pCard->prevFont = NULL;
pCard->height = 648;
pCard->width = 1016;
// ouverture du printer pour extraction contexte graphique
if ( OpenPrinter( pPrinterName, &(pCard->hPrinter), NULL ) )
{
LONG lDVsize = DocumentProperties( NULL, pCard->hPrinter, pPrinterName, NULL, NULL, 0 );
if ( lDVsize )
{
LPBYTE bInDV = new BYTE[ lDVsize ];
LPBYTE bOutDV = new BYTE[ lDVsize ];
DEVMODE sDV;
if ( ( bInDV != NULL ) && ( bOutDV != NULL ) )
{
lDVsize = DocumentProperties( NULL, pCard->hPrinter, pPrinterName, (PDEVMODE) bOutDV, NULL, DM_COPY );
if (lDVsize == IDOK)
{
if ( IDOK == DocumentProperties(NULL, pCard->hPrinter, pPrinterName, (PDEVMODE)bInDV, (PDEVMODE)bOutDV,
DM_IN_BUFFER | /*DM_IN_PROMPT |*/ DM_OUT_BUFFER))
{
memcpy( &sDV, bInDV, sizeof(DEVMODE) );
if ( pCard->hDC = CreateDC( NULL, pPrinterName, NULL, &sDV ) )
{
DOCINFO dinfo;
dinfo.cbSize = sizeof(DOCINFO);
dinfo.lpszDocName = NULL;
dinfo.lpszOutput = NULL;//"FILE:";
dinfo.lpszDatatype = TEXT("raw");
if ( StartDoc( pCard->hDC, &dinfo ) > 0 )
{
if ( StartPage( pCard->hDC ) <= 0 )
{
EvoError( pCard, "Error : StartPage Failed \r\n" );
}
}
else
{
EvoError( pCard, "Error : StartDoc Failed \r\n" );
}
}
else // from CreateDC
{
EvoError( pCard , "Error : CreateDC Failed \r\n" );
}
}
else // from IDOK == DocumentProperties
{
EvoError( pCard, "Error : DocumentProperties Failed \r\n" );
}
}
else // from (lDVsize == IDOK)
{
EvoError( pCard, "Error : DocumentProperties (Copy Request) Failed \r\n" );
}
}
else // from ( ( bInDV != NULL ) && ( bOutDV != NULL ) )
{
EvoError( pCard, "Error : Memory Allocation Failed \r\n" );
}
// nettoyage
delete(bInDV);
delete(bOutDV);
if ( !ClosePrinter(pCard->hPrinter) )
{
EvoError( pCard, "Error : ClosePrinter Failed \r\n" );
}
}
else // from lDVSize
{
EvoError( pCard, "Error : DocumentProperties (Size Request) Failed \r\n" );
}
}
else // openprinter
{
EvoError( pCard, "Error : OpenPrinter Failed \r\n" );
}
return ( !pCard->bOnError );
}