Jump to content
Sign in to follow this  

Print direct to printer

Recommended Posts

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)

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

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
        Return 0
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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...