Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to Cancel Default Printer Jobs 1

Status
Not open for further replies.

waytech2003

Programmer
Jul 14, 2003
316
US
I would like to know if there is a way to cancel all jobs that are setting in the default printer que.

I know it can be done in the Priner properties via Start-Printers menu, but my customer wants it on one of my forms.

I assume I will have to call an API but have nno idea which one.

Wayne Lette
 
You can use Printer.KillDoc to kill the current printing document

So I suppose if you keep calling KillDoc, you should eventually kill all the qued documents, seeing that as one job is deleted, another one starts in its place

Hope this helps

*****************************************
May the Code Be With You...[lightsaber]
----------
x50-8 (X Fifty Eigt)
 
x508, I tried that and it will not work. Killdoc only effects a print that is currently being created. After an EndDoc, KillDoc does not seem to apply.

One thing I should note is the que'd documents are VB6 Printer.Printform calls that my program called. There may be 20 or 30 waiting to print when the customer wants to bail out. These will all be individual Doc's in the que.
 
I've just copied and pasted this from various modules in a large project and simplified the fundtion somewhat so I hope I didn't miss any bits. Call the fSetPrinterStatus function with lngStatus = 3 (purge).
Code:
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const PRINTER_ACCESS_ADMINISTER = &H4
Public Const PRINTER_ACCESS_USE = &H8
Public Const PRINTER_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED _
Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE

'Printer Control constants to use with SetPrinter
Public Const PRINTER_CONTROL_PAUSE = 1
Public Const PRINTER_CONTROL_RESUME = 2
Public Const PRINTER_CONTROL_PURGE = 3

'Null pointer
Public Const NULLPTR = 0&

Public Type PRINTER_INFO_2
    pServerName As Long
    pPrinterName As Long
    pShareName As Long
    pPortName As Long
    pDriverName As Long
    pComment As Long
    pLocation As Long
    pDevmode As Long       ' Pointer to DEVMODE
    pSepFile As Long
    pPrintProcessor As Long
    pDatatype As Long
    pParameters As Long
    pSecurityDescriptor As Long
    Attributes As Long
    Priority As Long
    DefaultPriority As Long
    StartTime As Long
    UntilTime As Long
    Status As Long
    cJobs As Long
    AveragePPM As Long
End Type

Public Type PRINTER_DEFAULTS
    pDatatype As Long
    pDevmode As Long
    DesiredAccess As Long
End Type

Public Declare Function OpenPrinter1 Lib "winspool.drv" _
Alias "OpenPrinterA" _
(ByVal pPrinterName As String, _
phPrinter As Long, _
pDefault As PRINTER_DEFAULTS) As Long

Public Declare Function SetPrinter Lib "winspool.drv" _
Alias "SetPrinterA" _
(ByVal hPrinter As Long, _
ByVal Level As Long, _
pPrinter As Any, _
ByVal Command As Long) As Long

Public Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long

Public Declare Function GetLastError Lib "kernel32.dll" () As Long

'Printer control enums
Public Enum PDXPrinterControl
    pdxPrinterControlPause = PRINTER_CONTROL_PAUSE
    pdxPrinterControlPurge = PRINTER_CONTROL_PURGE
    pdxPrinterControlResume = PRINTER_CONTROL_RESUME
End Enum
'_____________________________________

Public Function fSetPrinterStatus(ByVal strPrinterName As String, _
ByVal lngStatus As PDXPrinterControl) As Boolean

    '--- Sets the status of the specified printer
    '     to a PDXPrinterControl enum
    
    '--- Parameters
    '     [In]
    '     strPrinterName: name of the printer to change
    '     lngStatus: status to set. One of pause, purge or resume
    

    '--- Return value
    '     returns True if the status was set successfully else False if an error occurred
    
    Dim pudtPD As PRINTER_DEFAULTS  'PRINTER_DEFAULTS structure
    Dim pudtPI2 As PRINTER_INFO_2   'PRINTER_INFO_2 structure
    Dim phPrinter As Long           'handle to printer
    Dim plngSizeReq As Long         'Size in bytes needed to hold a structure
    Dim plngRtn As Long             'Return value
    Dim plngTmp As Long             'Temp buffer
    Dim pblnRtn As Boolean          'return value
    Dim pabytPI() As Byte           'Byte array to hold the PRINTER_DEFAULTS structure
    
    'Get a handle to the printer.
    pudtPD.DesiredAccess = PRINTER_ALL_ACCESS
    plngRtn = OpenPrinter1(strPrinterName, phPrinter, pudtPD)
    If plngRtn = 0 Or phPrinter = 0 Then
        'Failed to open the printer
        fSetPrinterStatus = False
        Exit Function
    End If
    
    'Set the printer status
    plngRtn = SetPrinter(phPrinter, NULLPTR, ByVal NULLPTR, lngStatus)
    If plngRtn = 0 Then
        'Status set failed
        fSetPrinterStatus = False
        GoTo ExitFunc
    End If
    'Return value
    fSetPrinterStatus = True
    
ExitFunc:
    If Not phPrinter = 0 Then
        ClosePrinter phPrinter
    End If

End Function

Paul Bent
Northwind IT Systems
 

In this thread713-745303 there is a start of what you will need to know to accomplish what you want.

Good Luck (your gonna need it) :)

 
Thank you Paul Bent, your code worked perfectly and you have a new star.

Wayne Lette
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top