home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code2 / p_print / read.txt < prev   
Text File  |  1994-07-10  |  20KB  |  419 lines

  1. PPRTR.DLL copyright 1992, 1993, 1994 Paul F. Poellinger, Silent O Software
  2. -------------------------------------------------------------------
  3.                       REVISION HISTORY
  4. -------------------------------------------------------------------
  5. v4.3 -- added code/returns to account for no existing default printer
  6. -------------------------------------------------------------------
  7. v4.2 -- deleted DC created for pprtrcap...was causing memory leakage.
  8.      -- added VER version resource information for install programs.
  9. -------------------------------------------------------------------
  10. v4.1 -- restores "not found" error code 998 for when bad printer
  11.         name is passed to DefPrtr...left out in 4.0 conversion.
  12. -------------------------------------------------------------------
  13. v4.0 -- strings passed from Prtrs, GetPrtr, DefPrtr now contain
  14.         " on xxxx.." where xxxx.. is the port.  Required to accomodate
  15.         a printer of the same type on more than one port.  Previously,
  16.         I ignored all but the first.
  17.      -- added explanatory note about how Visual Basic handles
  18.         device contexts and DEVMODES, and the allowed points
  19.         for changing stuff
  20.      NOTE: Code written to work with prior versions of these functions
  21.         should be checked for compatibility with this version's.
  22.         The calling sequences are the same, but as noted above, the
  23.         strings now include port info.
  24. -------------------------------------------------------------------
  25. v3.1 -- contains a fix for user defined page length/width
  26. NOTE: When setting a user-defined pagelength or pagewidth,
  27.       you do not need to change the pagesize to user-defined
  28.       first...the pagelength/pagewidth actions do it for you.
  29.      -- added GetPort function
  30. -------------------------------------------------------------------
  31. v3.0 -- added PrtrCap, GetPrtr functions
  32. -------------------------------------------------------------------
  33. v2.0 -- fixed copies error
  34. -------------------------------------------------------------------
  35.  
  36. Included:
  37.  
  38. PPRTR    DLL                 The real deal.
  39. READ     ME                  self-reference (this).
  40. PPRTR    FRM                 .. \    Visual Basic
  41. PPRTR    MAK                   ..>    (version 3.0)
  42. PPRTR    BAS                 .. /     example of PPrtr functions.
  43. PPRTRSMP EXE                 .. \    Example VB3.0 program EXE and
  44. PPRTRFRM TXT                   ..>    saved text for users without
  45. PPRTRBAS TXT                 .. /     v3.0 of VB (EXE needs VBRUN300.DLL
  46. PPGLOBAL TXT                 VB constants.
  47. PRINT    TXT                 constant definitions from C header file.
  48. DEVCAP   TXT                 device cap definitions from C hdr file.
  49. PPRTR    LIB                 Import library for C.
  50. PPRTR    H                   Header file for C.
  51.  
  52. functions:
  53.  
  54.     PPrtr -- allows retrieval or change to any attribute of the default
  55.              printer
  56.  
  57.     DefPrtr -- allows you to find out or change the default printer
  58.  
  59.     Prtrs -- returns semi-colon delimeted list of available active
  60.              printers
  61.  
  62.     PrtrCap -- returns structure (VB type) containing default printer
  63.                device capabilities
  64.  
  65.     GetPrtr -- returns the name of the current default printer
  66.  
  67.     GetPort -- returns the port of the current default printer
  68.  
  69. -----------------------------------------------------------------------
  70.  
  71. function prototypes:          ( in C format ) :
  72.  
  73.     int FAR PASCAL PPrtr (HWND hwndx, int selection, int NewValue, int action);
  74.     int FAR PASCAL Prtrs (LPSTR szActives);
  75.     int FAR PASCAL DefPrtr (LPSTR szNewPrinter, LPSTR szOldPrinter);
  76.     int FAR PASCAL GetPrtr (LPSTR szPrtr);
  77.     int FAR PASCAL GetPort (LPINT szPort);
  78.     int FAR PASCAL PrtrCap (LPINT nDevCap);
  79.  
  80. -----------------------------------------------------------------------
  81.  
  82. function definitions:         ( in Visual Basic format ) :
  83.  
  84.     ******************************** PPrtr **********************************
  85.  
  86.     Declare Function PPrtr Lib "PPRTR.DLL" (ByVal hWnd As Integer, ByVal ppSelection As Integer, ByVal PPNewValue As Integer, ByVal ppAction As Integer) As Integer
  87.  
  88.           where:    hWnd ................ is a window handle
  89.                     ppSelection ......... is the selected printer device
  90.                                            attribute to get/change.
  91.                                       ... NOTE that not all printers
  92.                                            support all actions (e.g. my
  93.                                            Epson LX-800 doesn't support
  94.                                            PaperLength or PaperWidth)
  95.                     ppNewValue .......... is the value to change it to
  96.                                       ... (anything will do if call is a
  97.                                            gimme, no change )
  98.                                       ... see PPGLOBAL.TXT for available
  99.                                            values
  100.                     ppAction ............ is the action requested
  101.                                       ...  0 = gimme current value
  102.                                       ...  1 = change it to ppNewValue
  103.              returns ......... integer of value of selected attribute
  104.                                 before the call
  105.                            ... 995 when there is no default printer
  106.                            ... 996 when the ppSelection is not supported
  107.                                    by the default printer driver
  108.                            ... 997 for a bad ppSelection code parameter
  109.                            ... 998 for a bad ppAction code parameter
  110.                            ... 999 when it can't find printer/driver info
  111.  
  112.     ppSelection:
  113.         DM_ORIENTATION = &H1
  114.         DM_PAPERSIZE = &H2
  115.         DM_PAPERLENGTH = &H4
  116.         DM_PAPERWIDTH = &H8
  117.         DM_SCALE = &H10
  118.         DM_COPIES = &H100
  119.         DM_DEFAULTSOURCE = &H200
  120.         DM_PRINTQUALITY = &H400
  121.         DM_COLOR = &H800
  122.         DM_DUPLEX = &H1000
  123.         DM_YRESOLUTION = &H2000
  124.         DM_TTOPTION = &H4000
  125.  
  126.  
  127.     Samples:
  128.  
  129.         PPrtr(hWnd, DM_PAPERSIZE, PP_UNNEEDED, PP_GIMME)
  130.         PPrtr(hWnd, DM_ORIENTATION, PP_UNNEEDED, PP_GIMME)
  131.  
  132.         PPrtr(hWnd, DM_ORIENTATION, DMORIENT_PORTRAIT, PP_CHANGE_IT)
  133.         PPrtr(hWnd, DM_PAPERSIZE, DMPAPER_LEGAL, PP_CHANGE_IT)
  134.  
  135.     C programmers...the relavent header file for this call is PRINT.H
  136.                     (in Borland C++)
  137.     ******************************** DefPrtr *******************************-
  138.  
  139.     Declare Function DefPrtr Lib "PPRTR.DLL" (ByVal newone As String, ByVal oldone As String) As Integer
  140.  
  141.        where:  newone .. is a string corresponding to what you see in the
  142.                          control panel printers dialog box.  It shows
  143.                          printer names followed by "on xxxx:" where
  144.                          xxxx is a port.  Don't use one where it says
  145.                          "on None".
  146.  
  147.                                     HP LaserJet Series II on LPT1:
  148.                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  149.                                                    ^-- all this
  150.  
  151.                          This is case insensitive, but otherwise must
  152.                          be identical.
  153.  
  154.                          Note: the printer must have been
  155.                          made "active" in the control panel
  156.                          printers applet...it'll show "None"
  157.                          for a port if it's not...e.g.
  158.  
  159.                             active -> HP LaserJet Series II=HPPCL,LPT1:
  160.                             not ----> HPGL Plotter=MGXHPGL,None
  161.  
  162.                          Note: the printer may be active on
  163.                          more than one port.  It'll show the
  164.                          additional ports on the same line
  165.                          separated by commas...e.g.
  166.  
  167.                             1 port -> HP LaserJet Series II on LPT1:
  168.                             3 ports -> HP LaserJet Series II on LPT1:, LPT2:, COM2:
  169.  
  170.                          To use the LPT2 printer, pass this:
  171.  
  172.                              HP LaserJet Series II on LPT2:
  173.  
  174.                          Passing this parameter as an empty string or
  175.                          unrecognizable string results in a 998 error, but
  176.                          does return the name of the current printer
  177.                          in the "oldone" parameter...thus, allowing
  178.                          retrieval of the name of the current default
  179.                          printer without changing anything:
  180.  
  181.                             currentptr$ = String$(255, 0)
  182.                             i = DefPrtr("", currentptr$)
  183.  
  184.        where:  oldone .. is a string in which the function will return
  185.                          the default printer before your call.
  186.  
  187.                          Save this for use as "newone" to reset the
  188.                          printer to the prior default printer when
  189.                          and if you desire to do so.
  190.  
  191.                          Note: in Visual Basic you must pre-load a
  192.                          string which is to be filled by a called
  193.                          function...e.g.
  194.  
  195.                             oldptr$ = String$(255, 0)
  196.                             i = DefPrtr("HP LaserJet Series II on LPT1:", oldptr$)
  197.  
  198.                          If there was no old default printer, this string
  199.                          will be as you initialized it on return.
  200.  
  201.        returns:          0   = successful
  202.                          999 = Unable to write to WIN.INI ... this
  203.                                is a system problem.
  204.                          998 = The "newone" printer was not found in
  205.                                [devices] section of WIN.INI
  206.                                ... be sure you've put in all spaces
  207.                          997 = The "newone" printer was found, but it
  208.                                is not "active"...i.e. its port is
  209.                                "None"
  210.  
  211.  
  212.     Sample:
  213.        Declare Function DefPrtr Lib "PPRTR.DLL" (ByVal newone As String, ByVal oldone As String) As Integer
  214.  
  215.        //---- change to LaserJet ---------------------
  216.        oldprinter$ = String$(255, 0)
  217.        i = DefPrtr("HP LaserJet Series II on LPT1:", oldprinter$)
  218.        //----
  219.        .
  220.        .    print to LaserJet
  221.        .
  222.        //---- change back to original printer --------
  223.        dontcare$ = String$(255, 0)
  224.        i = DefPrtr(oldprinter$,dontcare$)
  225.  
  226.     ******************************** Prtrs *******************************-
  227.  
  228.     Declare Function Prtrs Lib "PPRTR.DLL" (ByVal pList As String,) As Integer
  229.  
  230.        where:  pList ... is a string for the return of a list of
  231.                          available active printers.
  232.  
  233.                          The list only contains the names of "active"
  234.                          printers.  The printer must have been
  235.                          made "active" in the control panel
  236.                          printers applet...it'll show "None"
  237.                          for a port if it's not...e.g.
  238.  
  239.                             active -> HP LaserJet Series II=HPPCL,LPT1:
  240.                             not ----> HPGL Plotter=MGXHPGL,None
  241.  
  242.                          Note: in Visual Basic you must pre-load a
  243.                          string which is to be filled by a called
  244.                          function...e.g.
  245.  
  246.                             plist$ = String$(255, 0)
  247.                             i = Prtrs(plist$)
  248.  
  249.                          The active printer names are separated by
  250.                          semi-colons (;), e.g.
  251.  
  252.                               Epson LX-800 on LPT1:;HP LaserJet Series II on LPT2:
  253.  
  254.        returns ....... 0 if no active printers found, or
  255.                        unable to access [drivers] section in WIN.INI
  256.                ....... 999 if the substring " on " cannot be found in the
  257.                        string you passed, or
  258.                ....... the length of the returned string
  259.  
  260.     ******************************** PrtrCap *******************************-
  261.     Declare Function PrtrCap Lib "PPRTR.DLL" (ndc As DEVCAP) As Integer
  262.        where:  ndc .. is a structure (VB type definition) containing the
  263.                       device capability variable definitions:
  264.  
  265.                       Type devcap
  266.                            DRIVERVERSION As Integer
  267.                            TECHNOLOGY    As Integer ' bits
  268.                            HORZSIZE      As Integer
  269.                            VERTSIZE      As Integer
  270.                            HORZRES       As Integer
  271.                            VERTRES       As Integer
  272.                            BITSPIXEL     As Integer
  273.                            PLANES        As Integer
  274.                            NUMBRUSHES    As Integer
  275.                            NUMPENS       As Integer
  276.                            NUMMARKERS    As Integer
  277.                            NUMFONTS      As Integer
  278.                            NUMCOLORS     As Integer
  279.                            PDEVICESIZE   As Integer
  280.                            CURVECAPS     As Integer ' bits
  281.                            LINECAPS      As Integer ' bits
  282.                            POLYGONALCAPS As Integer ' bits
  283.                            TEXTCAPS      As Integer ' bits
  284.                            CLIPCAPS      As Integer ' bits
  285.                            RASTERCAPS    As Integer ' bits
  286.                            ASPECTX       As Integer
  287.                            ASPECTY       As Integer
  288.                            ASPECTXY      As Integer
  289.                            LOGPIXELSX    As Integer
  290.                            LOGPIXELSY    As Integer
  291.                            SIZEPALETTE  As Integer
  292.                            NUMRESERVED  As Integer
  293.                            COLORRES     As Integer
  294.                       End Type
  295.  
  296.                       See the PPGlobal.txt file for 'bit' field masks;
  297.                       and see the VB example for sample usage.  See the
  298.                       windows SDK documentation for explanation of the
  299.                       dev cap fields.
  300.  
  301.        Returns 0 unless there is no default printer, then returns 995;
  302.  
  303.     ******************************** GetPrtr *******************************-
  304.     Declare Function GetPrtr Lib "PPRTR.DLL" (ByVal DefP As String) As Integer
  305.        where:  DefP .. is a string set up to receive the name of the
  306.                        current default printer.
  307.  
  308.                        Note: in Visual Basic you must pre-load a
  309.                        string which is to be filled by a called
  310.                        function...e.g.
  311.  
  312.                           defptr$ = String$(255, 0)
  313.                           i = GetPrtr(defptr$)
  314.  
  315.       Returns 0 -- and printer name in the string if successful;
  316.       Returns 995 when there is no default printer, string is as you
  317.                   initialized it.
  318.     ******************************** GetPort *******************************-
  319.     Declare Function GetPort Lib "PPRTR.DLL" (ByVal DefP As String) As Integer
  320.        where:  DefP .. is a string set up to receive the name of the
  321.                        current default printer port.
  322.  
  323.                        Note: in Visual Basic you must pre-load a
  324.                        string which is to be filled by a called
  325.                        function...e.g.
  326.  
  327.                           defptr$ = String$(255, 0)
  328.                           i = GetPort(defptr$)
  329.  
  330.       Returns 0 -- and printer name in the string if successful;
  331.                    if not, string is as you initialized it.
  332.       Returns 995 when there is no default printer, string is as you
  333.                   initialized it.
  334.  
  335. --------------------------------------------------------------------
  336. Visual Basic programmers, PLEASE READ:
  337.    Windows programs, including VB, print to a virtual printer called
  338. a Device Context, or DC.  When you start a print job by performing
  339. any print action, VB gets a new DC...this attaches printer setting
  340. data from a structure called DEVMODE.  From then till you issue an
  341. ENDDOC, setting changes like orientation or default printer are not
  342. recognized.  It appears as tho the dll calls didn't work, when in
  343. fact they worked but were ignored.
  344.    So, you must make pprtr.dll calls before your first print action,
  345. or after the ENDDOC if you want to change stuff between print jobs.
  346. --------------------------------------------------------------------
  347. This DLL has been extensively tested by me and friends, but YMMV.
  348.  
  349. A tip of the pelican's beak to OsoSoft George Campbell who suggested the
  350. original idea for this DLL.
  351.  
  352. You are free to try this DLL for 30 days.
  353.  
  354. If you decide to use it thereafter, you are obligated to send $10 to
  355.                      PAUL POELLINGER
  356.                      2019 Round Lake Drive
  357.                      Houston, TX  77077
  358. Please include you e-mail address if you have one.
  359.  
  360.          -- OR --
  361.  
  362. register via Compuserve's shareware registration service by
  363. typing GO SWREG at the prompt.  Registration ID # 1462.  I charge
  364. $12 for registration this way, cause Compuserve takes a 15%
  365. share :-( ... guess shareware means everyone who can gets a share.
  366.  
  367. After doing so, you are free to use it in your applications, and
  368. to distribute it with such applications, as long as you do not
  369. charge separately for the DLL or publish its calling conventions.
  370.  
  371. Please note that even if you paid for a diskette or CD containing
  372. this package, you must still pay the $10 registration fee for use
  373. of this DLL past the 30 day free trial.  What you paid them is
  374. their "share".
  375.  
  376. Multi-user licenses are available for:
  377.       up to 50 developers...........$250
  378.       Unlimited.....................$400
  379. DLL Source code is available for $500.
  380.  
  381. If you paid for the earlier version, you've paid for this one.
  382. I and all those dependent on me thank you.
  383.  
  384. You are free to pass this package on to others or upload it to
  385. bulletin boards provided that 1) you do not charge for it above
  386. the cost of distribution, and 2) all parts of the package are
  387. included (see "included" at the top).
  388.  
  389. Thank you for supporting shareware.
  390. -------------------------------------------------------------------
  391. Let me know if you have any trouble or suggestions.
  392.  
  393.       Paul Poellinger
  394.         Code Wallah
  395.         Silent O Software
  396.         Purveyors of Peliware
  397.         Compuserve: 70732,3576
  398.         AOL: PFPelican
  399.                                      7-7-94
  400. -------------------------------------------------------------------
  401. **************** another offering you might like ******************
  402. -------------------------------------------------------------------
  403. WINPTR.ZIP/Bin  Bytes: 199472 on many compuserve forums and America
  404. On Line.
  405. And coming soon to your favorite Internet ftp site (as wprt102.zip).
  406.  
  407.   Title   : 1.02 Capture,print,control printer w/icon/hotkeys
  408.   Keywords: PRTSC PRINTER SCREEN WINDOW CLIENT CLIPBOARD CLIP FILE FAX
  409.             DEFAULT
  410.  
  411.   Send screen,window,client or rectangle to printer,clipboard,file or
  412.   fax. Send clipboard contents to printer,file or fax. Print files. Load
  413.   files to the clipboard. Text,bitmaps or metafiles. Assign a new default
  414.   printer. Change to portrait/landscape. Route all printer output to files.
  415.   View or clear the clipboard. See what printer is current and its
  416.   orientation on  icon.  ALL FROM A SINGLE ICON loaded with windows.  Most
  417.   via HOTKEYS. Shareware $20.  Upl by author.
  418.  
  419.