如何在VB程序下生成二维条码
答案:2 悬赏:10 手机版
解决时间 2021-01-04 06:13
- 提问者网友:遮云壑
- 2021-01-03 13:31
如何在VB程序下生成二维条码
最佳答案
- 五星知识达人网友:十鸦
- 2021-01-22 06:17
如何在VB程序下生成二维条码,包括PDF417、QrCode、DataMatrix和汉信二维条码,具体步驺如下:
工具/原料
准备VB开发环境,VS6.0开发环境
方法/步骤
创建VB工程,COPY二维条码动态链接库到您的工程中。您需要引用的动态库有:EnCodePdf.dll,EnCodeQr.dll,EnDataMatrix和EnHanxin.dll。
大家可以参照下图放置DLL和INI的目录位置。
'动态链接库引用
(说明:下面是所有四种条码的接口引用申明,读者可以适当剪裁)
'串口接口
Private Declare FunctionInitRead Lib "EnCodePdf.dll" (ByVal hcallwnd As Long, ByVal pathnameAs String) As Long
Private Declare FunctionCloseRead Lib "EnCodePdf.dll" () As Long
'生成PDF417接口
Private Declare SubSetPdfConFile Lib "EnCodePdf.dll" (ByVal confile As String)
Private Declare FunctionEnPdfText Lib "EnCodePdf.dll" (ByVal txtData As String, ByVal outfileAs String) As String
Private Declare FunctionEnCodePdf Lib "EnCodePdf.dll" (ByVal txtfile As String, ByVal outfileAs String) As String
Private Declare FunctionMakePdf417 Lib "EnCodePdf.dll" (ByVal txtfile As String, ByValpictfile As String, ByVal otherfile As String, ByVal outfile As String) AsString
'生成QrCode接口
Private Declare SubSetQrConFile Lib "EnCodeQr.dll" (ByVal confile As String)
Private Declare FunctionEnQrText Lib "EnCodeQr.dll" (ByVal txtData As String, ByVal outfileAs String) As String
Private Declare FunctionEnCodeQr Lib "EnCodeQr.dll" (ByVal txtfile As String, ByVal outfileAs String) As String
Private Declare FunctionMakeQrCode Lib "EnCodeQr.dll" (ByVal txtfile As String, ByVal pictfileAs String, ByVal otherfile As String, ByVal outfile As String) As String
'生成DataMatrix接口
Private Declare SubSetDmConFile Lib "EnDataMatrix.dll" (ByVal confile As String)
Private Declare FunctionEnDmText Lib "EnDataMatrix.dll" (ByVal txtData As String, ByValoutfile As String) As String
Private Declare FunctionEnDataMatrix Lib "EnDataMatrix.dll" (ByVal txtfile As String, ByValoutfile As String) As String
Private Declare FunctionMakeDataMatrix Lib "EnDataMatrix.dll" (ByVal txtfile As String, ByValpictfile As String, ByVal otherfile As String, ByVal outfile As String) AsString
'生成HanXin接口
Private Declare SubSetHxConFile Lib "EnHanXin.dll" (ByVal confile As String)
Private Declare FunctionEnHxText Lib "EnHanXin.dll" (ByVal txtData As String, ByVal outfileAs String) As String
Private Declare FunctionEnCodeHx Lib "EnHanXin.dll" (ByVal txtfile As String, ByVal outfileAs String) As String
Private Declare FunctionMakeHanXin Lib "EnHanXin.dll" (ByVal txtfile As String, ByValpictfile As String, ByVal otherfile As String, ByVal outfile As String) AsString
'WAPI接口
Private Declare FunctionSetCurrentDirectory Lib "kernel32" Alias"SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Private Declare FunctionWritePrivateProfileString Lib "kernel32" Alias"WritePrivateProfileStringA" (ByVal lpApplicationName As String,ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) AsLong
Private Declare FunctionGetPrivateProfileInt Lib "kernel32" Alias"GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVallpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) AsLong
Private Declare FunctionGetPrivateProfileString Lib "kernel32" Alias"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVallpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String,ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare FunctionSetWindowLong Lib "user32" Alias "SetWindowLongA" (ByValhwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare FunctionSetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParentAs Long) As Long
'生成图像小波压缩接口
'exports from nlcomp.dll 图像压缩函数
Private Declare FunctionSizeDIB Lib "Wcomp.dll" (ByVal oldmap As String, ByVal BmpHeight AsInteger, ByVal BmpWidth As Integer) As Long
Private Declare FunctionWcompress Lib "Wcomp.dll" (ByVal infile As String, ByVal outfile AsString, ByVal budget As Long) As Long
Private Declare FunctionWdecompress Lib "Wcomp.dll" (ByVal infile As String, ByVal outfile AsString) As Long
进行条形码制作:
我们在引用API接口后,可以参照下面程序,实现接口调用
程序中txtfile表示文本文件名,binBmpFile表示输入的图像文件名
若需要装载图像可以采用Make开头接口,若不需要则采用En开头接口。
If (txtfile<> "" Or binBmpFile <> "") Then
If m_bWorkMode = 1 Then 'PDF417
SetPdfConFile (Edit_ConFileName.Text)
If (Edit_ImgFileName.Text <> "") Then
strBmpFile = MakePdf417(txtfile, binBmpFile,"", "")
Else
strBmpFile = EnPdfText(Edit_Source.Text,"")
End If
ElseIf m_bWorkMode = 2 Then 'Qr_Code
SetQrConFile (Edit_ConFileName.Text)
If (Edit_ImgFileName.Text <> "") Then
strBmpFile = MakeQrCode(txtfile, binBmpFile,"", "")
Else
strBmpFile = EnQrText(Edit_Source.Text,"")
End If
ElseIf m_bWorkMode = 3 Then ' DataMatrix
SetDmConFile (Edit_ConFileName.Text)
If (Edit_ImgFileName.Text <> "") Then
strBmpFile = MakeDataMatrix(txtfile,binBmpFile, "", "")
Else
strBmpFile = EnDmText(Edit_Source.Text,"")
End If
Else
SetHxConFile (Edit_ConFileName.Text)
If (Edit_ImgFileName.Text <> "") Then
strBmpFile = MakeHanXin(txtfile, binBmpFile,"", "")
Else
strBmpFile = EnHxText(Edit_Source.Text,"")
End If
End If
打开关闭串口:
条码编码控件一般自带串口接收处理接口:
InitRead接口是初始化串口
CloseRead接口是关闭串口
If Cmd_OpenComm.Caption = "连接串口" Then
Call SetPdfConFile(Edit_ConFileName.Text)
If InitRead(Me.hwnd, App.Path + "\") = 1 Then
Cmd_OpenComm.Caption = "断开串口"
End If
Else '关闭串口
If CloseRead() = 1 Then
Cmd_OpenComm.Caption = "连接串口"
End If
End If
接收条码识读器内容:
串口收到识读器信息后,以键盘消息的形式,触发页面消息。
我们调用FORM下,处理KeyDown事件。
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim FileNo As Integer
Dim strTmp As String
Dim strBmpFile As String
strBmpFile = App.Path & "\temp.bmp"
If KeyCode = 255 Then
FileNo = FreeFile()
Open App.Path & "\temp.txt" For Input As #FileNo
Edit_Source.Text = ""
Do While Not EOF(FileNo)
strTmp = ""
Input #FileNo, strTmp
Edit_Source.Text = Edit_Source.Text & strTmp & Chr(13) & Chr(10)
Loop
Close #FileNo
If Dir(strBmpFile) <> "" Then
Kill (strBmpFile)
End If
If Dir(App.Path & "\temp.img") <> "" Then
If FileLen(App.Path & "\temp.img") > 10 Then
Call Wdecompress(App.Path & "\temp.img", strBmpFile)
End If
End If
If Dir(strBmpFile) <> "" Then
Image_Bar.Picture = LoadPicture(strBmpFile)
Else
Image_Bar.Picture = LoadPicture("")
End If
Cmd_Print.Enabled = False
End If
End Sub
工具/原料
准备VB开发环境,VS6.0开发环境
方法/步骤
创建VB工程,COPY二维条码动态链接库到您的工程中。您需要引用的动态库有:EnCodePdf.dll,EnCodeQr.dll,EnDataMatrix和EnHanxin.dll。
大家可以参照下图放置DLL和INI的目录位置。
'动态链接库引用
(说明:下面是所有四种条码的接口引用申明,读者可以适当剪裁)
'串口接口
Private Declare FunctionInitRead Lib "EnCodePdf.dll" (ByVal hcallwnd As Long, ByVal pathnameAs String) As Long
Private Declare FunctionCloseRead Lib "EnCodePdf.dll" () As Long
'生成PDF417接口
Private Declare SubSetPdfConFile Lib "EnCodePdf.dll" (ByVal confile As String)
Private Declare FunctionEnPdfText Lib "EnCodePdf.dll" (ByVal txtData As String, ByVal outfileAs String) As String
Private Declare FunctionEnCodePdf Lib "EnCodePdf.dll" (ByVal txtfile As String, ByVal outfileAs String) As String
Private Declare FunctionMakePdf417 Lib "EnCodePdf.dll" (ByVal txtfile As String, ByValpictfile As String, ByVal otherfile As String, ByVal outfile As String) AsString
'生成QrCode接口
Private Declare SubSetQrConFile Lib "EnCodeQr.dll" (ByVal confile As String)
Private Declare FunctionEnQrText Lib "EnCodeQr.dll" (ByVal txtData As String, ByVal outfileAs String) As String
Private Declare FunctionEnCodeQr Lib "EnCodeQr.dll" (ByVal txtfile As String, ByVal outfileAs String) As String
Private Declare FunctionMakeQrCode Lib "EnCodeQr.dll" (ByVal txtfile As String, ByVal pictfileAs String, ByVal otherfile As String, ByVal outfile As String) As String
'生成DataMatrix接口
Private Declare SubSetDmConFile Lib "EnDataMatrix.dll" (ByVal confile As String)
Private Declare FunctionEnDmText Lib "EnDataMatrix.dll" (ByVal txtData As String, ByValoutfile As String) As String
Private Declare FunctionEnDataMatrix Lib "EnDataMatrix.dll" (ByVal txtfile As String, ByValoutfile As String) As String
Private Declare FunctionMakeDataMatrix Lib "EnDataMatrix.dll" (ByVal txtfile As String, ByValpictfile As String, ByVal otherfile As String, ByVal outfile As String) AsString
'生成HanXin接口
Private Declare SubSetHxConFile Lib "EnHanXin.dll" (ByVal confile As String)
Private Declare FunctionEnHxText Lib "EnHanXin.dll" (ByVal txtData As String, ByVal outfileAs String) As String
Private Declare FunctionEnCodeHx Lib "EnHanXin.dll" (ByVal txtfile As String, ByVal outfileAs String) As String
Private Declare FunctionMakeHanXin Lib "EnHanXin.dll" (ByVal txtfile As String, ByValpictfile As String, ByVal otherfile As String, ByVal outfile As String) AsString
'WAPI接口
Private Declare FunctionSetCurrentDirectory Lib "kernel32" Alias"SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Private Declare FunctionWritePrivateProfileString Lib "kernel32" Alias"WritePrivateProfileStringA" (ByVal lpApplicationName As String,ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) AsLong
Private Declare FunctionGetPrivateProfileInt Lib "kernel32" Alias"GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVallpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) AsLong
Private Declare FunctionGetPrivateProfileString Lib "kernel32" Alias"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVallpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String,ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare FunctionSetWindowLong Lib "user32" Alias "SetWindowLongA" (ByValhwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare FunctionSetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParentAs Long) As Long
'生成图像小波压缩接口
'exports from nlcomp.dll 图像压缩函数
Private Declare FunctionSizeDIB Lib "Wcomp.dll" (ByVal oldmap As String, ByVal BmpHeight AsInteger, ByVal BmpWidth As Integer) As Long
Private Declare FunctionWcompress Lib "Wcomp.dll" (ByVal infile As String, ByVal outfile AsString, ByVal budget As Long) As Long
Private Declare FunctionWdecompress Lib "Wcomp.dll" (ByVal infile As String, ByVal outfile AsString) As Long
进行条形码制作:
我们在引用API接口后,可以参照下面程序,实现接口调用
程序中txtfile表示文本文件名,binBmpFile表示输入的图像文件名
若需要装载图像可以采用Make开头接口,若不需要则采用En开头接口。
If (txtfile<> "" Or binBmpFile <> "") Then
If m_bWorkMode = 1 Then 'PDF417
SetPdfConFile (Edit_ConFileName.Text)
If (Edit_ImgFileName.Text <> "") Then
strBmpFile = MakePdf417(txtfile, binBmpFile,"", "")
Else
strBmpFile = EnPdfText(Edit_Source.Text,"")
End If
ElseIf m_bWorkMode = 2 Then 'Qr_Code
SetQrConFile (Edit_ConFileName.Text)
If (Edit_ImgFileName.Text <> "") Then
strBmpFile = MakeQrCode(txtfile, binBmpFile,"", "")
Else
strBmpFile = EnQrText(Edit_Source.Text,"")
End If
ElseIf m_bWorkMode = 3 Then ' DataMatrix
SetDmConFile (Edit_ConFileName.Text)
If (Edit_ImgFileName.Text <> "") Then
strBmpFile = MakeDataMatrix(txtfile,binBmpFile, "", "")
Else
strBmpFile = EnDmText(Edit_Source.Text,"")
End If
Else
SetHxConFile (Edit_ConFileName.Text)
If (Edit_ImgFileName.Text <> "") Then
strBmpFile = MakeHanXin(txtfile, binBmpFile,"", "")
Else
strBmpFile = EnHxText(Edit_Source.Text,"")
End If
End If
打开关闭串口:
条码编码控件一般自带串口接收处理接口:
InitRead接口是初始化串口
CloseRead接口是关闭串口
If Cmd_OpenComm.Caption = "连接串口" Then
Call SetPdfConFile(Edit_ConFileName.Text)
If InitRead(Me.hwnd, App.Path + "\") = 1 Then
Cmd_OpenComm.Caption = "断开串口"
End If
Else '关闭串口
If CloseRead() = 1 Then
Cmd_OpenComm.Caption = "连接串口"
End If
End If
接收条码识读器内容:
串口收到识读器信息后,以键盘消息的形式,触发页面消息。
我们调用FORM下,处理KeyDown事件。
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim FileNo As Integer
Dim strTmp As String
Dim strBmpFile As String
strBmpFile = App.Path & "\temp.bmp"
If KeyCode = 255 Then
FileNo = FreeFile()
Open App.Path & "\temp.txt" For Input As #FileNo
Edit_Source.Text = ""
Do While Not EOF(FileNo)
strTmp = ""
Input #FileNo, strTmp
Edit_Source.Text = Edit_Source.Text & strTmp & Chr(13) & Chr(10)
Loop
Close #FileNo
If Dir(strBmpFile) <> "" Then
Kill (strBmpFile)
End If
If Dir(App.Path & "\temp.img") <> "" Then
If FileLen(App.Path & "\temp.img") > 10 Then
Call Wdecompress(App.Path & "\temp.img", strBmpFile)
End If
End If
If Dir(strBmpFile) <> "" Then
Image_Bar.Picture = LoadPicture(strBmpFile)
Else
Image_Bar.Picture = LoadPicture("")
End If
Cmd_Print.Enabled = False
End If
End Sub
全部回答
- 1楼网友:逐風
- 2021-01-22 06:30
你学习的话 用一个office的附带的barcode控件即可,输出是图像格式 http://www.programfan.com/blog/article.asp?id=2505 不过专业的条码打印还是用vb的printer控件line函数以画图方式输出最好 我曾开发过多种标准的条形码控件,不过是商业软件不好开放 这里有个39码的例子,你不妨看看 http://www.3800hk.com/article/cxsj/vb/bcslvb/2005-08-06/article_47920.html
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
正方形一边上任一点到这个正方形两条对角线的 |
阴历怎么看 ? |