求AU3如何直接LPT端口打印或者如何使用VB的CreateObject
本帖最后由 honylan 于 2009-10-8 20:59 编辑目的:打印小票,(热敏pos打印机)
已经测试的方法:1.使用windows API直接打印会出出现错误,不知道怎么回事,windows里的打印会把打印机的纸认为是A4,所以一打印,导致出来一在长条,突突突地走白纸。
(大概猜测原因是需要指定页面大小和纸型)
2.在官方英文论坛上搜到的几个例子,都有问题。
现在无法使用系统的api 那么只好直接将数据发送到LPT端口。VBS可以很简单实现。
set objfs=CreateObject("Scripting.FileSystemObject")
set objprinter=objfs.CreateTextFile ("LPT1:",true)
objprinter.Writeline "要打印的行"
现在问题是如何把上述代码转为AU3或者相关的办法。前提是不要写入VBS文件再调用VBS打印。
我想直接用AU3实现。
我看到过许多dllcall等的,不知道能不能实现.
$objfs = ObjCreate("Scripting.FileSystemObject")
$objprinter = $objfs.CreateTextFile("LPT1:", True)
$objprinter.Writeline("要打印的行")
谢谢,马上试一下 前几天网吧也要打印开机小票,,于是写了下面这个
#Region ;**** 参数创建于 AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=1.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Res_Comment=小票打印工具
#AutoIt3Wrapper_Res_Description=小票打印工具--阿宝
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_LegalCopyright=阿宝
#AutoIt3Wrapper_Run_Obfuscator=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <ACN_String.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("小票打印 程序制作:阿宝", 255, 188, 315, 235)
$Label1 = GUICtrlCreateLabel("输入押金:", 16, 64, 55, 17)
$Label2 = GUICtrlCreateLabel("输入机号:", 16, 103, 55, 17)
$Input1 = GUICtrlCreateInput("", 80, 96, 153, 21,$ES_NUMBER)
GUICtrlSetColor(-1, 0x0000FF)
$Label3 = GUICtrlCreateLabel("网吧名称:", 16, 24, 55, 17)
$Button1 = GUICtrlCreateButton("打印", 80, 144, 65, 25, 0)
$Button2 = GUICtrlCreateButton("退出", 169, 143, 65, 25, 0)
$Input2 = GUICtrlCreateInput("10", 80, 56, 153, 21)
GUICtrlSetColor(-1, 0x0000FF)
$Input3 = GUICtrlCreateInput(" XX网络会所", 81, 19, 153, 21)
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
HotKeySet ( "{Enter}" , "okk" )
While 1
$msg= GUIGetMsg()
Select
Case $msg=$Button2 or $msg=$GUI_EVENT_CLOSE
Exit
Case $msg=$Button1
$time=@MON &"/"& @MDAY & "/"&@HOUR & ":"&@MIN
$file = FileOpen("pr.txt", 2)
If $file = -1 Then
MsgBox(0, "错误", "pr.txt句柄无法打开")
Exit
EndIf
$wbnm=GUICtrlRead($Input3)
$yj=GUICtrlRead($Input2)
$jh=GUICtrlRead($Input1)
if $jh=="" Then
MsgBox(16,"错误","机号不能为空",3)
exit
endif
FileWrite($file, $wbnm & @CRLF& @CRLF)
FileWrite($file, "机号:" &$jh& @CRLF)
FileWrite($file, "押金:"&$yj& "元"& @CRLF)
FileWrite($file, $time)
FileClose($file)
ShellExecute("pr.txt", "", @ScriptDir, "print")
exit
EndSelect
WEnd
exit
Func okk()
ControlClick ( $Form1, "", $Button1)
EndFunc 很不错!!!风格 #include <EditConstants.au3> 多谢,正好测试下!
页:
[1]