
How to Print in non graphics mode
Here's some code I copied from another post on this newsgroup a couple of
weeks ago. I hope it helps. I haven't tried it, but it is supposed to
"copy" a text file to the printer.
Annette Gates
Private Declare Function OpenPrinter& Lib "winspool.drv" Alias
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal
pDefault As Long)
Private Declare Function StartDocPrinter& Lib "winspool.drv" Alias
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long,
pDocInfo As DOC_INFO_1)
Private Declare Function StartPagePrinter& Lib "winspool.drv" (ByVal
hPrinter As Long)
Private Declare Function WritePrinter& Lib "winspool.drv" (ByVal
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long)
Private Declare Function EndDocPrinter& Lib "winspool.drv" (ByVal
hPrinter As Long)
Private Declare Function EndPagePrinter& Lib "winspool.drv" (ByVal
hPrinter As Long)
Private Declare Function ClosePrinter& Lib "winspool.drv" (ByVal
hPrinter As Long)
Private Sub mnuFilePrint_Click()
CMDialog1.CancelError = True
On Error GoTo ErrHandler
frmSDI.CMDialog1.Flags = cdlPDReturnDC Or cdlPDHidePrintToFile Or
cdlPDNoSelection Or cdlPDNoPageNums Or cdlPDAllPages
frmSDI.CMDialog1.ShowPrinter
' go directly to the printer
Dim hPrinter&
Dim PrinterName$
Dim jobid&
Dim res&
Dim written&
Dim printdata$
Dim docinfo As DOC_INFO_1
PrinterName$ = Printer.DeviceName
res& = OpenPrinter(PrinterName$, hPrinter, 0)
If res& = 0 Then
MsgBox "Can't open printer"
Exit Sub
End If
docinfo.pDocName = "Viewer Output"
docinfo.pOutputFile = vbNullString
docinfo.pDatatype = vbNullString
jobid = StartDocPrinter(hPrinter, 1, docinfo)
Call StartPagePrinter(hPrinter)
Open strOpenFileName For Input As #8
printdata$ = Input(LOF(8), 8)
Close #8
Call WritePrinter(hPrinter, ByVal printdata$, Len(printdata$), written)
Call EndPagePrinter(hPrinter)
Call EndDocPrinter(hPrinter)
Call ClosePrinter(hPrinter)
Exit Sub
ErrHandler:
' User pressed the Cancel button
Exit Sub
End Sub
Quote:
> I have this problem:
> With VB4, I want to print to a printer in non graphics mode to obtain a
> most rapidly print with the default caracter (Utility or draft). (For
> printer while Epson LQ-1050+)
> In VB4 I normally use Printer.Print to print to a printer, but this
> method print always in graphics mode.
> Can I send a text file directly to the spooler with a function (DLL) of
> Windows???
> I'm sorry for my english.
> Champion Data