Тема: Default printer

Как получить имя принтера установленного по умолчанию в системе?

Re: Default printer

Vadim пишет:

Как получить имя принтера установленного по умолчанию в системе?

Author unknown:

Public Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
 
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Const HWND_BROADCAST = &HFFFF&
    Public Const WM_WININICHANGE = &H1A



Public Function SetDefaultPrinter(objPrn As Printer) As Boolean
    Dim x As Long, sztemp As String
    sztemp = objPrn.DeviceName & "," & objPrn.DriverName & "," & objPrn.Port
    x = WriteProfileString("windows", "device", sztemp)
    x = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0&, "windows")
End Function
 
Private Sub Command1_Click()
    Dim x As Printer
    If MsgBox("Are You Sure Want To Set " & Combo1.Text & " as Default printer ? ", vbYesNo, "Attention") = vbYes Then
 
        For Each x In Printers
            If x.DeviceName = Combo1.Text Then
                SetDefaultPrinter x
                Exit Sub
            End If
        Next
 
    End If
End Sub

~'J'~