|
|
|
|
|
Dicas
|
|
Visual Basic (Impressões/Impressoras)
|
|
|
Título da Dica: Precisa conhecer a impressora padrão instalada?
|
|
|
|
Postada em 25/8/2003 por Ð@®l@n
insira o código abaixo no módulo :
Private Declare Function GetProfileString Lib "kernel32.dll" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Public Function GetDefaultPrinter() As Printer Dim strBuffer As String * 254 Dim iRetValue As Long Dim strDefaultPrinterInfo As String Dim tblDefaultPrinterInfo() As String Dim objPrinter As Printer
' pega as informacoes da impressora padrao iRetValue = GetProfileString("windows", "device", ",,,", strBuffer, 254) strDefaultPrinterInfo = Left(strBuffer, InStr(strBuffer, Chr(0)) - 1) tblDefaultPrinterInfo = Split(strDefaultPrinterInfo, ",") For Each objPrinter In Printers If objPrinter.DeviceName = tblDefaultPrinterInfo(0) Then ' se achou a impressora padrao entao sai Exit For End If Next ' se nao achou retrona nothing If objPrinter.DeviceName <> tblDefaultPrinterInfo(0) Then Set objPrinter = Nothing End If Set GetDefaultPrinter = objPrinter End Function
No formulário padrão: Private Sub Command1_Click()
Dim objPrinter As Printer Set objPrinter = GetDefaultPrinter()
MsgBox "Impressora padrao => " + objPrinter.DeviceName & vbCrLf & _ "Driver da impressora => " + objPrinter.DriverName & vbCrLf & _ "A porta usada é a => " + objPrinter.Port
Set objPrinter = Nothing
End Sub
|
|
|
|
|