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

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