设为首页收藏本站

SKY外语、计算机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2792|回复: 0
打印 上一主题 下一主题

VB_打印不换页

[复制链接]

16

主题

0

好友

216

积分

中级会员

Rank: 3Rank: 3

生肖
性别

最佳新人 论坛元老

跳转到指定楼层
楼主
发表于 2012-4-28 21:41:12 |只看该作者 |倒序浏览
本帖最后由 sky_yx 于 2015-12-30 14:23 编辑

  1.       Option Explicit
  2.       Private Type DOCINFO
  3.           pDocName As String
  4.           pOutputFile As String
  5.           pDatatype As String
  6.       End Type
  7.       Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
  8.          hPrinter As Long) As Long
  9.       Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
  10.          hPrinter As Long) As Long
  11.       Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
  12.          hPrinter As Long) As Long
  13.       Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
  14.          "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
  15.           ByVal pDefault As Long) As Long
  16.       Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
  17.          "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
  18.          pDocInfo As DOCINFO) As Long
  19.       Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
  20.          hPrinter As Long) As Long
  21.       Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
  22.          hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
  23.          pcWritten As Long) As Long
  24.       Dim lhPrinter As Long
  25.       Private Sub Command1_Click()
  26.              Dim lReturn As Long
  27.              Dim lpcWritten As Long
  28.              Dim sWrittenData As String
  29.              sWrittenData = "How's that for Magic !!!!" & vbCrLf
  30.              lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
  31.                 Len(sWrittenData), lpcWritten)
  32.       End Sub
  33.       Private Sub Form_Load()
  34.           Dim lReturn As Long
  35.           Dim lDoc As Long
  36.           Dim MyDocInfo As DOCINFO
  37.           lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
  38.           If lReturn = 0 Then
  39.               MsgBox "The Printer Name you typed wasn't recognized."
  40.               Exit Sub
  41.           End If
  42.           MyDocInfo.pDocName = "AAAAAA"
  43.           MyDocInfo.pOutputFile = vbNullString
  44.           MyDocInfo.pDatatype = vbNullString
  45.           lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
  46.           Call StartPagePrinter(lhPrinter)
  47.       End Sub
  48.       Private Sub Form_Unload(Cancel As Integer)
  49.           Dim lReturn As Long
  50.           lReturn = EndPagePrinter(lhPrinter)
  51.           lReturn = EndDocPrinter(lhPrinter)
  52.           lReturn = ClosePrinter(lhPrinter)
  53.       End Sub
复制代码


分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
分享淘帖0 收藏收藏0 评分评分
您需要登录后才可以回帖 登录 | 立即注册


手机版|SKY外语计算机学习 ( 粤ICP备12031577 )    

GMT+8, 2024-12-22 00:35 , Processed in 0.108810 second(s), 28 queries .

回顶部