none
vb如何编实时打印曲线程序,急!!!!!!!!!!!!!!! RRS feed

全部回复

  • 你好:

    请详细描述你的问题,无法理解打印点的曲线。

    2010年9月23日 7:01
    版主
  • 是打印地震仪曲线,电脑每从外设收到一个点,立即在滚筒式打印机上打印出该点到上一点的曲线,目前我用API函数实现了实时打印字符,打印曲线如何实现呢??

    打印程序如下,字符打印出来了,曲线未打印出来!!!为什么???相关资料在哪里找哦???

      Option Explicit

     Public Type DOCINFO
       pDocName As String
       pOutputFile As String
       pDatatype As String
     End Type

     Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
     Public Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
     Public Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
     Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As Long
     Public Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As Long
     Public Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
     Public Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
     Public Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
     Public Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
     Public Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
     
     
     
     Public Type POINTAPI
            x As Long
            y As Long
     End Type
     

     

     


    Private Sub Command1_Click()
      Dim lhPrinter As Long
      Dim lReturn As Long
      Dim i, j As Long
      Dim lpcWritten As Long
      Dim lDoc As Long
      Dim sWrittenData As String
      Dim MyDocInfo As DOCINFO
      Dim pt As POINTAPI
      Dim OutString As String
             
             
        lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
        If lReturn = 0 Then
           MsgBox "The Printer Name you typed wasn't recognized."
           Exit Sub
        End If
        MyDocInfo.pDocName = "AAAAAA"
        MyDocInfo.pOutputFile = vbNullString
        MyDocInfo.pDatatype = vbNullString
        lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
        Call StartPagePrinter(lhPrinter)
       
        Printer.ScaleMode = 3
       
      
        OutString = "TEST LINE !!!!!!"
        i = LenB(StrConv(OutString, 1))
        TextOut lhPrinter, 10, 10, OutString, i
       
        TextOut lhPrinter, 10 / Printer.TwipsPerPixelX, 10 / Printer.TwipsPerPixelY, "TEST LINE !!!!!!", 2 * Len("TEST LINE !!!!!!")
       
        MoveToEx lhPrinter, 10 / Printer.TwipsPerPixelX, 1 / Printer.TwipsPerPixelY, pt
        LineTo lhPrinter, 120 / Printer.TwipsPerPixelX, 4 / Printer.TwipsPerPixelY
       
        lReturn = MoveToEx(lhPrinter, 20, 20, pt)
        lReturn = LineTo(lhPrinter, 12000, 5)
       
        lReturn = MoveToEx(lhPrinter, 0, 0, pt)
        lReturn = LineTo(lhPrinter, 120, 5000)
       
       
       
        lReturn = EndPagePrinter(lhPrinter)
        lReturn = EndDocPrinter(lhPrinter)
        lReturn = ClosePrinter(lhPrinter)

    End Sub

     

    2010年9月25日 3:02
  • 程序发错了,以这一段程序为准, 打印字符用WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)函数打出来了,但用textout,lineto,moveto等API函数编译通过,但未打印!!

    Option Explicit

     Public Type DOCINFO
       pDocName As String
       pOutputFile As String
       pDatatype As String
     End Type

     Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
     Public Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
     Public Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
     Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As Long
     Public Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As Long
     Public Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
     Public Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
     Public Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
     Public Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
     Public Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
     
     
     
     Public Type POINTAPI
            x As Long
            y As Long
     End Type
     

     

    Private Sub Command1_Click()
      Dim lhPrinter As Long
      Dim lReturn As Long
      Dim i, j As Long
      Dim lpcWritten As Long
      Dim lDoc As Long
      Dim sWrittenData As String
      Dim MyDocInfo As DOCINFO
      Dim pt As POINTAPI
      Dim OutString As String
             
             
        lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
        If lReturn = 0 Then
           MsgBox "The Printer Name you typed wasn't recognized."
           Exit Sub
        End If
        MyDocInfo.pDocName = "AAAAAA"
        MyDocInfo.pOutputFile = vbNullString
        MyDocInfo.pDatatype = vbNullString
        lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
        Call StartPagePrinter(lhPrinter)
       
        Printer.ScaleMode = 3
       
        sWrittenData = "How's that for Magic !!!!"
        lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
      
        MoveToEx lhPrinter, 10 / Printer.TwipsPerPixelX, 1 / Printer.TwipsPerPixelY, pt
        LineTo lhPrinter, 120 / Printer.TwipsPerPixelX, 4 / Printer.TwipsPerPixelY
       
        lReturn = MoveToEx(lhPrinter, 20, 20, pt)
        lReturn = LineTo(lhPrinter, 12000, 5)
       
        lReturn = MoveToEx(lhPrinter, 0, 0, pt)
        lReturn = LineTo(lhPrinter, 120, 5000)
       
       
       
        lReturn = EndPagePrinter(lhPrinter)
        lReturn = EndDocPrinter(lhPrinter)
        lReturn = ClosePrinter(lhPrinter)

    End Sub

    2010年9月25日 3:09