home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / abortprn / abortprn.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-09-06  |  3.7 KB  |  110 lines

  1. VERSION 2.00
  2. Begin Form frmAbortTest 
  3.    Caption         =   "Print Cancel Demo"
  4.    ClientHeight    =   2655
  5.    ClientLeft      =   2625
  6.    ClientTop       =   1485
  7.    ClientWidth     =   3705
  8.    Height          =   3060
  9.    Left            =   2565
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   2655
  13.    ScaleWidth      =   3705
  14.    Top             =   1140
  15.    Width           =   3825
  16.    Begin CommandButton cmdAbortTest 
  17.       Caption         =   "Exit Test"
  18.       Height          =   495
  19.       Index           =   2
  20.       Left            =   960
  21.       TabIndex        =   2
  22.       Top             =   1680
  23.       Width           =   1815
  24.    End
  25.    Begin CommandButton cmdAbortTest 
  26.       Caption         =   "Abort Print Job"
  27.       Height          =   495
  28.       Index           =   1
  29.       Left            =   960
  30.       TabIndex        =   0
  31.       Top             =   960
  32.       Width           =   1815
  33.    End
  34.    Begin CommandButton cmdAbortTest 
  35.       Caption         =   "Start Print Job"
  36.       Height          =   495
  37.       Index           =   0
  38.       Left            =   960
  39.       TabIndex        =   1
  40.       Top             =   240
  41.       Width           =   1815
  42.    End
  43. DefInt A-Z
  44. Declare Function AbortDoc Lib "GDI" (ByVal hDC As Integer) As Integer
  45. Dim Shared AbortJob As Integer
  46. Sub cmdAbortTest_Click (Index As Integer)
  47.     Select Case Index
  48.     Case 0              '   Start Print Job
  49.         '   Set Shared AbortJob to false, it will be
  50.         '   reset to true if Abort Job is selected by
  51.         '   user.
  52.         For PageNo = 1 To 2
  53.         AbortJob = False
  54.         For LineNo = 1 To 60
  55.             '   Set up a small delay so user can see what
  56.             '   is happening to print job
  57.             WaitTime! = Timer + .02
  58.             While WaitTime! > Timer: Wend
  59.             '   Inform the user of what's happening
  60.             msg$ = "Printing Page:" + Str(PageNo) + " Line:" + Str(LineNo)
  61.             frmAbortTest.Caption = msg$
  62.             Printer.Print msg$
  63.             '   Give user a chance to do something
  64.             DoEvents
  65.             If AbortJob Then Exit For
  66.         Next LineNo
  67.         If Not AbortJob Then Printer.NewPage
  68.         Next PageNo
  69.         If AbortJob Then Exit Sub
  70.         Printer.EndDoc
  71.         frmAbortTest.Caption = "Print Job Complete"
  72.     Case 1              '   Abort Print Job
  73.         '   Set up a local error handler to handle the error we are going
  74.         '   to cause shortly.
  75.         On Local Error GoTo ErrorHandler
  76.         '   Call Windows' AbortDoc function in the GDI libary
  77.         junk% = AbortDoc(Printer.hDC)
  78.         '   VB's printer object doesn't know you have aborted
  79.         '   the print job, so when a Printer.EndDoc is issued
  80.         '   VB is going to give you a printer error.  Issue
  81.         '   the EndDoc now while you can ignore the error.
  82.         Printer.EndDoc
  83.         frmAbortTest.Caption = "Print Job Aborted"
  84.         AbortJob = True
  85.     Case 2                  '   Exit Test
  86.         End
  87.     End Select
  88. '   Exit the sub here so that you don't run into your error handling
  89. '   routine.
  90. Exit Sub
  91. ErrorHandler:                   ' Error handler for VB's printer error.
  92.     Select Case Err
  93.     Case 482                ' This is VB's printer error so
  94.         Resume Next         ' ignore it!
  95.     Case Else               ' If it's not the printer error
  96.         MsgBox Error(Err)   ' then inform the user of the error
  97.         End                 ' and end program execution
  98.     End Select
  99. End Sub
  100. Sub Form_Load ()
  101.     '   Put form in the middle of the screen
  102.     Left = (Screen.Width - Width) / 2
  103.     Top = (Screen.Height - Height) / 2
  104.     '   Let'em know what program they are running
  105.     frmAbortTest.Caption = "Abort Print Job Test"
  106. End Sub
  107. Sub Form_Paint ()
  108.     cmdAbortTest(0).SetFocus
  109. End Sub
  110.