home *** CD-ROM | disk | FTP | other *** search
Wrap
PPRTR.DLL copyright 1993 Paul F. Poellinger ------------------------------------------------------------------- Included: PPRTR DLL The real deal READ ME self-reference (this) PPRTR FRM .. \ Visual Basic PPRTR MAK ..> (version 2.0) PPRTR BAS .. / Example of PPrtr functions PPGLOBAL TXT VB constants PPRTR LIB Import library for C PRINT TXT constant definitions from C header file DEVCAP TXT device cap definitions from C hdr file functions: PPrtr -- allows retrieval or change to any attribute of the default printer DefPrtr -- allows you to find out or change the default printer Prtrs -- returns semi-colon delimeted list of available active printers PrtrCap -- returns structure (VB type) containing default printer device capabilities GetPrtr -- returns the name of the current default printer ----------------------------------------------------------------------- function prototypes: ( in C format ) : int FAR PASCAL PPrtr (HWND hwndx, int selection, int NewValue, int action); int FAR PASCAL Prtrs (LPSTR szActives); int FAR PASCAL DefPrtr (LPSTR szNewPrinter, LPSTR szOldPrinter); int FAR PASCAL GetPrtr (LPSTR szPrtr); int FAR PASCAL GetPort (LPINT szPort); int FAR PASCAL PrtrCap (LPINT nDevCap); ----------------------------------------------------------------------- function definitions: ( in Visual Basic format ) : ******************************** PPrtr ********************************** Declare Function PPrtr Lib "PPRTR.DLL" (ByVal hWnd As Integer, ByVal ppSelection As Integer, ByVal PPNewValue As Integer, ByVal ppAction As Integer) As Integer where: hWnd ................ is a window handle ppSelection ......... is the selected printer device attribute to get/change. ... NOTE that not all printers support all actions (e.g. my Epson LX-800 doesn't support PaperLength or PaperWidth) ppNewValue .......... is the value to change it to ... (anything will do call is a gimme, no change ) ... see PPGLOBAL.TXT for available values ppAction ............ is the action requested ... 0 = gimme current value ... 1 = change it to ppNewValue returns ......... integer of value of selected attribute before the call ... 996 when the ppSelection is not supported by the default printer driver ... 997 for a bad ppSelection code parameter ... 998 for a bad ppAction code parameter ... 999 when it can't find printer/driver info ppSelection: DM_ORIENTATION = &H1 DM_PAPERSIZE = &H2 DM_PAPERLENGTH = &H4 DM_PAPERWIDTH = &H8 DM_SCALE = &H10 DM_COPIES = &H100 DM_DEFAULTSOURCE = &H200 DM_PRINTQUALITY = &H400 DM_COLOR = &H800 DM_DUPLEX = &H1000 DM_YRESOLUTION = &H2000 DM_TTOPTION = &H4000 Samples: PPrtr(hWnd, DM_PAPERSIZE, PP_UNNEEDED, PP_GIMME)) PPrtr(hWnd, DM_ORIENTATION, PP_UNNEEDED, PP_GIMME)) PPrtr(hWnd, DM_ORIENTATION, DMORIENT_PORTRAIT, PP_CHANGE_IT)) PPrtr(hWnd, DM_PAPERSIZE, DMPAPER_LEGAL, PP_CHANGE_IT)) C programmers...the relavent header file for this call is PRINT.H (in Borland C++) ******************************** DefPrtr *******************************- Declare Function DefPrtr Lib "PPRTR.DLL" (ByVal newone As String, ByVal oldone As String) As Integer where: newone .. is a string corresponding to the right side of the "=" in the [devices] section of WIN.INI for the printer to become the default printer...e.g. [devices] HP LaserJet Series II=HPPCL,LPT1: ^^^^^^^^^^^^^^^^^^^^^ <- this part You can also read the printer name in the control panel printers dialog box. It shows printer names followed by "on xxxx:" where xxxx is a port. Don't use one where it says "on None". HP LaserJet Series II on LPT1: ^^^^^^^^^^^^^^^^^^^^^ <- this part This is case insensitive, but otherwise must be identical. Note: the printer must have been made "active" in the control panel printers applet...it'll show "None" for a port if it's not...e.g. active -> HP LaserJet Series II=HPPCL,LPT1: not ----> HPGL Plotter=MGXHPGL,None Passing this parameter as an empty string or unrecognizable string results in a 998 error, but does return the name of the current printer in the "oldone" parameter...thus, allowing retrieval of the name of the current default printer without changing anything: currentptr$ = String$(255, 0) i = DefPrtr("", currentptr$) where: oldone .. is a string in which the function will return the default printer before your call. Save this for use as "newone" to reset the printer to the prior default printer when and if you desire to do so. Note: in Visual Basic you must pre-load a string which is to be filled by a called function...e.g. oldptr$ = String$(255, 0) i = DefPrtr("HP LaserJet Series II", oldptr$) returns: 0 = successful 999 = Unable to write to WIN.INI ... this is a system problem. 998 = The "newone" printer was not found in [devices] section of WIN.INI ... be sure you've put in all spaces 997 = The "newone" printer was found, but it is not "active"...i.e. its port is "None" Sample: Declare Function DefPrtr Lib "PPRTR.DLL" (ByVal newone As String, ByVal oldone As String) As Integer //---- change to LaserJet --------------------- oldprinter$ = String$(255, 0) i = DefPrtr("HP LaserJet Series II", oldprinter$) //---- . . print to LaserJet . //---- change back to original printer -------- dontcare$ = String$(255, 0) i = DefPrtr(oldprinter$,dontcare$) ******************************** Prtrs *******************************- Declare Function Prtrs Lib "PPRTR.DLL" (ByVal pList As String,) As Integer where: pList ... is a string for the return of a list of available active printers. The list only contains the names of "active" printers. The printer must have been made "active" in the control panel printers applet...it'll show "None" for a port if it's not...e.g. active -> HP LaserJet Series II=HPPCL,LPT1: not ----> HPGL Plotter=MGXHPGL,None Note: in Visual Basic you must pre-load a string which is to be filled by a called function...e.g. plist$ = String$(255, 0) i = Prtrs(plist$) The active printer names are separated by semi-colons (;), e.g. Epson LX-800;HP LaserJet Series II returns ....... 0 if no active printers found, or unable to access [drivers] section in WIN.INI ....... the length of the returned string ******************************** PrtrCap *******************************- Declare Function PrtrCap Lib "PPRTR.DLL" (ndc As DEVCAP) As Integer where: ndc .. is a structure (VB type definition) containing the device capability variable definitions: Type devcap DRIVERVERSION As Integer TECHNOLOGY As Integer ' bits HORZSIZE As Integer VERTSIZE As Integer HORZRES As Integer VERTRES As Integer BITSPIXEL As Integer PLANES As Integer NUMBRUSHES As Integer NUMPENS As Integer NUMMARKERS As Integer NUMFONTS As Integer NUMCOLORS As Integer PDEVICESIZE As Integer CURVECAPS As Integer ' bits LINECAPS As Integer ' bits POLYGONALCAPS As Integer ' bits TEXTCAPS As Integer ' bits CLIPCAPS As Integer ' bits RASTERCAPS As Integer ' bits ASPECTX As Integer ASPECTY As Integer ASPECTXY As Integer LOGPIXELSX As Integer LOGPIXELSY As Integer SIZEPALETTE As Integer NUMRESERVED As Integer COLORRES As Integer End Type See the PPGlobal.txt file for 'bit' field masks; and see the VB example for sample usage. See the windows SDK documentation for explanation of the dev cap fields. Returns 0 always. ******************************** GetPrtr *******************************- Declare Function GetPrtr Lib "PPRTR.DLL" (ByVal DefP As String) As Integer where: DefP .. is a string set up to receive the name of the current default printer. Note: in Visual Basic you must pre-load a string which is to be filled by a called function...e.g. defptr$ = String$(255, 0) i = GetPrtr(defptr$) Returns 0 -- and printer name in the string if successful; if not, string is as you initialized it. ******************************** GetPort *******************************- Declare Function GetPort Lib "PPRTR.DLL" (ByVal DefP As String) As Integer where: DefP .. is a string set up to receive the name of the current default printer port. Note: in Visual Basic you must pre-load a string which is to be filled by a called function...e.g. defptr$ = String$(255, 0) i = GetPort(defptr$) Returns 0 -- and printer name in the string if successful; if not, string is as you initialized it. -------------------------------------------------------------------- This DLL contains, fixes, improves on and replaces PPRTR.ZIP distributed earlier this year. That DLL contained a coding error for the "copies" setting. It has been extensively tested by me and friends, but YMMV. A tip of the pelican's beak to OsoSoft George Campbell who suggested the original idea for this DLL. Hope these are helpful. There are others (see WINP1.1, ORIENT.ZIP, PPFONT.ZIP in the Compuserve MSBASIC forum, Pel*Ican coming soon). You are free to try this DLL for 30 days. If you decide to use it thereafter, you are obligated to send $10 to PAUL POELLINGER 2019 Round Lake Drive Houston, TX 77077 After doing so, you are free to use it in your applications, and to distribute it with such applications, as long as you do not charge separately for the DLL or publish its calling conventions. If you paid for the earlier version, you've paid for this one. I and all those dependent on me thank you. You are free to pass this package on to others or upload it to bulletin boards provided that 1) you do not charge for it above the cost of distribution, and 2) all parts of the package are included (see "included" at the top). Thank you for supporting shareware. ------------------------------------------------------------------- Let me know if you have any trouble or suggestions. Paul Poellinger Compuserve 70732,3576 5-1-93