Hi,
This is a simple draft, but maybe is useful for anyone...
Original Win_PrinterFileRaw, bypass the driver to printer, with
PDFCreator does not work.
But, changing from "RAW" to "TEXT" with PDFCreator works, maybe with
others drivers printers
works too.
Additionally, SetPrinterCFG allows change Orientation direct with driver
(extract from microsoft msdn site).
Question: Is possible add a set functions like
SET( PRINTER_CFG, HB_ORIENTATION, HB_LANDSCAPE)
...
SET( PRINTER_CFG, HB_PAPER, HB_PAPER_A4)
Best regards,
Ranier Vilela
BOOL SetPrinterCFG(HANDLE hPrinter, LPCTSTR lpPrinterName, short
dmOrientation)
{
DWORD dwNeeded = 0;
PRINTER_INFO_2 *pi2 = NULL;
DEVMODE *pDevMode = NULL;
BOOL bFlag;
LONG lFlag;
assert(hPrinter != NULL);
// The first GetPrinter tells you how big the buffer should be in
// order to hold all of PRINTER_INFO_2. Note that this should fail
with
// ERROR_INSUFFICIENT_BUFFER. If GetPrinter fails for any other
reason
// or dwNeeded isn't set for some reason, then there is a problem...
SetLastError(0);
bFlag = GetPrinter(hPrinter, 2, 0, 0, &dwNeeded);
if ((!bFlag) && (GetLastError() != ERROR_INSUFFICIENT_BUFFER) ||
(dwNeeded == 0))
{
return FALSE;
}
// Allocate enough space for PRINTER_INFO_2...
pi2 = (PRINTER_INFO_2 *) hb_xgrab( dwNeeded );
if (pi2 == NULL)
{
return FALSE;
}
// The second GetPrinter fills in all the current settings, so all you
// need to do is modify what you're interested in...
bFlag = GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded);
if (!bFlag)
{
hb_xfree( pi2 );
return FALSE;
}
// If GetPrinter didn't fill in the DEVMODE, try to get it by calling
// DocumentProperties...
if (pi2->pDevMode == NULL)
{
LONG lSize = DocumentProperties(NULL, hPrinter,( LPTSTR )
lpPrinterName, NULL, NULL, 0);
if (lSize <= 0)
{
hb_xfree( pi2 );
return FALSE;
}
pDevMode = (DEVMODE *) hb_xgrab( lSize );
if (pDevMode == NULL)
{
hb_xfree( pi2 );
return FALSE;
}
lFlag = DocumentProperties(NULL, hPrinter,( LPTSTR )
lpPrinterName, pDevMode, NULL, DM_OUT_BUFFER);
if (lFlag != IDOK || pDevMode == NULL)
{
hb_xfree( pDevMode );
hb_xfree( pi2 );
return FALSE;
}
pi2->pDevMode = pDevMode;
}
// Driver is reporting that it doesn't support this change...
if (!(pi2->pDevMode->dmFields & DM_ORIENTATION))
{
hb_xfree( pi2 );
if (pDevMode)
{
hb_xfree( pDevMode );
}
return FALSE;
}
// Specify exactly what we are attempting to change...
pi2->pDevMode->dmFields = DM_ORIENTATION;
pi2->pDevMode->dmOrientation = dmOrientation;
// Do not attempt to set security descriptor...
pi2->pSecurityDescriptor = NULL;
// Make sure the driver-dependent part of devmode is updated...
lFlag = DocumentProperties(NULL, hPrinter,( LPTSTR ) lpPrinterName,
pi2->pDevMode, pi2->pDevMode, DM_IN_BUFFER | DM_OUT_BUFFER);
if (lFlag != IDOK)
{
hb_xfree( pi2 );
if (pDevMode)
{
hb_xfree( pDevMode );
}
return FALSE;
}
// Update printer information...
bFlag = SetPrinter(hPrinter, 2, (LPBYTE)pi2, 0);
if (!bFlag)
// The driver doesn't support, or it is unable to make the change...
{
hb_xfree( pi2 );
if ( pDevMode )
{
hb_xfree( pDevMode );
}
return FALSE;
}
// Tell other apps that there was a change...
SendMessageTimeout(HWND_BROADCAST, WM_DEVMODECHANGE, 0L,
(LPARAM)(LPCSTR)lpPrinterName, SMTO_NORMAL, 1000, NULL);
// Clean up...
if ( pi2 )
{
hb_xfree( pi2 );
}
if ( pDevMode )
{
hb_xfree( pDevMode );
}
return TRUE;
}
HB_FUNC( PRINTFILETEXT )
{
int iResult = -1;
if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) && HB_ISNUM( 3 ) )
{
const char * pszFileName = hb_parc( 2 );
const unsigned int iWidth = hb_parni( 3 );
HANDLE hPrinter;
void * hDeviceName;
LPCTSTR lpDeviceName = HB_PARSTR( 1, &hDeviceName, NULL );
if( OpenPrinter( ( LPTSTR ) lpDeviceName, &hPrinter, NULL ) != 0 )
{
void * hDocName;
DOC_INFO_1 DocInfo;
// change orientation to LANDSCAPE, only if Width > 112
if ( iWidth > 112 )
{
if (SetPrinterCFG(hPrinter, lpDeviceName, DMORIENT_LANDSCAPE))
{
// Tell other apps that there was a change...
SendMessageTimeout(HWND_BROADCAST, WM_DEVMODECHANGE, 0L,
(LPARAM)(LPCSTR)lpDeviceName, SMTO_NORMAL, 1000, NULL);
}
}
DocInfo.pDocName = ( LPTSTR ) HB_PARSTR( HB_ISCHAR( 3 ) ? 3 :
2, &hDocName, NULL );
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = ( LPTSTR ) TEXT( "TEXT" );
//DocInfo.pDatatype = ( LPTSTR ) TEXT( "RAW" );
if( StartDocPrinter( hPrinter, 1, ( LPBYTE ) &DocInfo ) != 0 )
{
if( StartPagePrinter( hPrinter ) != 0 )
{
HB_FHANDLE fhnd = hb_fsOpen( pszFileName, FO_READ |
FO_SHARED );
if( fhnd != FS_ERROR )
{
HB_BYTE pbyBuffer[ 32 * 1024 ];
DWORD dwWritten = 0;
HB_SIZE nRead;
while( ( nRead = hb_fsReadLarge( fhnd, pbyBuffer,
sizeof( pbyBuffer ) ) ) > 0 )
{
WritePrinter( hPrinter, pbyBuffer, ( DWORD )
nRead, &dwWritten );
}
iResult = 1;
hb_fsClose( fhnd );
}
else
iResult = -6;
EndPagePrinter( hPrinter );
}
else
iResult = -4;
EndDocPrinter( hPrinter );
}
else
iResult = -3;
ClosePrinter( hPrinter );
hb_strfree( hDocName );
}
else
iResult = -2;
hb_strfree( hDeviceName );
}
}
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour