Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change printer setting within program

Status
Not open for further replies.

fkkchung

Programmer
Oct 12, 2006
4
HK
Hi,

I had been maintaining some fox program code for some time. The codes are written in fox ver 2 (no OOPs involved). As more and more printers are install on the system, we had to install more and more printers on each station with all variations : orientation, paper size. For every new printer installed, we had to make up 4 printers at least for fox programs to use them : L,A4; L,A3, P,A4, P,A3 because fox was not able to change printer settings non interactively with the old coding. Recently I had some codes for API windows calls that can alter printer settings but I had never done anything like that. Can someone please shed a light on this?

The code are as follows :

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;
}

How should I make them usable to fox? How to "call" them from within fox programs. We had been using foxpro ver6 to recompile the old codes but it seems that the 'Help' needs some help itself. Old version of fox had a library of how to use commands but now it seems nowhere to be found in ver6.

Can anyone help me out with this? Tks a lot.
 
There is an easiest way with VFP. Just open your report as a table and change ORIENTATION=??? in the Expr field of the FIRST record.
Code:
USE MyReport.FRX AS ReportTemp IN 0
GO 1
IF IWantPortrait
   lcOrientation = [ORIENTATION=0]
   lcReplaced    = [ORIENTATION=1]
ELSE
   lcOrientation = [ORIENTATION=1]
   lcReplaced    = [ORIENTATION=0]
ENDIF
REPLACE Expr WITH STRTRAN(Expr, lcReplaced, lcOrientation) IN ReportTemp
USE IN SELECT([ReportTemp]0
REPORT FORM MyReport ....
BTW You could use Barbara Peish's Printer Properties (I hope this is the right name)


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top