Results 1 to 2 of 2

Thread: PrinterProperties API

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Posts
    6

    Thumbs down PrinterProperties API

    Help!

    I'm trying to bring up the printer properties dialog using OpenPrinter with admin access and it brings up the printer properties with everything locked out! Any ideas? Its driving me crazy!

    Thanks,
    Chris
    Chris Malcolm
    Petrofocus
    email : [email protected]

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try using code. I've never had a problem with this:
    VB Code:
    1. 'From 'http://www.vbapi.com/ref/p/printerproperties.html
    2.  
    3. Private Declare Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA" (ByVal flags As Long, ByVal name As String, ByVal Level As Long, pPrinterEnum As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
    4. Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    5. Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long
    6. Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
    7. Private Declare Function PrinterProperties Lib "winspool.drv" (ByVal hWnd As Long, ByVal hPrinter As Long) As Long
    8. Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
    9.  
    10. ' Declarations and such needed for the example:
    11. ' (Copy them to the (declarations) section of a module.)
    12. Private Type PRINTER_INFO_1
    13.     flags As Long
    14.     pDescription As String
    15.     pName As String
    16.     pComment As String
    17. End Type
    18.  
    19. Private Const PRINTER_ENUM_DEFAULT = &H1
    20.  
    21. Private Sub Command1_Click
    22.  
    23.     Dim pi1 As PRINTER_INFO_1  ' a little info about the printer
    24.     Dim bytesNeeded As Long    ' size needed for buffer
    25.     Dim numPrinters As Long    ' number of printers enumerated (should be 1)
    26.     Dim buffer() As Long       ' buffer for printer information
    27.     Dim slength As Long        ' length of string to copy
    28.     Dim hPrinter As Long       ' handle to the printer
    29.     Dim retval As Long         ' generic return value
    30.    
    31.     ' Figure out how much space is needed to store the printer information.
    32.     retval = EnumPrinters(PRINTER_ENUM_DEFAULT, vbNullString, 1, ByVal 0, 0, bytesNeeded, numPrinters)
    33.     ' Allocate that much space in the buffer array.
    34.     ReDim buffer(0 To bytesNeeded / 4 - 1) As Long
    35.     ' Get information about the default printer.
    36.     retval = EnumPrinters(PRINTER_ENUM_DEFAULT, vbNullString, 1, buffer(0), bytesNeeded, _
    37.         bytesNeeded, numPrinters)
    38.     ' Make sure we were successful.
    39.     If retval = 0 Or numPrinters <> 1 Then
    40.         MsgBox "No default printer or some other error."
    41.         Exit Sub
    42.     End If
    43.    
    44.     ' Copy the data into the structure.
    45.     With pi1
    46.         ' Copy numerical data directly.
    47.         .flags = buffer(0)
    48.         ' Strings require more work, since the buffer holds pointers to them.
    49.         .pDescription = Space(lstrlen(buffer(1)))
    50.         retval = lstrcpy(.pDescription, buffer(1))
    51.         .pName = Space(lstrlen(buffer(2)))
    52.         retval = lstrcpy(.pName, buffer(2))
    53.         .pComment = Space(lstrlen(buffer(3)))
    54.         retval = lstrcpy(.pComment, buffer(3))
    55.     End With
    56.    
    57.     ' Open the printer.
    58.     retval = OpenPrinter(pi1.pName, hPrinter, ByVal CLng(0))
    59.     If retval <> 0 Then
    60.         ' Display the properties dialog.
    61.         retval = PrinterProperties(Me.hWnd, hPrinter)
    62.         ' Close the printer.
    63.         retval = ClosePrinter(hPrinter)
    64.     Else
    65.         MsgBox "Unable to open printer!"
    66.     End If
    67. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width