VB6 获取和设置默认打印机

您所在的位置:网站首页 vb怎么调用打印机选择窗口 VB6 获取和设置默认打印机

VB6 获取和设置默认打印机

2024-07-14 14:14| 来源: 网络整理| 查看: 265

Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As LongFunction GetDeviceName() As StringDim di As Stringdef$ = String(128, 0)di = GetProfileString("WINDOWS", "DEVICE", "", def$, 127)GetDeviceName = Trim(def$)GetDeviceName = Left(GetDeviceName, InStr(GetDeviceName, ",") - 1)End FunctionPrivate Sub Command1_Click()Dim a As StringMsgBox GetDeviceNamea = GetDeviceName()Call setDefaultPrinter_To_System("PDF995")End SubPublic Sub setDefaultPrinter_To_System(devcName As String)    Dim X As Printer    Dim WshNetwork As Object    Dim k As Long    k = 0    For Each X In Printers       If X.DeviceName = devcName Then          ' Set printer as system default.          Set Printer = X          Set WshNetwork = CreateObject("WScript.Network")          WshNetwork.setDefaultPrinter (Printers(k).DeviceName)          ' Stop looking for a printer.          Exit For       End If       k = k + 1    Next    End Sub



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3