home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
PRINTDC.ZIP
/
PRINTDC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-23
|
7KB
|
249 lines
#include "c4w.h"
#include <print.h>
int PrinterDC();
CLIPPER PRINTERDC()
{
char *lpPrintType = _parc( 1, 1 );
char *lpPrintDriver = _parc( 1, 2 );
char *lpPrintPort = _parc( 1, 3 );
int nMode = _parni( 2 );
int aOptions[ 12 ];
aOptions[ 0 ] = _parni( 1, 7 );
aOptions[ 1 ] = _parni( 1, 8 );
aOptions[ 2 ] = _parni( 1, 9 );
aOptions[ 3 ] = _parni( 1, 10 );
aOptions[ 4 ] = _parni( 1, 11 );
aOptions[ 5 ] = _parni( 1, 12 );
aOptions[ 6 ] = _parni( 1, 13 );
aOptions[ 7 ] = _parni( 1, 14 );
aOptions[ 8 ] = _parni( 1, 15 );
aOptions[ 9 ] = _parni( 1, 16 );
aOptions[ 10 ] = _parni( 1, 17 );
aOptions[ 11 ] = _parni( 1, 18 );
_retni( PrinterDC( lpPrintType,
lpPrintDriver,
lpPrintPort,
aOptions,
nMode ) );
}
int PrinterDC( char *lpPrintType,
char *lpPrintDriver,
char *lpPrintPort,
int nOptions[12],
int nMode )
{
HANDLE hDriver;
HANDLE hDevMode;
LPDEVMODE lpDevMode;
LPFNDEVMODE lpfnExtDeviceMode;
HDC hDC;
int count;
if ( ( hDriver = LoadLibrary( lpPrintDriver) ) < (HANDLE ) 32 )
{
MessageBox( 0, "Could Not Load Driver!", "PrintDC Error", MB_OK);
return( 0 );
}
// Get a function pointer to the ExtDeviceMode() function.
// ExtDeviceMode() resides in the driver so we can't call it
// directly.
lpfnExtDeviceMode = (LPFNDEVMODE) GetProcAddress(hDriver,(LPSTR) "EXTDEVICEMODE");
if ( lpfnExtDeviceMode == NULL )
{
MessageBox( 0, "ExtDeviceMode Not Supported By Printer Driver!",
"PrintDC Error", MB_OK);
FreeLibrary(hDriver);
return( 0 );
}
// Get the number of bytes in the full DEVMODE buffer.
// This includes the device-dependent part at the end
// of the DEVMODE struct.
count = lpfnExtDeviceMode(0,
hDriver,
NULL,
lpPrintType,
lpPrintPort,
NULL,
NULL,
0); // 0 = get buffer size
if ( count == -1)
{
MessageBox( 0, "Invalid DEVMODE Size!", "PrintDC Error", MB_OK);
FreeLibrary( hDriver );
return( 0 );
}
// Allocate storage for the DEVMODE buffer.
hDevMode = GlobalAlloc(GHND, count);
if ( hDevMode == NULL )
{
MessageBox( 0, "Memory Allocation Failure!", "PrintDC Error", MB_OK);
FreeLibrary( hDriver );
return( 0 );
}
lpDevMode = (LPDEVMODE)GlobalLock(hDevMode);
// Get the current printer settings.
count = lpfnExtDeviceMode(0,
hDriver,
lpDevMode, // Output buffer
lpPrintType,
lpPrintPort,
NULL,
NULL,
DM_OUT_BUFFER); // aka DM_COPY
if( !( lpDevMode->dmFields & DM_ORIENTATION ) )
nOptions[ 0 ] = NIL;
if( !( lpDevMode->dmFields & DM_PAPERSIZE ) )
nOptions[ 1 ] = NIL;
if( !( lpDevMode->dmFields & DM_PAPERLENGTH ) )
nOptions[ 2 ] = NIL;
if( !( lpDevMode->dmFields & DM_PAPERWIDTH ) )
nOptions[ 3 ] = NIL;
if( !( lpDevMode->dmFields & DM_SCALE ) )
nOptions[ 4 ] = NIL;
if( !( lpDevMode->dmFields & DM_COPIES ) )
nOptions[ 5 ] = NIL;
if( !( lpDevMode->dmFields & DM_DEFAULTSOURCE ) )
nOptions[ 6 ] = NIL;
if( !( lpDevMode->dmFields & DM_PRINTQUALITY ) )
nOptions[ 7 ] = NIL;
if( !( lpDevMode->dmFields & DM_COLOR ) )
nOptions[ 8 ] = NIL;
if( !( lpDevMode->dmFields & DM_DUPLEX ) )
nOptions[ 9 ] = NIL;
if( !( lpDevMode->dmFields & DM_YRESOLUTION ) )
nOptions[ 10 ] = NIL;
if( !( lpDevMode->dmFields & DM_TTOPTION ) )
nOptions[ 11 ] = NIL;
lpDevMode->dmFields = 0;
if( nOptions[ 0 ] != NIL )
{
lpDevMode->dmOrientation = nOptions[ 0 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_ORIENTATION;
}
if( nOptions[ 1 ] != NIL )
{
lpDevMode->dmPaperSize = nOptions[ 1 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_PAPERSIZE;
}
if( nOptions[ 2 ] != NIL )
{
lpDevMode->dmPaperLength = nOptions[ 2 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_PAPERLENGTH;
}
if( nOptions[ 3 ] != NIL )
{
lpDevMode->dmPaperWidth = nOptions[ 3 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_PAPERWIDTH;
}
if( nOptions[ 4 ] != NIL )
{
lpDevMode->dmScale = nOptions[ 4 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_SCALE;
}
if( nOptions[ 5 ] != NIL )
{
lpDevMode->dmCopies = nOptions[ 5 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_COPIES;
}
if( nOptions[ 6 ] != NIL )
{
lpDevMode->dmDefaultSource = nOptions[ 6 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_DEFAULTSOURCE;
}
if( nOptions[ 7 ] != NIL )
{
lpDevMode->dmPrintQuality = nOptions[ 7 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_PRINTQUALITY;
}
if( nOptions[ 8 ] != NIL )
{
lpDevMode->dmColor = nOptions[ 8 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_COLOR;
}
if( nOptions[ 9 ] != NIL )
{
lpDevMode->dmDuplex = nOptions[ 9 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_DUPLEX;
}
if( nOptions[ 10 ] != NIL )
{
lpDevMode->dmYResolution = nOptions[ 10 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_YRESOLUTION;
}
if( nOptions[ 11 ] != NIL )
{
lpDevMode->dmTTOption = nOptions[ 11 ];
lpDevMode->dmFields = lpDevMode->dmFields | DM_TTOPTION;
}
// Call ExtDeviceMode() once more to allow the driver
// to change the device-dependent portion of the
// DEVMODE buffer if it needs to.
if ( nMode == 0 )
nMode = DM_COPY | DM_MODIFY;
count = lpfnExtDeviceMode(0,
hDriver,
lpDevMode, // Output buffer
lpPrintType,
lpPrintPort,
lpDevMode, // Input buffer
NULL,
nMode);
hDC = CreateDC(lpPrintDriver,lpPrintType,lpPrintPort, (void FAR*)lpDevMode);
GlobalUnlock(hDevMode);
GlobalFree(hDevMode);
FreeLibrary(hDriver);
return( (int ) hDC );
}