Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Specify printer tray or bin to print report to programma
Message
From
30/07/2003 13:11:02
 
 
To
10/07/2003 11:22:41
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
00808875
Message ID:
00814998
Views:
34
Thanks to Simon's generous sharing of his code, I am able to select a paper tray for all printers now. This works in Windows XP using VFP8. Can anyone think of any reason why it would not work in previous versions of windows or previous versions of VFP? Anyone willing to test this code using Win95/98/2K?
*Courtesy of Simon Clark, Universal Thread, July 2003
*put a DEFAULTSOURCE=<bin number> in the EXPR column 
*of the FRX row with OBJTYPE=53 after selection

oform=CREATEOBJECT('papertrayform')
oform.show()
READ EVENTS
RETURN

DEFINE CLASS papertrayform AS form


	Top = 0
	Left = 1
	Height = 365
	Width = 631
	DoCreate = .T.
	Caption = "Paper Tray Selection Form"
	Name = "PAPERTRAYS"
	DIMENSION paperbins[1,4]


	ADD OBJECT list1 AS listbox WITH ;
		FontName = "Courier New", ;
		FontSize = 9, ;
		BoundColumn = 1, ;
		RowSourceType = 6, ;
		RowSource = 'LEFT(trays.pname,45)+"  "+left(trays.pbin,20)+"  "+LEFT(trays.pbinno,20)+"  "+LEFT(trays.pport,10)', ;
		ControlSource = "m.selection", ;
		Height = 300, ;
		ColumnLines = .T., ;
		Left = 8, ;
		MultiSelect = .F., ;
		TabIndex = 10, ;
		Top = 39, ;
		Width = 612, ;
		Name = "List1"


	ADD OBJECT label1 AS label WITH ;
		Caption = "Press <ENTER> to select a paper tray or Double-Click on any item to select it", ;
		Height = 17, ;
		Left = 8, ;
		Top = 11, ;
		Width = 580, ;
		Name = "Label1"


	PROCEDURE buf2word
		*PROCEDURE SYLSTLEN_buf2word && Convert BUF to WORD
		PARAMETERS QQbuffer
		* ---INTERFACE---
		PRIVATE ALL LIKE QQ*
		* IMPORTS:
		*   A buffer/pointer
		*
		* EXPORTS:
		*   The passed in buffer converted to a word format
		*

		* ---INITIALISE---
		QQudfRet    = ASC(SUBSTR(QQbuffer, 1,1)) + ASC(SUBSTR(QQbuffer, 2,1)) * 256

		RETURN QQudfRet
	ENDPROC


	PROCEDURE Init
		IF USED('trays')
			USE IN trays
		ENDIF
		IF FILE('trays.dbf')
			DELETE FILE trays.dbf
		ENDIF
		CLEAR
		DODEFAULT()
		SET SAFETY OFF
		*For the FRX's it easy, you just put a DEFAULTSOURCE=<bin number> in the EXPR column
		*of the FRX row with OBJTYPE=53 (same for DUPLEX= by the way...).

		#DEFINE GMEM_FIXED   0
		#DEFINE DC_PAPERS     2
		#DEFINE DC_BINS       6
		#DEFINE DC_SIZE       8
		#DEFINE DC_VERSION    10
		#DEFINE DC_BINNAMES   12
		#DEFINE DC_PAPERNAMES 16
		#DEFINE DEFAULT_VALUES 0

		* Needed to interrogate the printer driver for paper bins/trays
		DECLARE INTEGER DeviceCapabilities IN winspool.drv;
		STRING pDevice, STRING pPort, INTEGER fwCapability,;
		STRING @pOutput, INTEGER pDevMode

		=APRINTERS(pPrinters)
		FOR ip = 1 TO ALEN(pPrinters,1)
			*QQprintername=SET("PRINTER",2) && windows own default printer
			QQprintername=pPrinters(ip,1)
			pPort=ALLTRIM(pPrinters(ip,2))
			*   Windows API declarations
			* Hook in here to determine the paper trays and their bin numbers
			* Update the GVoPrintJob object with the results
			QQbinBfr   = REPLICATE(CHR(0), 16384)
			QQbinBf2   = REPLICATE(CHR(0), 1024)
			* provide valid printer and port names
			*	pPort="HPJD1"
			QQnCount = DeviceCapabilities(QQprintername, pPort, DC_BINNAMES, @QQbinBfr, 0)
			QQnCnt2  = DeviceCapabilities(QQprintername, pPort, DC_BINS, @QQbinBf2, 0)
			*    QQnCount = DeviceCapabilities(QQprintername, "LPT1", DC_BINNAMES, @QQbinBfr, 0)
			*    QQnCnt2  = DeviceCapabilities(QQprintername, "LPT1", DC_BINS, @QQbinBf2, 0)
			* Set the number of bins available on this printer property
			p_bin_count=IIF(QQnCount<0, 0, QQnCount)
			*GVoPrintJob.p_bin_count = iif(QQnCount<0, 0, QQnCount)
			*    if GVoPrintJob.p_Bin_Count > 0
			IF p_bin_count>0
				* each string buffer is 24 characters long, terminated with a NULL / chr(0)
				* and contains the name of a paper bin
				*dimension GVoPrintJob.p_bin_names[QQnCount], GVoPrintJob.p_bin_labels[QQnCount]
				DIMENSION p_bin_names[QQnCount], p_bin_labels[QQnCount]
				FOR QQindex=1 TO QQnCount
					QQbinName = SUBSTR(QQbinBfr, (QQindex-1)*24+1, 24) + CHR(0)
					QQbinName = SUBSTR(QQbinName, 1, AT(CHR(0), QQbinName)-1)
					*GVoPrintJob.
					p_bin_names[QQindex] = QQbinName
				ENDFOR
				QQptr   = 1
				FOR QQindex=1 TO QQnCnt2*2 STEP 2
					QQbinNum = THISFORM.buf2word(SUBSTR(QQbinBf2, QQindex, 2))

					*            GVoPrintJob.p_bin_labels[QQptr] = QQbinNum
					p_bin_labels[QQptr] = QQbinNum
					QQptr   = QQptr + 1
				ENDFOR
			ENDIF
			IF ALEN(p_bin_names,1)=ALEN(p_bin_labels,1)
				FOR i = 1 TO ALEN(p_bin_names,1)
					IF TYPE('thisform.paperbins')="U"
						DIMENSION THISFORM.paperbins(i,4)
					ELSE
						DIMENSION THISFORM.paperbins(ALEN(THISFORM.paperbins,1)+1,4)
					ENDIF
					THISFORM.paperbins(ALEN(THISFORM.paperbins,1),1)=QQprintername
					THISFORM.paperbins(ALEN(THISFORM.paperbins,1),2)=p_bin_names(i)
					THISFORM.paperbins(ALEN(THISFORM.paperbins,1),3)=p_bin_labels(i)
					THISFORM.paperbins(ALEN(THISFORM.paperbins,1),4)=pPort
				ENDFOR
			ENDIF
		ENDFOR
		*SET STEP ON
		*	LIST MEMORY LIKE p_bin_names
		*	LIST MEMORY LIKE p_bin_labels
		*	LIST MEMORY LIKE thisform.paperbins
		nlen1=0
		nlen2=0
		nlen3=4
		nlen4=0
		=ACOPY(THISFORM.paperbins,paperbins)
		FOR i = 1 TO ALEN(paperbins,1)
			IF TYPE('paperbins(i,1)')<>"L"
				IF LEN(ALLTRIM(paperbins(i,1)))>nlen1
					nlen1=LEN(ALLTRIM(paperbins(i,1)))
				ENDIF
			ENDIF
			IF TYPE('paperbins(i,2)')<>"L"
				IF LEN(ALLTRIM(paperbins(i,2)))>nlen2
					nlen2=LEN(ALLTRIM(paperbins(i,2)))
				ENDIF
			ENDIF
		*!*		IF TYPE('paperbins(i,3)')<>"L"
		*!*			IF LEN(ALLTRIM(paperbins(i,3)))>nlen3
		*!*				nlen3=LEN(ALLTRIM(paperbins(i,3)))
		*!*			ENDIF
		*!*		ENDIF
			IF TYPE('paperbins(i,4)')<>"L"
				IF LEN(ALLTRIM(paperbins(i,4)))>nlen4
					nlen4=LEN(ALLTRIM(paperbins(i,4)))
				ENDIF
			ENDIF
		ENDFOR
		IF nlen1=0
			nlen1=1
		ENDIF
		IF nlen2=0
			nlen2=1
		ENDIF
		IF nlen4=0
			nlen4=1
		ENDIF
		CREATE CURSOR trays (pname c(nlen1), pbin c(nlen2), pbinno c(nlen3), pPort c(nlen4))
		SELE trays
		FOR i = 1 TO ALEN(paperbins,1)
			IF TYPE('paperbins(i,1)')<>"L"
				SELE trays
				APPEND BLANK
		*!*			IF i > 1
		*!*				ta=i-1
		*!*				IF TYPE('paperbins(i,1)')=TYPE('paperbins(ta,1)') .and. paperbins(i,1) <> paperbins(ta,1)
		*!*					REPLACE trays.pname WITH ALLTRIM(paperbins(i,1))
		*!*				ELSE
		*!*					IF TYPE('paperbins(i,1)')!=TYPE('paperbins(ta,1)')
		*!*				 		REPLACE trays.pname WITH ALLTRIM(paperbins(i,1))
		*!*					ENDIF
		*!*				ENDIF
		*!*			ENDIF
				REPLACE trays.pname WITH ALLTRIM(paperbins(i,1))
				IF TYPE('paperbins(i,2)')<>"L"
					REPLACE trays.pbin WITH ALLTRIM(paperbins(i,2))
				ENDIF
				IF TYPE('paperbins(i,3)')<>"L"
					REPLACE trays.pbinno WITH ALLTRIM(STR(paperbins(i,3)))
				ENDIF
				IF TYPE('paperbins(i,4)')<>"L"
					REPLACE trays.pPort WITH ALLTRIM(paperbins(i,4))
				ENDIF
			ENDIF
		ENDFOR
		GO TOP
		THISFORM.List1.REFRESH
	ENDPROC

	PROCEDURE UNLOAD
		CLEAR EVENTS
	ENDPROC

	PROCEDURE list1.DblClick
			IF USED('TRAYS') .AND. RECCOUNT('TRAYS')>0 .AND. !EOF('TRAYS')
				mchoice=trays.pbinno
			ENDIF
			MESSAGEBOX('You chose: '+CHR(13)+CHR(13);
				+"Printer: "+ALLTRIM(trays.pname)+ CHR(13);
				+"Tray: "+trays.pbin+CHR(13);
				+"Bin No: "+trays.pbinno+CHR(13),0,'Paper Tray Selectioin')
			NODEFAULT
			THISFORM.RELEASE()
	ENDPROC


	PROCEDURE list1.KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl

		IF LASTKEY() = 13 .or. LASTKEY() = -9
			nKeyCode = 13
			nShiftAltCtrl = 0
		ENDIF

		mchoice=""
		DO CASE 

		CASE nKeyCode = 13 .or. nkeyCode = -9 

			IF USED('TRAYS') .AND. RECCOUNT('TRAYS')>0 .AND. !EOF('TRAYS')
				mchoice=trays.pbinno
			ENDIF
			MESSAGEBOX('You chose: '+CHR(13)+CHR(13);
				+"Printer: "+ALLTRIM(trays.pname)+ CHR(13);
				+"Tray: "+trays.pbin+CHR(13);
				+"Bin No: "+trays.pbinno+CHR(13),0,'Paper Tray Selectioin')
			NODEFAULT
			THISFORM.RELEASE()

		OTHERWISE

			mchoice=""
			DODEFAULT()

		ENDCASE
	ENDPROC


	PROCEDURE list1.Refresh
		IF !USED('trays') .OR. RECCOUNT('trays')=0
			THIS.ENABLED=.F.
		ELSE
			THIS.ENABLED=.T.
		ENDIF
		DODEFAULT()
	ENDPROC


ENDDEFINE
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform