Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Get the Default Printer

Total Hit ( 5393)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


API Declarations

Click here to copy the following block
Option Explicit

'MS Windows API Function Prototypes
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

Module

Click here to copy the following block
'---------------------------------------------------------------
' Retreive the vb object "printer" corresponding to the window's
' default printer.
'---------------------------------------------------------------
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

  ' Retreive current default printer information
  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
      ' Default printer found !
      Exit For
    End If
  Next
  ' If not found, return nothing
  If objPrinter.DeviceName <> tblDefaultPrinterInfo(0) Then
    Set objPrinter = Nothing
  End If
  Set GetDefaultPrinter = objPrinter
End Function

Usage

Click here to copy the following block
'Example:
'- Start a new project and on the form_load event write this code
Private Sub Form_Load()
  Dim objPrinter As Printer

  Set objPrinter = GetDefaultPrinter()
  MsgBox "Default printer is: " + objPrinter.DeviceName
  MsgBox "Driver name is: " + objPrinter.DriverName
  MsgBox "Port is: " + objPrinter.Port
  Set objPrinter = Nothing
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.