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 / prinfo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  2.9 KB  |  90 lines

  1. VERSION 5.00
  2. Begin VB.Form frmPrintInfo 
  3.    Caption         =   "Printer Info"
  4.    ClientHeight    =   3045
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   5145
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   3045
  11.    ScaleWidth      =   5145
  12.    Begin VB.CommandButton Command1 
  13.       Caption         =   "GetInfo"
  14.       Height          =   495
  15.       Left            =   3600
  16.       TabIndex        =   3
  17.       Top             =   360
  18.       Width           =   1215
  19.    End
  20.    Begin VB.TextBox txtDescription 
  21.       Height          =   1035
  22.       Left            =   300
  23.       MultiLine       =   -1  'True
  24.       TabIndex        =   2
  25.       Top             =   960
  26.       Width           =   3075
  27.    End
  28.    Begin VB.TextBox txtPRName 
  29.       Height          =   285
  30.       Left            =   1560
  31.       TabIndex        =   0
  32.       Text            =   "HPLJ"
  33.       Top             =   360
  34.       Width           =   1815
  35.    End
  36.    Begin VB.Label Label1 
  37.       Alignment       =   1  'Right Justify
  38.       Caption         =   "Printer Name:"
  39.       Height          =   255
  40.       Left            =   240
  41.       TabIndex        =   1
  42.       Top             =   420
  43.       Width           =   1275
  44.    End
  45. Attribute VB_Name = "frmPrintInfo"
  46. Attribute VB_GlobalNameSpace = False
  47. Attribute VB_Creatable = False
  48. Attribute VB_PredeclaredId = True
  49. Attribute VB_Exposed = False
  50. Option Explicit
  51. ' Copyright 
  52.  1997 by Desaware Inc. All Rights Reserved.
  53. '**********************************
  54. '**  Type Definitions:
  55. #If Win32 Then
  56. Private Type PRINTER_INFO_1
  57.     flags As Long
  58.     pDescription As Long
  59.     pName As Long
  60.     pComment As Long
  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)
  67. Private Declare Function GetPrinter& Lib "winspool.drv" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long)
  68. Private Declare Function ClosePrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
  69. #End If 'WIN32
  70. Private Sub Command1_Click()
  71.     Dim pi As PRINTER_INFO_1
  72.     Dim hPrinter&, res&
  73.     Dim needed&
  74.     res = OpenPrinter(txtPRName.Text, hPrinter, 0)
  75.     If res = 0 Then
  76.         MsgBox "Can't open printer - Specify a valid printer name"
  77.         Exit Sub
  78.     End If
  79.     ' Find out how large the buffer needs to be
  80.     res = GetPrinter(hPrinter, 1, 0, 0, needed)
  81.     ReDim buffer(needed) As Byte
  82.     res = GetPrinter(hPrinter, 1, buffer(0), needed, needed)
  83.     ' Copy to a structure
  84.     agCopyData buffer(0), pi, Len(pi)
  85.     txtDescription.Text = agGetStringFromPointer(pi.pDescription)
  86.     Call ClosePrinter(hPrinter)
  87. End Sub
  88. Private Sub Form_Load()
  89. End Sub
  90.