Hi,
I was sent the following codes when I bump into some problem within VFP. This is suppose to be some API source code for changing the window printers settings without going thru Window's interactive dialog. Is this in VB? If it is, what do I have to do to make it 'Window API'?
--------------------------------------------------------
BOOL SetPrinterDeviceOrientation(LPTSTR pszPrinterName, int Orientation)
{
// if NULL is passed, then assume we are setting app object's devmode and devnames
// Open printer
HANDLE hPrinter;
if( OpenPrinter( pszPrinterName, &hPrinter, NULL ) == FALSE )
return FALSE;
// obtain PRINTER_INFO_2 structure and close printer
DWORD dwBytesReturned, dwBytesNeeded;
GetPrinter( hPrinter, 2, NULL, 0, &dwBytesNeeded );
PRINTER_INFO_2* p2 = (PRINTER_INFO_2*)GlobalAlloc( GPTR, dwBytesNeeded);
if( GetPrinter( hPrinter, 2, (LPBYTE)p2, dwBytesNeeded, &dwBytesReturned) == 0 )
{
GlobalFree( p2 );
ClosePrinter( hPrinter );
return FALSE;
}
p2->pDevMode->dmFields |= DM_ORIENTATION;
p2->pDevMode->dmOrientation = Orientation;
if( SetPrinter(
hPrinter, // handle to printer object
2, // information level
(LPBYTE) p2, // printer data buffer
0 // printer-state command
) == 0 )
{
GlobalFree( p2 );
ClosePrinter( hPrinter );
return FALSE;
}
ClosePrinter( hPrinter );
// Allocate a global handle for DEVMODE
return TRUE;
}
------------------------------------------------------
Sorry if I am in the wrong terrain.
I was sent the following codes when I bump into some problem within VFP. This is suppose to be some API source code for changing the window printers settings without going thru Window's interactive dialog. Is this in VB? If it is, what do I have to do to make it 'Window API'?
--------------------------------------------------------
BOOL SetPrinterDeviceOrientation(LPTSTR pszPrinterName, int Orientation)
{
// if NULL is passed, then assume we are setting app object's devmode and devnames
// Open printer
HANDLE hPrinter;
if( OpenPrinter( pszPrinterName, &hPrinter, NULL ) == FALSE )
return FALSE;
// obtain PRINTER_INFO_2 structure and close printer
DWORD dwBytesReturned, dwBytesNeeded;
GetPrinter( hPrinter, 2, NULL, 0, &dwBytesNeeded );
PRINTER_INFO_2* p2 = (PRINTER_INFO_2*)GlobalAlloc( GPTR, dwBytesNeeded);
if( GetPrinter( hPrinter, 2, (LPBYTE)p2, dwBytesNeeded, &dwBytesReturned) == 0 )
{
GlobalFree( p2 );
ClosePrinter( hPrinter );
return FALSE;
}
p2->pDevMode->dmFields |= DM_ORIENTATION;
p2->pDevMode->dmOrientation = Orientation;
if( SetPrinter(
hPrinter, // handle to printer object
2, // information level
(LPBYTE) p2, // printer data buffer
0 // printer-state command
) == 0 )
{
GlobalFree( p2 );
ClosePrinter( hPrinter );
return FALSE;
}
ClosePrinter( hPrinter );
// Allocate a global handle for DEVMODE
return TRUE;
}
------------------------------------------------------
Sorry if I am in the wrong terrain.