Results 1 to 2 of 2

Thread: printing

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Location
    kl
    Posts
    1

    printing

    hi,

    basically my problem is like this:

    I want the printer to send status to my application if there is something error while printing my documents.

    can i use abortprinter function?. but the thing is that - i don't know what parameter should i pass. example please.

    thanks,
    amelia

  2. #2
    jim mcnamara
    Guest
    This is a lot messier than you would like. Or I would like.
    Not all printers can be queried. About all you can do is this:

    Code:
    Sub PrintStuff()
    On Eroro goto OOPS
    ' put your code to print stuff in here
    
    Printer.EndDoc
    Exit Sub
    
    OOPS:
    Printer.KillDoc  ' this aborts printing
    
    End Sub
    The reason for this is that printer messages get intercepted by the driver, so you can't just go out and query the printer 'Are You Okay?' and get an answer back. Plus, the actual message you send is different for each kind of printer, especially line printers.

    To send something DIRECTLY to the printer use the Escape api.

    Here is sample escape api code from allapi.net
    Code:
    Const NEWFRAME = 1
    Private Declare Function Escape Lib "gdi32" (ByVal hdc As Long, ByVal nEscape As Long, ByVal nCount As Long, ByVal lpInData As String, lpOutData As Any) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Dim hMemoryDC As Long
    Private Sub Command1_Click()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'API uses pixels
        Picture1.ScaleMode = vbPixels
        Printer.ScaleMode = vbPixels
        'Take paper
        Printer.Print ""
    
        'Create a compatible device context
        hMemoryDC = CreateCompatibleDC(Picture1.hdc)
        'Select Picture1's picture into our new device context
        hOldBitMap = SelectObject(hMemoryDC, Picture1.Picture)
    
        'Stretch our picture to the height and width of the paper
        StretchBlt Printer.hdc, 0, 0, Printer.ScaleWidth, Printer.ScaleHeight, hMemoryDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbSrcCopy
    
        'Select the original bitmap into our DC
        hOldBitMap = SelectObject(hMemoryDC, hOldBitMap)
        'Delete our memorydc
        DeleteDC hMemoryDC
    
        'Access our printer device
        Escape Printer.hdc, NEWFRAME, 0, 0&, 0&
    
        'End of document
        Printer.EndDoc
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width