a quick and dirty program that gets the windows device printer paper types and trays.
program is designed to acquire the info then send the gathered info to the clipboard upon the users instructions for another program to view,print, or whatever.
thanks PB team for having these easy functions
here is the program listing
i am sure this could be done better but it serves my purpose of getting the paper types and trays along with the assigned number that sets these properties.
i do not know how to get the printer driver descriptions for the printers but a person can easily type it into the textbox after acquiring the printer info.
maybe some other energetic sole will carry the ball all the way to more detailed info of a windows printer.
program is designed to acquire the info then send the gathered info to the clipboard upon the users instructions for another program to view,print, or whatever.
thanks PB team for having these easy functions
Code:
XPRINT GET TRAY XPRINT GET TRAYS XPRINT GET PAPER XPRINT GET PAPERS rem also the working partners to these commands are XPRINT SET TRAY XPRINT SET PAPER
i am sure this could be done better but it serves my purpose of getting the paper types and trays along with the assigned number that sets these properties.
i do not know how to get the printer driver descriptions for the printers but a person can easily type it into the textbox after acquiring the printer info.
maybe some other energetic sole will carry the ball all the way to more detailed info of a windows printer.
Code:
'wprtpaper.bas 'program acquires windows only device printer paper types and trays #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 stemp1 AS STRING LOCAL stemp2 AS STRING LOCAL sprintername AS STRING 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 XPRINT ATTACH CHOOSE IF XPRINT$="" THEN MSGBOX ("No printer choosen") EXIT FUNCTION END IF sprintername=XPRINT$ XPRINT GET PAPERS TO stemp1 XPRINT GET TRAYS TO stemp2 XPRINT CLOSE gstextbox= STRING$(80,"=")+$CRLF+_ "Printer name - "+sprintername+$CRLF+STRING$(80,"=")+$CRLF+_ "("+STEMP1+")"+$CRLF+".......end of printer paper type listing......."+$CRLF+_ "("+STEMP2+")"+$CRLF+".......end of printer paper tray listing......."+$CRLF+_ gstextbox 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 '------------------------------------------------------------------------------
Comment