home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vb_g_prt / vbg1.bas < prev    next >
Encoding:
BASIC Source File  |  1995-09-06  |  4.6 KB  |  129 lines

  1. '----------------------------------------------------------------
  2. 'Copyright 1994   Unger Business Systems  All Rights Reserved
  3. 'This code is distributed as shareware.  If you use it, you
  4. 'are required by law to register it.  Please contact Unger
  5. 'Business Systems at 11926 Barrett Brae, Houston, TX 77072-4004
  6. 'or call (713) 498-8517.  Registration fee is $20.00 US
  7. 'See the README.TXT file for more information
  8. '
  9. 'All code, forms, modules, controls, etc. are provided without
  10. 'warranty or liability
  11. '----------------------------------------------------------------
  12.  
  13. Option Explicit
  14.  
  15. Global Const MB_OK = 0                'Display OK button only.
  16. Global Const MB_OKCANCEL = 1          'Display OK and Cancel buttons.
  17. Global Const MB_ABORTRETRYIGNORE = 2  'Display Abort, Retry, and Ignore buttons.
  18. Global Const MB_YESNOCANCEL = 3       'Display Yes, No, and Cancel buttons.
  19. Global Const MB_YESNO = 4             'Display Yes and No buttons.
  20. Global Const MB_RETRYCANCEL = 5       'Display Retry and Cancel buttons.
  21.  
  22. Global Const MB_ICONSTOP = 16
  23. Global Const MB_ICONQUESTION = 32
  24. Global Const MB_ICONEXCLAMATION = 48
  25. Global Const MB_ICONINFORMATION = 64
  26.  
  27. Global Const MB_DEFBUTTON1 = 0    'First button is default.
  28. Global Const MB_DEFBUTTON2 = 256  'Second button is default.
  29. Global Const MB_DEFBUTTON3 = 512  'Third button is default.
  30.  
  31. Global Const MB_APPLMODAL = 0     'Application modal.  The user must respond to the
  32. 'message box before continuing work in the current application.
  33. Global Const MB_SYSTEMMODAL = 4096    'System modal.  All applications are suspended until the
  34. 'user responds to the message box.
  35.  
  36. Global Const IDOK = 1      'OK button selected.
  37. Global Const IDCANCEL = 2  'Cancel button selected.
  38. Global Const IDABORT = 3   'Abort button selected.
  39. Global Const IDRETRY = 4   'Retry button selected.
  40. Global Const IDIGNORE = 5  'Ignore button selected.
  41. Global Const IDYES = 6     'Yes button selected.
  42. Global Const IDNO = 7      'No button selected.
  43.  
  44. Global ThisPrinter$, ThisOrientation$
  45.  
  46. Sub PrintThisText (ByVal TextStr$, ByVal TFontName$, ByVal TFontSize!, ByVal UseBold%, ByVal UseItalic%)
  47.     Dim prhdc%, di%, NumLines%, I%
  48.     
  49.     If Trim$(TFontName) = "" Then
  50.        MsgBox "You must supply a font name.", MB_ICONSTOP
  51.        Exit Sub
  52.     End If
  53.  
  54.     If TFontSize < 6 Or TFontSize > 48 Then 'these values are arbitrary for this example
  55.        MsgBox "Invalid font size.", MB_ICONSTOP
  56.        Exit Sub
  57.     End If
  58.  
  59.     prhdc = GenPrinterSetup(ThisPrinter, ThisOrientation)
  60.     'prhdc is an integer which now contains the device
  61.     'context for ThisPrinter.  ThisPrinter is a string of the
  62.     'form "HP LaserJet IIP,HPPCL,LPT1:" as stored in the
  63.     'WIN.INI file.  Note that prhdc is passed to virtually
  64.     'all of the other GENPRINT routines.  This routine as
  65.     'written call DefaultFontSetup and uses "Ariel" font in
  66.     '10 pt size.
  67.  
  68.     If prhdc = 0 Then  'call failed
  69.     GoTo PrintThisTextErrHandler
  70.     End If
  71.  
  72.     SetPrtFontName prhdc, GetOnlyFontName(TFontName)
  73.     SetPrtFontSize prhdc, TFontSize
  74.     SetPrtFontBold prhdc, UseBold
  75.     SetPrtFontItalic prhdc, UseItalic
  76.  
  77.     SetupDocInfo ("VBG Printer")
  78.     'This supplies the information used by Print Manager.
  79.  
  80.     SetAbortCallback (prhdc)
  81.     'This sets up the abort procedure.
  82.  
  83.     ShowAbortForm (False)  'must not be system modal
  84.     'This displays the abort form.
  85.  
  86.     di = StartDocument(prhdc)
  87.     'This tells Print Manager that we are starting a document.
  88.  
  89.     di = StartAPage(prhdc)
  90.     'Start a page!
  91.  
  92.     NumLines = SplitLines(prhdc, TextStr, 5.5)
  93.     'Split TextStr into lines of not more than 5.5 inches
  94.     'Return number of lines generated
  95.  
  96.     SetTextY 1  'start printing 1 inch from top
  97.  
  98.     'There are numerous other functions which can now be called to draw
  99.     'lines, rectangles, etc.  The font can also be changed.  See the
  100.     'GPRINTER.BAS module for available functions.
  101.     For I = 1 To NumLines
  102.     SetTextX .75  'start printing .75 inches from left margin
  103.     PrintText prhdc, LinesArray(I)
  104.     LineFeed prhdc
  105.     Next I
  106.  
  107.     di = EndAPage(prhdc)
  108.     'This is called each time you want to end a page.  If
  109.     'more pages are to be printed, be sure to call StartAPage
  110.     'again.
  111.  
  112.     di = EndDocument(prhdc)
  113.     'This tells Print Manager that the document is finished.
  114.  
  115.     UnloadAbortForm
  116.     'Get rid of the abort form.
  117.  
  118.     GenPrinterClose prhdc
  119.     'Clean up after printer.  After this call prhdc is no
  120.     'longer valid.
  121.  
  122.     Exit Sub
  123.  
  124. PrintThisTextErrHandler:
  125.     MsgBox "Unable to create device context!", MB_ICONSTOP
  126.     Exit Sub
  127. End Sub
  128.  
  129.