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 / samples4 / ch12 / docjob.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-02-16  |  3.4 KB  |  98 lines

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