made a small correction in the first
xprint cancel before xprint close, works great for getting the fax windows printer setting
this program just grew and grew, one function is written in totally funk.
but it works, i just could not figure out how to display my results
if there is anything else to add let me know, but i hope that you have the code to get the info on the printer.
you are going to want to forget about the first program after you see this one.
Code:
'wprtpaper.bas 'program acquires windows only device printer paper types and trays 'compiled with powerbasic pbwin9.02 ' #PBFORMS CREATED V1.51 '------------------------------------------------------------------------------ ' The first line in this file is a PB/Forms metastatement. ' It should ALWAYS be the first line of the file. Other ' PB/Forms metastatements are placed at the beginning and ' end of "Named Blocks" of code that should be edited ' with PBForms only. Do not manually edit or delete these ' metastatements or PB/Forms will not be able to reread ' the file correctly. See the PB/Forms documentation for ' more information. ' Named blocks begin like this: #PBFORMS BEGIN ... ' Named blocks end like this: #PBFORMS END ... ' Other PB/Forms metastatements such as: ' #PBFORMS DECLARATIONS ' are used by PB/Forms to insert additional code. ' Feel free to make changes anywhere else in the file. '------------------------------------------------------------------------------ #COMPILE EXE #DIM ALL '------------------------------------------------------------------------------ ' ** Includes ** '------------------------------------------------------------------------------ #PBFORMS BEGIN INCLUDES #IF NOT %DEF(%WINAPI) #INCLUDE "WIN32API.INC" #ENDIF #INCLUDE "PBForms.INC" #PBFORMS END INCLUDES '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Constants ** '------------------------------------------------------------------------------ #PBFORMS BEGIN CONSTANTS %IDD_DIALOG1 = 101 %IDC_TEXTBOX1 = 999 %IDC_BUTTON1 = 1001 %IDC_BUTTON2 = 1002 %iDC_BUTTON5 = 1005 #PBFORMS END CONSTANTS GLOBAL gstextbox AS STRING GLOBAL gstextboxold AS STRING GLOBAL gstemp AS STRING GLOBAL gltemp AS LONG GLOBAL gltemp2 AS LONG GLOBAL hDlg AS DWORD '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Declarations ** '------------------------------------------------------------------------------ DECLARE CALLBACK FUNCTION ShowDIALOG1Proc() DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG FUNCTION getprinterpapertypes() AS LONG LOCAL stemp0 AS STRING LOCAL stemp1 AS STRING LOCAL stemp2 AS STRING LOCAL stemp3 AS STRING LOCAL stemp4 AS STRING LOCAL stemp5 AS STRING LOCAL stemp6 AS STRING LOCAL stemp7 AS STRING LOCAL stemp8 AS STRING LOCAL stemp9 AS STRING LOCAL stemp10 AS STRING LOCAL stemp11 AS STRING LOCAL stemp12 AS STRING LOCAL stemp13 AS STRING LOCAL i AS LONG LOCAL j AS LONG LOCAL k AS LONG LOCAL lcopycount AS LONG LOCAL llines AS LONG LOCAL lorientation AS LONG LOCAL lduplexstatus AS LONG LOCAL lpaper AS LONG LOCAL ltray AS LONG LOCAL lquality AS LONG LOCAL sprintername AS STRING LOCAL xWidth!,xHeight!,xLeft!, xTop!, xRight!, xBottom!, x&,y& REM get the previous text on the screen and format it before adding the new printer's info CONTROL GET TEXT HDLG,%IDC_TEXTBOX1 TO gstextbox gstextbox=TRIM$(gstextbox) REM remove extra blank LINES AND ANY spaces prior AND after ANY CRLF WHILE INSTR(gstextbox, " "+$CRLF) REPLACE " "+$CRLF WITH $CRLF IN gstextbox WEND WHILE INSTR(gstextbox, $CRLF+" ") REPLACE $CRLF+" " WITH $CRLF IN gstextbox WEND WHILE INSTR(gstextbox, $CRLF+$CRLF) REPLACE $CRLF+$CRLF WITH $CRLF IN gstextbox WEND IF gstextbox=$CRLF THEN gstextbox="" REM CRLF FROM the beginning OF the TEXTBOX IF it exist IF LEN(gstextbox)>1 THEN IF LEFT$(gstextbox,2)=$CRLF THEN gstextbox=RIGHT$(gstextbox,LEN(gstextbox)-2) END IF END IF REM get the selected printers info- paper types and paper trays ERRCLEAR XPRINT ATTACH CHOOSE IF ERR OR XPRINT$="" THEN MSGBOX "No printer choosen",%MB_OK,"Message" EXIT FUNCTION END IF sprintername=XPRINT$ REM get the demographics from the printer ERRCLEAR XPRINT GET PAPERS TO stemp1 IF ERR THEN stemp1="" ERRCLEAR XPRINT GET TRAYS TO stemp2 IF ERR THEN stemp2="" ERRCLEAR XPRINT GET CLIENT TO xwidth!,xheight! 'get the printable width and height IF ERR THEN xwidth!=0!:xheight!=0! ERRCLEAR XPRINT GET MARGIN TO xleft!, xtop!, xright!, xbottom! 'margins IF ERR THEN xleft!=0!:xtop!=0!:xright!=0!:xbottom!=0! ERRCLEAR XPRINT GET PPI TO x&,y& 'pixels per inch IF ERR THEN x&=0&:y&=0& ERRCLEAR XPRINT GET LINES TO llines IF ERR THEN llines=-1 ERRCLEAR XPRINT GET COPIES TO lcopycount IF ERR THEN lcopycount=-1 ERRCLEAR XPRINT GET ORIENTATION TO lorientation IF ERR THEN lorientation=-1 ERRCLEAR XPRINT GET QUALITY TO lquality IF ERR THEN lquality=-1 ERRCLEAR XPRINT GET DUPLEX TO lduplexstatus IF ERR THEN lduplexstatus=-1 ERRCLEAR XPRINT GET PAPER TO lpaper IF ERR THEN lpaper=-1 ERRCLEAR XPRINT GET TRAY TO ltray IF ERR THEN ltray=-1 XPRINT CANCEL 'cancel so printer wont try to print just now XPRINT CLOSE stemp4="points per inch x="+TRIM$(STR$(x&))+" y="+TRIM$(STR$(y&))+$CRLF+_ "---------------------------end of resolution------------------------------------"+$CRLF+_ "margins in inches left="+TRIM$(STR$(xleft!/x&))+" right="+TRIM$(STR$(xright!/x&))+" top="+TRIM$(STR$(xtop!/y&))+" bottom="+TRIM$(STR$(xBottom!/y&))+$CRLF+_ "margins in points left="+TRIM$(STR$(xleft!))+" right="+TRIM$(STR$(xright!))+" top="+TRIM$(STR$(xtop!))+" bottom="+TRIM$(STR$(xBottom!))+$CRLF+_ "printable size in inches width="+TRIM$(STR$(xwidth!/x&))+" height="+TRIM$(STR$(xheight!/y&))+$CRLF+_ "printable size in points width="+TRIM$(STR$(xwidth!))+" height="+TRIM$(STR$(xheight!))+$CRLF+_ "computed paper size = "+TRIM$(STR$((xwidth!/x&)+((xleft!+xright!)/x&)))+" x "+TRIM$(STR$((xheight!/y&)+ ((xtop!+xBottom!)/y&) ))+$CRLF+_ "---------------------------end of dimensions------------------------------------" IF llines >=1 THEN stemp5="Lines per page is "+TRIM$(STR$(llines)) ELSE stemp5="Lines per page is unknown" END IF IF lcopycount >=1 THEN stemp6="Copies to make is "+TRIM$(STR$(lcopycount)) ELSE stemp6="Copies to make is unknown" END IF IF lorientation >-1 THEN stemp7="Print orientation is "+TRIM$(STR$(lorientation))+" usual 1=portrait 2=landscape" ELSE stemp7="Print orientation is unknown" END IF IF lquality >-1 THEN stemp8="Print quality is "+TRIM$(STR$(lquality))+" usual 1=draft 2=low 3=medium 4=high" ELSE stemp8="Print quality is unknown" END IF IF lduplexstatus >-1 THEN stemp9="Duplex setting is "+TRIM$(STR$(lduplexstatus))+" usual 1=oneside 2=flip on vertical edge 3=flip on horiz. edge" ELSE stemp9="Duplex setting is unknown" END IF IF lpaper<0& THEN stemp10="Paper type is unknown" ELSE j=PARSECOUNT(stemp1,",") DIM a(1 TO j) AS STRING PARSE stemp1, a(),"," FOR i=1 TO J-1 STEP 2 a(i)=TRIM$(a(i)) IF a(i)=TRIM$(STR$(lpaper)) THEN stemp10="Paper type is "+a(i)+" "+a(i+1):EXIT FOR NEXT i END IF stemp11="" IF lpaper>-1 THEN k=0& FOR i=1 TO J-1 STEP 2 IF LEN(a(i+1)) >=K THEN K=LEN(a(i+1)) NEXT i FOR i=1 TO J-1 STEP 2 a(i+1)=LEFT$(a(i+1)+STRING$(K+3," "),K+3) NEXT i stemp0="" FOR i=1 TO J-1 STEP 2 stemp0=stemp0+RIGHT$(" "+a(i),6)+"="+a(i+1) IF LEN(stemp0)>70 THEN stemp11=stemp11+RTRIM$(stemp0)+$CRLF:stemp0="" NEXT i stemp11=stemp11+stemp0+$CRLF+"---------------------------end of paper type listing----------------------------" END IF IF ltray<0& THEN stemp12="Paper tray is unknown" ELSE j=PARSECOUNT(stemp2,",") DIM b(1 TO j) AS STRING PARSE stemp2, b(),"," FOR i=1 TO J-1 STEP 2 b(i)=TRIM$(b(i)) IF b(i)=TRIM$(STR$(ltray)) THEN stemp12="Paper tray is "+b(i)+" "+b(i+1):EXIT FOR NEXT i END IF stemp13="" IF ltray>-1 THEN k=0& FOR i=1 TO J-1 STEP 2 IF LEN(b(i+1)) >=K THEN K=LEN(b(i+1)) NEXT i FOR i=1 TO J-1 STEP 2 b(i+1)=LEFT$(b(i+1)+STRING$(K+3," "),K+3) NEXT i stemp0="" FOR i=1 TO J-1 STEP 2 stemp0=stemp0+RIGHT$(" "+b(i),6)+"="+b(i+1) IF LEN(stemp0)>70 THEN stemp13=stemp13+RTRIM$(stemp0)+$CRLF:stemp0="" NEXT i stemp13=stemp13+stemp0+$CRLF+"---------------------------end of paper tray listing----------------------------" END IF gstextbox=STRING$(80,"=")+$CRLF+"Printer name - "+sprintername+$CRLF+STRING$(80,"=")+$CRLF+_ stemp5+$CRLF+stemp6+$CRLF+stemp7+$CRLF+stemp8+$CRLF+stemp9+$CRLF+_ stemp10$+$CRLF+stemp12+$CRLF+"---------------------------end of current settings------------------------------"+$CRLF+_ stemp4+$CRLF+stemp11+$CRLF+_ stemp13+$CRLF+gstextbox WHILE INSTR(gstextbox, $CRLF+$CRLF) REPLACE $CRLF+$CRLF WITH $CRLF IN gstextbox WEND CONTROL SET TEXT HDLG,%IDC_TEXTBOX1, gstextbox CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 END FUNCTION #PBFORMS DECLARATIONS '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Main Application Entry Point ** '------------------------------------------------------------------------------ FUNCTION PBMAIN() gstextbox="" ShowDIALOG1 %HWND_DESKTOP END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** CallBacks ** '------------------------------------------------------------------------------ CALLBACK FUNCTION ShowDIALOG1Proc() SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %IDC_TEXTBOX1 CASE %IDC_BUTTON1 REM GET papertypes FROM printer IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN getprinterpapertypes() END IF CASE %IDC_BUTTON2 REM CLEAR the TEXT IN textbox1 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL SET TEXT HDLG,%IDC_TEXTBOX1, "" CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 END IF CASE %IDC_BUTTON5 REM send text to clipboard IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL GET TEXT HDLG,%IDC_TEXTBOX1 TO gstemp IF gstemp<>"" THEN FOR gltemp=1& TO 100& CLIPBOARD RESET, gltemp2 IF gltemp2 THEN EXIT FOR SLEEP 20 NEXT gltemp FOR gltemp=1 TO 100& CLIPBOARD SET TEXT gstemp,gltemp2 IF gltemp2 THEN EXIT FOR SLEEP 30 NEXT gltemp CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 END IF END IF END SELECT END SELECT END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Dialogs ** '------------------------------------------------------------------------------ FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG #PBFORMS BEGIN DIALOG %IDD_DIALOG1->-> ' LOCAL hDlg AS DWORD LOCAL hFont1 AS DWORD DIALOG NEW hParent, "Retreive paper types and trays from a windows printer", _ 42, 47, 645, 270, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR _ %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR _ %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _ %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR, TO hDlg CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 0, 26, 645, 239, %WS_CHILD _ OR %WS_VISIBLE OR %WS_HSCROLL OR %WS_VSCROLL OR _ %ES_LEFT OR %ES_MULTILINE OR %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL OR _ %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Select printer to get " + _ "available paper types and trays", 10, 5, 200, 15,_ %WS_CHILD OR %WS_VISIBLE OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "Clear all", 450, 5, 36, 15,_ %WS_CHILD OR %WS_VISIBLE OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD BUTTON, hDlg, %IDC_BUTTON5, "Send text to clipboard", 250, 5, 100, 15,_ %WS_CHILD OR %WS_VISIBLE OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING hFont1 = PBFormsMakeFont("Courier", 10, 400, %FALSE, %FALSE, %FALSE, _ %ANSI_CHARSET) CONTROL SEND hDlg, %IDC_TEXTBOX1, %WM_SETFONT, hFont1, 0 #PBFORMS END DIALOG DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt #PBFORMS BEGIN CLEANUP %IDD_DIALOG1 DeleteObject hFont1 #PBFORMS END CLEANUP FUNCTION = lRslt END FUNCTION '------------------------------------------------------------------------------
Leave a comment: