home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
code
/
print
/
abortprn
/
abortprn.frm
< prev
next >
Wrap
Text File
|
1995-02-27
|
4KB
|
121 lines
VERSION 2.00
Begin Form frmAbortTest
Caption = "Print Cancel Demo"
ClientHeight = 2655
ClientLeft = 2625
ClientTop = 1485
ClientWidth = 3705
Height = 3180
Left = 2565
LinkMode = 1 'Source
LinkTopic = "Form1"
ScaleHeight = 2655
ScaleWidth = 3705
Top = 1020
Width = 3825
Begin CommandButton cmdAbortTest
Caption = "Exit Test"
Height = 495
Index = 2
Left = 960
TabIndex = 2
Top = 1680
Width = 1815
End
Begin CommandButton cmdAbortTest
Caption = "Abort Print Job"
Height = 495
Index = 1
Left = 960
TabIndex = 0
Top = 960
Width = 1815
End
Begin CommandButton cmdAbortTest
Caption = "Start Print Job"
Height = 495
Index = 0
Left = 960
TabIndex = 1
Top = 240
Width = 1815
End
End
DefInt A-Z
Declare Function AbortDoc Lib "GDI" (ByVal hDC As Integer) As Integer
Dim Shared AbortJob As Integer
Sub cmdAbortTest_Click (Index As Integer)
Select Case Index
Case 0 ' Start Print Job
' Set Shared AbortJob to false, it will be
' reset to true if Abort Job is selected by
' user.
For PageNo = 1 To 2
AbortJob = False
For LineNo = 1 To 60
' Set up a small delay so user can see what
' is happening to print job
WaitTime! = Timer + .02
While WaitTime! > Timer: Wend
' Inform the user of what's happening
msg$ = "Printing Page:" + Str(PageNo) + " Line:" + Str(LineNo)
frmAbortTest.Caption = msg$
Printer.Print msg$
' Give user a chance to do something
DoEvents
If AbortJob Then Exit For
Next LineNo
If Not AbortJob Then Printer.NewPage
Next PageNo
If AbortJob Then Exit Sub
Printer.EndDoc
frmAbortTest.Caption = "Print Job Complete"
Case 1 ' Abort Print Job
' Set up a local error handler to handle the error we are going
' to cause shortly.
On Local Error GoTo ErrorHandler
' Call Windows' AbortDoc function in the GDI libary
junk% = AbortDoc(Printer.hDC)
' VB's printer object doesn't know you have aborted
' the print job, so when a Printer.EndDoc is issued
' VB is going to give you a printer error. Issue
' the EndDoc now while you can ignore the error.
Printer.EndDoc
frmAbortTest.Caption = "Print Job Aborted"
AbortJob = True
Case 2 ' Exit Test
End
End Select
' Exit the sub here so that you don't run into your error handling
' routine.
Exit Sub
ErrorHandler: ' Error handler for VB's printer error.
Select Case Err
Case 482 ' This is VB's printer error so
Resume Next ' ignore it!
Case Else ' If it's not the printer error
MsgBox Error(Err) ' then inform the user of the error
End ' and end program execution
End Select
End Sub
Sub Form_Load ()
' Put form in the middle of the screen
Left = (Screen.Width - Width) / 2
Top = (Screen.Height - Height) / 2
' Let'em know what program they are running
frmAbortTest.Caption = "Abort Print Job Test"
End Sub
Sub Form_Paint ()
cmdAbortTest(0).SetFocus
End Sub