首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(0) | 引用(0) | 阅读1242次
莫名其妙的问题Printers.Count 3

解决 莫名其妙的问题Printers.Count 2 ,改用API函数 获得默认打印机,枚举打印机等

Public Sub WinNTGetDefaultPrinter(PrinterName As String)
    Dim Buffer As String
    Dim DeviceName As String
    Dim DriverName As String
    Dim PrinterPort As Stringwww.shengfang.org
'    Dim PrinterName As String
    Dim r As Long

    ' Get the printer information for the currently selected
    ' printer in the list. The information is taken from the
    ' WIN.INI file.
    Buffer = Space(1024)

    r = GetProfileString("Windows", "device", "", _
        Buffer, Len(Buffer))www.shengfang.org

    ' Parse the driver name anwww.shengfang.orgd port name out of the buffer
    GetDriverAndPort Buffer, DriverName, PrinterPort

    PrinterName = DriverName
End Sub


 Public Sub EnumeratePrinters4(iprts As Integer, str() As String)
      Dim Success As Boolean, cbRequired As Long, cbBuffer As Long
      Dim Buffer() As Long, nEntries As Long
      Dim i As Long, PName As String, SName As String
      Dim Attrib As Long, Temp As Long
         cbBuffer = 3072
         ReDim Buffer((cbBuffer \ 4) - 1) As Long
         Success = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
                               PRINTER_ENUM_LOCAL, _
                               vbNullString, _
                               4, _
                               Buffer(0), _
                               cbBuffer, _
                               cbRequired, _www.shengfang.org
                               nEntries)
         If Success Then
            If cbRequired > cbBuffer Then
               cbBuffer = cbRequired
               Debug.Print "Buffer too small.  Trying again with " & _
                        cbBuffer & " bytes."
               ReDim Buffer(cbBuffer \ 4) As Long
               Success = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
                                   PRINTER_ENUM_LOCAL, _
                                   vbNullString, _
                                   4, _www.shengfang.org
                                   Buffer(0), _
                                   cbBuffer, _
                                   cbRequired, _
                                   nEntries)
               If Not Success Then
                  Debug.Print "Error enumerating printers."
                  Exit Sub
               End If
            End If
            Debug.Print "There are " & nEntries & _
                      " local and connected printers."
            iprts = nEntrieswww.shengfang.org
            ReDim str(nEntries)
            For i = 0 To nEntries - 1
                PName = Space$(StrLen(Buffer(i * 3)))
                Temp = PtrToStr(PName, Buffer(i * 3))
                SName = Space$(StrLen(Buffer(i * 3 + 1)))
                Temp = PtrToStr(SName, Buffer(i * 3 + 1))
                Attrib = Buffer(i * 3 + 2)
                str(i) = PName
            'MsgBox "Printer: " & PName ' + "Server: " & Str(SName) + "Attributes: " & Str(Hex$(Attrib))
            Next i
         Else
            iprts = 0
         End If
      End Sub

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:
266767 (http://support.microsoft.com/kb/266767/EN-US/) HOWTO: Set Which Printer Is the System Default Printer
142388 (http://support.microsoft.com/kb/142388/EN-US/) HOWTO: Changing WIN.INI Printer Settings from VB using Windows API
For additional information on determining which 32-Bit for Windows NT 3.51, Windows NT 4.0 and Windows 95, click the article number below to view the article in the Microsoft Knowledge Base:
189249 (http://support.microsoft.com/kb/189249/EN-US/) HOWTO: Determine Which 32-Bit Windows Version Is Being Used
140560 (http://support.microsoft.com/kb/140560/EN-US/) HOWTO: Set the Default Printer Programmatically in Windows 95, Windows 98, or Windows Me
167735 (http://support.microsoft.com/kb/167735/EN-US/) FIX: Setting Printer to Item in the Printers Collection Fails
253612 (http://support.microsoft.com/kb/253612/EN-US/) FIX: Printers Collection May Not Contain All Printers in the Printers Folder
246772 (http://support.microsoft.com/kb/246772/EN-US/) How To Retrieve and Set the Default Printer in Windows

字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/printercount3.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1122275256

2005年7月25日15:07星期一  [Dev开发] 追踪此文的RSS
提示:
此文还没有评论。

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1839
在线: 9||用户: 2576 [列表]
今日:2211||到访:2854065
Rss:885222||评论:1604

最新日志

最新评论

友情链接

日历

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8