Appendix B
‘Specify Default Filter CommonDialog1.FilterIndex = 1 ‘Display Open dialog box CommonDialog1.ShowOpen loadfile = CommonDialog1.FileName Label2.Caption = loadfile
Exit Sub
ErrHandler:
Exit Sub
End Sub
Private Sub cmdStoreImage_Click()
Dim hPrinter&
Dim jobid&
Dim res&
Dim written&
Dim printdata$
Dim docinfo As DOC_INFO_1
loadfile = Form1.txtFile.Text If loadfile = ““ Then
MsgBox “You must Open a file to send”, vbExclamation Exit Sub
End If
‘Open file. f1 = FreeFile
Open loadfile For Binary As f1
‘Open printer for printing
res& = OpenPrinter(SelPrinter, hPrinter, 0) If res = 0 Then
MsgBox “Unable to open the printer” Exit Sub
End If
docinfo.pDocName = “MyDoc” docinfo.pOutputFile = vbNullString docinfo.pDatatype = vbNullString
jobid = StartDocPrinter(hPrinter, 1, docinfo) Call StartPagePrinter(hPrinter)
Call WritePrinter(hPrinter, ByVal printdata$, Len(printdata$), written) While Not EOF(1)
Get #f1, , ch printdata$ = ch
Call WritePrinter(hPrinter, ByVal printdata$, Len(printdata$),
written) Wend
Call EndPagePrinter(hPrinter)
Call EndDocPrinter(hPrinter)
Call ClosePrinter(hPrinter) ‘ Close when done
‘Close file Close #1
MsgBox “File sent to print spooler.”, vbExclamation
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
81 |