6259.html

来自「以电子书的形式收集了VB一些常见问题解决方法,可以很方便的查找自己需要解决的问题」· HTML 代码 · 共 23 行

HTML
23
字号
<html>
  <head>
    <title>使用 File API</title>
  </head>
  <body bgcolor="#FFFFFF" vlink="#808080">
    <center>
      <h1>使用 File API</h1>
    </center>
<hr size=7 width=75%>

<hr size=7 width=75%><p>
Posted by <a href="mailto:yfwu@iname.com">小吴</a> on October 06, 1998 at 08:18:03:<p>
In Reply to: <a href="6252.html">请教各位网友:如何在vb6.0中向epson-1900k打印机发送打印机控制命令</a> posted by John on October 05, 1998 at 16:23:06:<p>
你可以使用 FileAPI 来开始 printer port (LPT1, LPT2, or PRN),这样就可以直接输出到打印机了。<p>Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long<br>Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long<br>Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long<br>Public Const OFS_MAXPATHNAME = 128<br>Public Const OF_WRITE = &H1<br>   <br>Type OFSTRUCT<br>    cBytes As Byte<br>    fFixedDisk As Byte<br>    nErrCode As Integer<br>    Reserved1 As Integer<br>    Reserved2 As Integer<br>    szPathName(OFS_MAXPATHNAME) As Byte<br>End Type<p>Private Sub Test()<br>    Dim hFile As Integer<br>    Dim strPath As String<br>    Dim strucFname As OFSTRUCT<br>    Dim strhFiles As String<br>    Dim strPort As String<br>    Dim bytData() As Byte<br>    Dim lrc As Long<br>    Dim lngBytesWritten As Long<br>    <br>    <br>    strPort = "LPT1"<br>    <br>    hFile = OpenFile(strPort, strucFname, OF_WRITE)<br>    <br>    If hFile = -1 Then<br>        MsgBox "开启印表机埠发生错误", vbExclamation<br>    Else<br>        Open txtFilename For Binary As #1<br>        bytData = InputB(LOF(1), 1)<br>        lrc = WriteFile(hFile, bytData(0), LOF(1), lngBytesWritten, ByVal 0&)<br>        Close #1<br>    End If<br>    lclose hFile<br>End Sub<br>
<br>
<br><hr size=7 width=75%><p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 6259-->
</ul><!--end: 6259-->
<br><hr size=7 width=75%><p>

</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?