Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Setting Printer Properties Beta Testers Needed
Message
From
22/09/2005 18:37:21
 
General information
Forum:
Visual FoxPro
Category:
Third party products
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01050441
Message ID:
01052214
Views:
13
Barbara--

Not too sure what you are doing here, but you might take a look at Win32 documentation on the DocumentProperties and DeviceCapabilities functions and in particular the DEVMODE data structure. The DEVMODE data structure defines the capabilities and settings for the printer. This structure can be different based on the printer manufacturer, so you first make a call to DocumentProperties to get the size, then subsequent calls to get and set the values. In MSDN, there is a recommended way to determine and set the parameters. I developed the following program based on the MSDN steps to be able to set the page orientation (note that the binary procedures were copied from APIConvert.prg found on the UT) for a printer:
*-*******************************************************************************************************
*-* pcPrinterName  - text value returned by SET("printer", 3)
*-* pnOrientation  - 1=portrait; 2=landscape
*-*
FUNCTION GetDevMode
LPARAMETERS pcPrinterName,pnOrientation
LOCAL lcPrinterName, lhPrinter, lcDevModeInput, lcDevModeOutput, lnMode, lhWnd, lnError, lnOrientation
LOCAL lnSizeOf, lcOrientation, lcDMFields, lnDMFields
DECLARE INTEGER DocumentProperties IN winspool.drv INTEGER lhWnd, INTEGER lhPrinter, STRING pcPrinterName,;
        STRING @lcDevModeOutput, STRING @lcDevModeInput, INTEGER lnMode
DECLARE INTEGER OpenPrinter  IN winspool.drv STRING pcPrinterName, INTEGER @ lhPrinter, INTEGER lnDefault
DECLARE INTEGER ClosePrinter IN winspool.drv INTEGER lhPrinter
DECLARE INTEGER GetLastError IN kernel32

*-*	Constants for DEVMODE
#DEFINE CCHFORMNAME        32
#DEFINE CCHDEVICENAME      32
#DEFINE DM_FORMNAME        0x10000
#DEFINE DM_ORIENTATION     0x1
#DEFINE DM_PAPERSIZE       0x2
#DEFINE DM_PAPERLENGTH     0x4
#DEFINE DM_PAPERWIDTH      0x8

*-*	Constants for DocumentProperties() call
#DEFINE DM_MODIFY          8
#DEFINE DM_IN_BUFFER       DM_MODIFY
#DEFINE DM_COPY            2
#DEFINE DM_OUT_BUFFER      DM_COPY
#DEFINE DMORIENT_PORTRAIT  1
#DEFINE DMORIENT_LANDSCAPE 2

lhPrinter = 0
lcDevModeInput  = ""
lcDevModeOutput = ""
IF PARAMETERS() < 2
	WAIT WINDOW "Invalid call to procedure" NOWAIT
	RETURN ""
ENDIF
IF pnOrientation = DMORIENT_PORTRAIT .OR. pnOrientation = DMORIENT_LANDSCAPE
	IF OpenPrinter(pcPrinterName,@lhPrinter,0) > 0
*-*		Get the sizeof DevMode structure for selected printer
		lnSizeOf = DocumentProperties(0,lhPrinter,pcPrinterName,@lcDevModeOutput,@lcDevModeInput,0)
		IF lnSizeOf < 0
			lnError = GetLastError()
			lcDevModeInput = ""
		ELSE
*-*			Allocate memory for the DevMode structure
			lcDevModeOutput = REPLICATE(" ",lnSizeOf)
			lcDevModeInput  = lcDevModeOutput
*-*			Get the current DevMode structure for selected printer
			DocumentProperties(0,lhPrinter,pcPrinterName,@lcDevModeOutput,@lcDevModeInput,DM_OUT_BUFFER)
*-*			Set the orientation setting in the DevMode structure
			lcOrientation  = APIShortToChar(pnOrientation)
			lcDevModeInput = STUFF(lcDevModeOutput,45,2,lcOrientation)
*-*			Set flag for changes to DevMode structure
			lnDMFields = APICharToLong(SUBSTR(lcDevModeOutput,41,4))
			lcDMFields = APILongToChar(DM_ORIENTATION)
			lcDevModeInput = STUFF(lcDevModeInput,41,4,lcDMFields)
*-*			Update the DevMode structure with new settings
			lnMode = BITOR(DM_OUT_BUFFER,DM_IN_BUFFER)
			DocumentProperties(0,lhPrinter,pcPrinterName,@lcDevModeInput,@lcDevModeInput,lnMode)
		ENDIF
		ClosePrinter(lhPrinter)
	ELSE
		WAIT WINDOW "Unable to open printer" NOWAIT
	ENDIF
ELSE
	WAIT WINDOW "Invalid Orientation setting in parameter" NOWAIT
ENDIF
RETURN lcDevModeInput
ENDFUNC


*====================================================================
* Converts a 16-bit integer variable (WORD, SHORT) into a binary 
* string.
*====================================================================
PROCEDURE APIShortToChar
LPARAMETER tnShort
	LOCAL lcString
	lcString = SPACE(2)
	DECLARE RtlMoveMemory IN Win32API AS __ShortToChar STRING@, SHORT@, INTEGER
	__ShortToChar(@lcString,@tnShort,2)
RETURN m.lcString


*====================================================================
* Converts a binary string into a 16-bit unsigned integer.
*====================================================================
PROCEDURE APICharToShort
LPARAMETER tcString
	LOCAL lnShort
	lnShort = 0
	IF TYPE("Version(4)") == "C"
		DECLARE RtlMoveMemory in Win32API as __CharToShort SHORT@, STRING@, INTEGER
	ELSE
		DECLARE RtlMoveMemory in Win32API as __CharToShort INTEGER@, STRING@, INTEGER
	ENDIF
	__CharToShort( @lnShort, @tcString, 2 )
	IF TYPE("Version(4)") == "C"
		IF m.lnShort < 0
			lnShort = m.lnShort + 2^16
		ENDIF
	ENDIF
RETURN m.lnShort


*====================================================================
* Converts a binary string into a 16-bit signed integer.
*====================================================================
PROCEDURE APICharToSShort
LPARAMETER tcString
	LOCAL lnShort
	lnShort = 0
	IF TYPE("Version(4)") == "C"
		DECLARE RtlMoveMemory IN Win32API AS __CharToSShort SHORT@, STRING@, INTEGER
	ELSE
		DECLARE RtlMoveMemory IN Win32API AS __CharToSShort INTEGER@, STRING@, INTEGER
	ENDIF
	__CharToSShort( @lnShort, @tcString, 2 )
	IF !TYPE("Version(4)") == "C"
		IF m.lnShort >= 2^15
			lnShort = m.lnShort - 2^16
		ENDIF
	ENDIF
RETURN m.lnShort


*====================================================================
* Converts a 32-bit integer variable (LONG) into a binary string.
*====================================================================
PROCEDURE APILongToChar
LPARAMETER tnLong
	LOCAL lcString
	lcString = SPACE(4)
	DECLARE RtlMoveMemory IN Win32API AS __LongToChar STRING@, LONG@, INTEGER
	__LongToChar(@lcString, @tnLong, 4 )
RETURN m.lcString


*====================================================================
* Converts a binary string into a 32-bit unsigned integer.
*====================================================================
PROCEDURE APICharToLong
LPARAMETER tcString
	LOCAL lnLong
	lnLong = 0
	DECLARE RtlMoveMemory IN Win32API AS __CharToLong LONG@, STRING@, INTEGER
	__CharToLong( @lnLong, @tcString, 4 )
	IF m.lnLong < 0
		lnLong = m.lnLong + 2^32
	ENDIF
RETURN m.lnLong
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform