Microsoft KB Archive/198860

= How To Open the Printer Properties Dialog =

Article ID: 198860

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition

-



This article was previously published under Q198860



SUMMARY
If you need to create your own printer dialog, you can use the PrinterProperties API function to bring up a printer's properties dialog. Your users can then make most of the same changes they could if they brought up this dialog by hand. The only difference will be that some tabs may be missing.



Step-by-Step Example
 Start a new project in Visual Basic. Form1 is created by default. Add a CommandButton and a ListBox to the Form.  Paste the following code into the Form's module:

Option Explicit

Private Declare Function PrinterProperties Lib "winspool.drv" _ (ByVal hwnd As Long, ByVal hPrinter As Long) As Long

Private Declare Function OpenPrinter Lib "winspool.drv" _ Alias "OpenPrinterA" (ByVal pPrinterName As String, _       phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long

Private Declare Function ClosePrinter Lib "winspool.drv" _ (ByVal hPrinter As Long) As Long

Private Type PRINTER_DEFAULTS pDatatype As Long ' String pDevMode As Long pDesiredAccess As Long End Type

Private Const STANDARD_RIGHTS_REQUIRED = &HF0000 Private Const PRINTER_ACCESS_ADMINISTER = &H4 Private Const PRINTER_ACCESS_USE = &H8 Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _        PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)

Private Sub Form_Load Dim I As Integer

' List all available printers For I = 0 To Printers.Count - 1 List1.AddItem Printers(I).DeviceName If Printers(I).DeviceName = Printer.DeviceName Then List1.Selected(I) = True ' Select current default printer End If        Next I      End Sub

Private Sub List1_Click Dim Prt As Printer

' Find and use the printer just selected in the ListBox For Each Prt In Printers If Prt.DeviceName = List1.Text Then Set Printer = Prt Exit For End If        Next End Sub

Private Sub Command1_Click Dim RetVal As Long, hPrinter As Long Dim PD As PRINTER_DEFAULTS

PD.pDatatype = 0 ' Note that you cannot request more rights than you have as a user PD.pDesiredAccess = STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_USE PD.pDevMode = 0 RetVal = OpenPrinter(Printer.DeviceName, hPrinter, PD) If RetVal = 0 Then MsgBox "OpenPrinter Failed!" Else RetVal = PrinterProperties(Me.hwnd, hPrinter) RetVal = ClosePrinter(hPrinter) End If     End Sub  Run the project and click on Command1. The Properties dialog will open for the currently selected printer. Note that some tabs may be missing from what you see when bringing up these properties by hand.

(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Chris E. Jolley, Microsoft Corporation.

Keywords: kbhowto kbprint kbapi kbspooler KB198860

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.