home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / print / abortprn / abortprn.frm < prev    next >
Text File  |  1995-02-27  |  4KB  |  121 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          =   3180
  9.    Left            =   2565
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   2655
  13.    ScaleWidth      =   3705
  14.    Top             =   1020
  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. End
  44. DefInt A-Z
  45. Declare Function AbortDoc Lib "GDI" (ByVal hDC As Integer) As Integer
  46. Dim Shared AbortJob As Integer
  47.  
  48. Sub cmdAbortTest_Click (Index As Integer)
  49.     Select Case Index
  50.     Case 0              '   Start Print Job
  51.         '   Set Shared AbortJob to false, it will be
  52.         '   reset to true if Abort Job is selected by
  53.         '   user.
  54.         For PageNo = 1 To 2
  55.         AbortJob = False
  56.         For LineNo = 1 To 60
  57.             '   Set up a small delay so user can see what
  58.             '   is happening to print job
  59.             WaitTime! = Timer + .02
  60.             While WaitTime! > Timer: Wend
  61.             '   Inform the user of what's happening
  62.             msg$ = "Printing Page:" + Str(PageNo) + " Line:" + Str(LineNo)
  63.             frmAbortTest.Caption = msg$
  64.             Printer.Print msg$
  65.             '   Give user a chance to do something
  66.             DoEvents
  67.             If AbortJob Then Exit For
  68.         Next LineNo
  69.         If Not AbortJob Then Printer.NewPage
  70.         Next PageNo
  71.         If AbortJob Then Exit Sub
  72.         Printer.EndDoc
  73.         frmAbortTest.Caption = "Print Job Complete"
  74.     Case 1              '   Abort Print Job
  75.         '   Set up a local error handler to handle the error we are going
  76.         '   to cause shortly.
  77.         On Local Error GoTo ErrorHandler
  78.         '   Call Windows' AbortDoc function in the GDI libary
  79.         junk% = AbortDoc(Printer.hDC)
  80.         '   VB's printer object doesn't know you have aborted
  81.         '   the print job, so when a Printer.EndDoc is issued
  82.         '   VB is going to give you a printer error.  Issue
  83.         '   the EndDoc now while you can ignore the error.
  84.         Printer.EndDoc
  85.         frmAbortTest.Caption = "Print Job Aborted"
  86.         AbortJob = True
  87.     Case 2                  '   Exit Test
  88.         End
  89.     End Select
  90.  
  91. '   Exit the sub here so that you don't run into your error handling
  92. '   routine.
  93. Exit Sub
  94.  
  95. ErrorHandler:                   ' Error handler for VB's printer error.
  96.  
  97.     Select Case Err
  98.     Case 482                ' This is VB's printer error so
  99.         Resume Next         ' ignore it!
  100.     Case Else               ' If it's not the printer error
  101.         MsgBox Error(Err)   ' then inform the user of the error
  102.         End                 ' and end program execution
  103.     End Select
  104.  
  105.     
  106.  
  107. End Sub
  108.  
  109. Sub Form_Load ()
  110.     '   Put form in the middle of the screen
  111.     Left = (Screen.Width - Width) / 2
  112.     Top = (Screen.Height - Height) / 2
  113.     '   Let'em know what program they are running
  114.     frmAbortTest.Caption = "Abort Print Job Test"
  115. End Sub
  116.  
  117. Sub Form_Paint ()
  118.     cmdAbortTest(0).SetFocus
  119. End Sub
  120.  
  121.