Sign in to follow this  
Followers 0
tAKTelapis

Print direct to printer

1 post in this topic

#1 ·  Posted (edited)

Hi Guys,

My script prints the inputted data to a reciept printer.

Is there anyway of doing this without writing a temporary file.

I would also like to be able to specify the printer name to use (instead of forcing a default)

Here is my code (currently working 100%):

#Include <GUIConstants.au3>

$GUI = GUICreate("Input Details", 200, 150)
GUICtrlCreateLabel("Username:", 10, 10)
$inpt_Name = GUICtrlCreateInput("", 10, 25, 180, 25)
GUICtrlCreateLabel("Password:", 10, 55)
$inpt_PWord = GUICtrlCreateInput("", 10, 75, 180, 25)
$btn_Print = GUICtrlCreateButton("Print", 75, 120, 50, 25)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Select
    Case $Msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $Msg = $btn_Print
        $File = FileOpen("c:\temp.txt", 2)
        FileWriteLine($File, GUICtrlRead($inpt_Name))
        FileWriteLine($File, GUICtrlRead($inpt_PWord))
        FileClose($File)
        _FilePrint("c:\temp.txt")
        GUICtrlSetData($inpt_Name, "")
        GUICtrlSetData($inpt_PWord, "")
    EndSelect
WEnd

Func _FilePrint($s_File, $i_Show = @SW_HIDE)
    Local $a_Ret = DllCall("shell32.dll", "long", "ShellExecute", _
            "hwnd", 0, _
            "string", "print", _
            "string", $s_File, _
            "string", "", _
            "string", "", _
            "int", $i_Show)
    If $a_Ret[0] > 32 And Not @error Then
        Return 1
    Else
        SetError($a_Ret[0])
        Return 0
    EndIf
EndFunc   ;==>_FilePrint

ps: i copied the _FilePrint() function into my script so that i didnt have to have the rest of the file.au3 included.

Edited by tAKTelapis

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0