home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples5 / ch12 / docjob.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  3.4 KB  |  99 lines

  1. VERSION 5.00
  2. Begin VB.Form frmDocJob 
  3.    Caption         =   "Direct Spooler Access"
  4.    ClientHeight    =   2700
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   5250
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   2700
  11.    ScaleWidth      =   5250
  12.    Begin VB.CommandButton cmdPrint 
  13.       Caption         =   "Print"
  14.       Height          =   375
  15.       Left            =   3900
  16.       TabIndex        =   3
  17.       Top             =   240
  18.       Width           =   915
  19.    End
  20.    Begin VB.TextBox txtText 
  21.       Height          =   855
  22.       Left            =   960
  23.       MultiLine       =   -1  'True
  24.       TabIndex        =   2
  25.       Text            =   "DocJob.frx":0000
  26.       Top             =   720
  27.       Width           =   3855
  28.    End
  29.    Begin VB.TextBox txtName 
  30.       Height          =   315
  31.       Left            =   960
  32.       TabIndex        =   0
  33.       Text            =   "HPLJ"
  34.       Top             =   240
  35.       Width           =   1695
  36.    End
  37.    Begin VB.Label Label2 
  38.       Alignment       =   1  'Right Justify
  39.       Caption         =   "Printer:"
  40.       Height          =   195
  41.       Left            =   120
  42.       TabIndex        =   1
  43.       Top             =   300
  44.       Width           =   795
  45.    End
  46. Attribute VB_Name = "frmDocJob"
  47. Attribute VB_GlobalNameSpace = False
  48. Attribute VB_Creatable = False
  49. Attribute VB_PredeclaredId = True
  50. Attribute VB_Exposed = False
  51. Option Explicit
  52. ' Copyright 
  53.  1997 by Desaware Inc. All Rights Reserved.
  54. '**********************************
  55. '**  Type Definitions:
  56. #If Win32 Then
  57. Private Type DOC_INFO_1
  58.     pDocName As String
  59.     pOutputFile As String
  60.     pDatatype As String
  61. End Type
  62. #End If 'WIN32 Types
  63. '**********************************
  64. '**  Function Declarations:
  65. #If Win32 Then
  66. Private Declare Function OpenPrinter& Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) ' Third param changed to long
  67. Private Declare Function StartDocPrinter& Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOC_INFO_1)
  68. Private Declare Function StartPagePrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
  69. Private Declare Function WritePrinter& Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long)
  70. Private Declare Function EndDocPrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
  71. Private Declare Function EndPagePrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
  72. Private Declare Function ClosePrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
  73. #End If 'WIN32
  74. Private Sub cmdPrint_Click()
  75.     Dim hPrinter&
  76.     Dim jobid&
  77.     Dim res&
  78.     Dim written&
  79.     Dim printdata$
  80.     Dim docinfo As DOC_INFO_1
  81.     res& = OpenPrinter(txtName.Text, hPrinter, 0)
  82.     If res = 0 Then
  83.         MsgBox "Unable to open the printer"
  84.         Exit Sub
  85.     End If
  86.     docinfo.pDocName = "MyDoc"
  87.     docinfo.pOutputFile = vbNullString
  88.     docinfo.pDatatype = vbNullString
  89.     jobid = StartDocPrinter(hPrinter, 1, docinfo)
  90.     Call StartPagePrinter(hPrinter)
  91.     printdata$ = txtText.Text & vbFormFeed
  92.     Call WritePrinter(hPrinter, ByVal printdata$, Len(printdata$), written)
  93.     Call EndPagePrinter(hPrinter)
  94.     Call EndDocPrinter(hPrinter)
  95.     Call ClosePrinter(hPrinter) ' Close when done
  96. End Sub
  97. Private Sub Form_Load()
  98. End Sub
  99.