找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 506|回复: 2

[VBA程序]:如何列出可用的打印机配置及打印样式?

[复制链接]
发表于 2003-9-13 11:48:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
在VB中如何列出cad可用的打印机配置及打印样式?就是控制面板中的打印机及打印样式管理器中的内容。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 181个

财富等级: 日进斗金

发表于 2003-9-13 12:31:10 | 显示全部楼层
枚举打印机要使用API函数。

  1.   [FONT=courier new]
  2. ' Get information about all of the local printers using structure 1.  Note how
  3. ' the elements of the array are loaded into an array of data structures manually.  Also
  4. ' note how the following special declares must be used to allow numeric string pointers
  5. ' to be used in place of strings:
  6. Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
  7. Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long
  8. Private Declare Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA" (ByVal flags As Long, ByVal name As String, ByVal Level As Long, pPrinterEnum As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
  9. Const PRINTER_ENUM_LOCAL = &H2
  10. Private Type PRINTER_INFO_1
  11.         flags As Long
  12.         pDescription As String
  13.         pName As String
  14.         pComment As String
  15. End Type
  16. Private Sub Form_Load()
  17.     'KPD-Team 1999
  18.     'URL: [url]http://www.allapi.net/[/url]
  19.     'E-Mail: [email]KPDTeam@Allapi.net[/email]
  20.     Dim longbuffer() As Long  ' resizable array receives information from the function
  21.     Dim printinfo() As PRINTER_INFO_1  ' values inside longbuffer() will be put into here
  22.     Dim numbytes As Long  ' size in bytes of longbuffer()
  23.     Dim numneeded As Long  ' receives number of bytes necessary if longbuffer() is too small
  24.     Dim numprinters As Long  ' receives number of printers found
  25.     Dim c As Integer, retval As Long  ' counter variable & return value
  26.     Me.AutoRedraw = True 'Set current graphic mode to persistent
  27.     ' Get information about the local printers
  28.     numbytes = 3076  ' should be sufficiently big, but it may not be
  29.     ReDim longbuffer(0 To numbytes / 4) As Long  ' resize array -- note how 1 Long = 4 bytes
  30.     retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 1, longbuffer(0), numbytes, numneeded, numprinters)
  31.     If retval = 0 Then  ' try enlarging longbuffer() to receive all necessary information
  32.         numbytes = numneeded
  33.         ReDim longbuffer(0 To numbytes / 4) As Long  ' make it large enough
  34.         retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 1, longbuffer(0), numbytes, numneeded, numprinters)
  35.         If retval = 0 Then ' failed again!
  36.             Debug.Print "Could not successfully enumerate the printes."
  37.         End  ' abort program
  38.     End If
  39.     End If
  40.     ' Convert longbuffer() data into printinfo()
  41.     ReDim printinfo(0 To numprinters - 1) As PRINTER_INFO_1  ' room for each printer
  42.     For c = 0 To numprinters - 1  ' loop, putting each set of information into each element
  43.         ' longbuffer(4 * c) = .flags, longbuffer(4 * c + 1) = .pDescription, etc.
  44.         ' For each string, the string is first buffered to provide enough room, and then the string is copied.
  45.         printinfo(c).flags = longbuffer(4 * c)
  46.         printinfo(c).pDescription = Space(lstrlen(longbuffer(4 * c + 1)))
  47.         retval = lstrcpy(printinfo(c).pDescription, longbuffer(4 * c + 1))
  48.         printinfo(c).pName = Space(lstrlen(longbuffer(4 * c + 2)))
  49.         retval = lstrcpy(printinfo(c).pName, longbuffer(4 * c + 2))
  50.         printinfo(c).pComment = Space(lstrlen(longbuffer(4 * c + 3)))
  51.         retval = lstrcpy(printinfo(c).pComment, longbuffer(4 * c + 3))
  52.     Next c
  53.     ' Display name of each printer
  54.     For c = 0 To numprinters - 1
  55.         Me.Print "Name of printer"; c + 1; " is: "; printinfo(c).pName
  56.     Next c
  57. End Sub
  58.   [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 181个

财富等级: 日进斗金

发表于 2003-9-13 12:38:39 | 显示全部楼层
打印机样式应该就是打印机配置,可以使用Document的 PlotConfigurations 属性返回所有的打印配置集合。然后通过枚举PlotConfigurations就可以查看每个配置情况了。

  1.   [FONT=courier new]
  2. Sub Example_CopyFrom()
  3.     ' This example will create two new plot configurations and will use
  4.     ' the CopyFrom method to duplicate the settings in the first plot configuration
  5.     ' to the second plot configuration.

  6.     Dim PlotConfigurations As AcadPlotConfigurations
  7.     Dim PlotConfiguration As AcadPlotConfiguration
  8.     Dim NewPC1 As AcadPlotConfiguration, NewPC2 As AcadPlotConfiguration
  9.    
  10.     ' Get PlotConfigurations collection from document object
  11.     Set PlotConfigurations = ThisDrawing.PlotConfigurations
  12.    
  13.     ' Add a new plot configuration and customize some of the properties
  14.     Set NewPC1 = PlotConfigurations.Add("NEW_CONFIGURATION1")
  15.         NewPC1.PlotRotation = ac270degrees
  16.         NewPC1.PlotHidden = True
  17.         NewPC1.PaperUnits = acMillimeters
  18.    
  19.     ' Add another plot configuration and leave default values intact
  20.     Set NewPC2 = PlotConfigurations.Add("NEW_CONFIGURATION2")
  21.    
  22.     ' Show plot configuration settings before we copy information from PC1
  23.     GoSub VIEWPC2SETTINGS
  24.    
  25.     ' Copy setting information from plot configuration to plot configuration
  26.     NewPC2.CopyFrom NewPC1
  27.    
  28.     ' Show plot configuration settings after we copy information from plot configuration
  29.     GoSub VIEWPC2SETTINGS
  30.    
  31.     Exit Sub
  32.    
  33. VIEWPC2SETTINGS:
  34.     MsgBox "The settings for NEW_CONFIGURATION2 are: " & vbCrLf & _
  35.             "Plot Rotation: " & NewPC2.PlotRotation & vbCrLf & _
  36.             "Plot Hidden: " & NewPC2.PlotHidden & vbCrLf & _
  37.             "Paper Units: " & NewPC2.PaperUnits

  38.     Return
  39. End Sub
  40.   [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-22 18:31 , Processed in 0.188896 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表