HOWTO: Open the Printer Properties Dialog
ID: Q198860
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions for Windows, version 4.0
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.
MORE INFORMATIONStep-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
PD.pDesiredAccess = PRINTER_ALL_ACCESS
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.
Additional query words:
Keywords : kbAPI kbPrinting kbSpooler kbVBp kbVBp400 kbVBp500 kbVBp600 kbGrpVB
Version : WINDOWS:4.0,5.0,6.0
Platform : WINDOWS
Issue type : kbhowto
|