Print bitmap

Windows specific questions.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Print bitmap

Postby MichaelW » Jun 27, 2006 22:19

This is a test of a procedure that prints a bitmap file to a Windows printer, wysiwyg.

EDIT: Corrected syntax and removed multiline comment so source will compile with FBC v0.15b.

Code: Select all

#include "windows.bi"
#include "win\commdlg.bi"
option explicit

'*************************************************************************

function FileLength( filename as string )

    dim as integer handle, length

    handle = freefile
    open filename for input as #handle
    length = lof( handle )
    close #handle
    return length

end function

function GetFile( filename as string, buffer as byte ptr )

    dim as integer handle, length, res

    length = FileLength( filename )
    buffer = allocate( length )
    handle = freefile
    open filename for binary as #handle
    res = get( #handle, , *buffer, length )
    close #handle
    return res

end function

function PrintBMP( filename as string )

    dim as LPBITMAPFILEHEADER lpbmfh
    dim as LPBITMAPINFO lpbmi
    dim as byte ptr buffer
    dim as HANDLE hDesktopDC

    dim as PRINTDLG pd
    dim as DOCINFO di

    dim as single fLogPelsX1, fLogPelsX2, fLogPelsY1, fLogPelsY2
    dim as single fScaleX, fScaleY

    '' GetFile will allocate a buffer of the required size, assign
    '' the address of the buffer to <buffer>, copy the file data to
    '' the buffer, and return whatever GET # returned, either 0 or
    '' an error code.
    ''
    if GetFile( filename, buffer ) then
        print "Error getting file"
        sleep
        deallocate( buffer )
        return
    endif

    '' Set up the necessary buffer pointers. A BMP file starts with
    '' a 14-byte BITMAPFILEHEADER structure, followed immediately by
    '' a BITMAPINFO (or BITMAPCOREINFO) structure.
    ''
    lpbmfh = cast( LPBITMAPFILEHEADER, buffer )
    lpbmi = cast( LPBITMAPINFO, buffer + 14 )

    '' Initialize the PRINTDLG and DOCINFO structures.
    ''
    pd.lStructSize = sizeof( PRINTDLG )
    pd.Flags = PD_RETURNDC or PD_USEDEVMODECOPIES
    pd.nCopies = 1

    di.cbSize = sizeof( DOCINFO )
    di.lpszDocName = strptr( "Print BMP Test" )

    '' Get a printer device context, or return an error.
    ''
    if PrintDlg( @pd ) = 0 then
        if CommDlgExtendedError() then
            print "Print Dialog returned error"
            sleep
            deallocate( buffer )
            return
        else
            print "Print Dialog was canceled or closed"
            sleep
            deallocate( buffer )
            return
        endif
    else
        if GetDeviceCaps( pd.hDC, RASTERCAPS ) and RC_STRETCHDIB = 0 then
            print "Printer does not support StretchDIBits"
            sleep
            DeleteDC( pd.hDC )
            deallocate( buffer )
            return
        endif
    endif

    #ifdef USE_ACTUAL_SIZE

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the bitmap.
    ''
    fLogPelsX1 = lpbmi->bmiHeader->biXPelsPerMeter * .0254
    fLogPelsY1 = lpbmi->bmiHeader->biYPelsPerMeter * .0254

    #else

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the current display.
    ''
    hDesktopDC = GetDC( 0 )
    fLogPelsX1 = GetDeviceCaps( hDesktopDC, LOGPIXELSX )
    fLogPelsY1 = GetDeviceCaps( hDesktopDC, LOGPIXELSY )
    ReleaseDC( 0, hDesktopDC )

    #endif

    print fLogPelsX1, fLogPelsY1

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the selected printer.
    ''
    fLogPelsX2 = cast( single, GetDeviceCaps( pd.hDC, LOGPIXELSX ) )
    fLogPelsY2 = cast( single, GetDeviceCaps( pd.hDC, LOGPIXELSY ) )

    print fLogPelsX2, fLogPelsY2

    '' Calc the scaling factors required to maintain the original
    '' proportions when the bitmap is printed.
    ''
    if fLogPelsX1 > fLogPelsX2 then
        fScaleX = fLogPelsX1 / fLogPelsX2
    else
        fScaleX = fLogPelsX2 / fLogPelsX1
    endif
    if fLogPelsY1 > fLogPelsY2 then
        fScaleY = fLogPelsY1 / fLogPelsY2
    else
        fScaleY = fLogPelsY2 / fLogPelsY1
    endif

    print fScaleX, fScaleY

    '' Start a print job.
    ''
    if StartDoc( pd.hDC, @di ) = SP_ERROR then
        print "StartDoc returned error"
        sleep
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return
    endif

    '' Prepare the printer driver to accept data.
    ''
    if StartPage( pd.hDC ) <= 0 then
        print "StartPage returned error"
        sleep
        EndDoc( pd.hDC )
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return
    endif

    '' Use StretchDIBits to copy the bitmap to the printer device
    '' context, stretching or compressing as necessary to maintain
    '' its original proportions.
    ''
    '' declare function StretchDIBits( hdc byval as HDC,
    ''                                 destX byval as integer,
    ''                                 destY byval as integer,
    ''                                 destWidth byval as integer,
    ''                                 destHeight byval as integer,
    ''                                 srcX byval as integer,
    ''                                 srcY byval as integer,
    ''                                 srcWidth byval as integer,
    ''                                 srcHeight byval as integer,
    ''                                 lpbits byval as any ptr,
    ''                                 lpbmi byval as BITMAPINFO ptr,
    ''                                 options byval as UINT,
    ''                                 rasterop byval as DWORD )
    ''                                 as integer
    ''
    if StretchDIBits( pd.hDC, _
                      0, _
                      0, _
                      cint( lpbmi->bmiHeader.biWidth * fScaleX ), _
                      cint( lpbmi->bmiHeader.biHeight * fScaleY ), _
                      0, _
                      0, _
                      lpbmi->bmiHeader.biWidth, _
                      lpbmi->bmiHeader.biHeight, _
                      buffer + lpbmfh->bfOffBits, _
                      cast( LPBITMAPINFO, buffer + 14 ), _
                      DIB_RGB_COLORS, _
                      SRCCOPY ) = GDI_ERROR then

        print "StretchDIBits returned error"
        sleep
        EndPage( pd.hDC )
        EndDoc( pd.hDC )
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return
    endif

    '' Notify the printer driver that the page is complete.
    ''
    if EndPage( pd.hDC ) <= 0 then
        print "EndPage returned error"
        sleep
        EndDoc( pd.hDC )
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return
    endif

    '' End the print job.
    ''
    if EndDoc( pd.hDC ) <= 0 then
        print "EndDoc returned error"
        sleep
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return
    endif

    DeleteDC( pd.hDC )
    deallocate( buffer )

    return 1

end function

print PrintBMP( "image.bmp" )

sleep

'' type BITMAPFILEHEADER field=2
''    bfType as WORD
''    bfSize as DWORD
''    bfReserved1 as WORD
''    bfReserved2 as WORD
''    bfOffBits as DWORD
'' end type
''
'' type BITMAPINFO
''    bmiHeader as BITMAPINFOHEADER
''    bmiColors(0 to 1-1) as RGBQUAD
'' end type
''
'' type BITMAPINFOHEADER
''    biSize as DWORD
''    biWidth as LONG
''    biHeight as LONG
''    biPlanes as WORD
''    biBitCount as WORD
''    biCompression as DWORD
''    biSizeImage as DWORD
''    biXPelsPerMeter as LONG
''    biYPelsPerMeter as LONG
''    biClrUsed as DWORD
''    biClrImportant as DWORD
'' end type


And this is the code I used to create a test bitmap with low ink requirements.

Code: Select all

screen 12
color 0,15
cls
line (120,40)-(520,440),,B
circle (320,240),200
bsave "image.bmp",0
sleep
Last edited by MichaelW on Jun 29, 2006 19:27, edited 3 times in total.
rdc
Posts: 1713
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Postby rdc » Jun 27, 2006 22:31

Worked perfectly on my Win2K Pro machine.
test1234
Posts: 40
Joined: Sep 29, 2006 17:10

Postby test1234 » May 08, 2007 6:28

with latest CVS not work
wallyfblu
Posts: 69
Joined: May 24, 2006 10:58
Location: ITALY

Postby wallyfblu » May 08, 2007 10:47

I've used -lang deprecated and set all undefined return to 1 and it print the bitmap.

Beautiful code, thank MichaelW
test1234
Posts: 40
Joined: Sep 29, 2006 17:10

Postby test1234 » May 08, 2007 12:03

i also print
thank you @MichaelW
thank you @wallyfblu
counting_pine
Site Admin
Posts: 5826
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » May 08, 2007 12:15

This should compile without warning in the latest version of FB, and probably previous versions as well.
I think it's better to set the empty returns to 0, since as far as I can tell, it returns 1 on success and 0 on failure.

Code: Select all

#include "windows.bi"
#include "win\commdlg.bi"

'*************************************************************************

function FileLength( byref filename as string ) as integer

    dim as integer handle, length

    handle = freefile
    open filename for input as #handle
    length = lof( handle )
    close #handle
    return length

end function

function GetFile( byref filename as string, byref buffer as ubyte ptr ) as integer

    dim as integer handle, length, res

    length = FileLength( filename )
    buffer = allocate( length )
    handle = freefile
    open filename for binary as #handle
    res = get( #handle, , *buffer, length )
    close #handle
    return res

end function

function PrintBMP( byref filename as string ) as integer

    dim as LPBITMAPFILEHEADER lpbmfh
    dim as LPBITMAPINFO lpbmi
    dim as byte ptr buffer
    dim as HANDLE hDesktopDC

    dim as PRINTDLG pd
    dim as DOCINFO di

    dim as single fLogPelsX1, fLogPelsX2, fLogPelsY1, fLogPelsY2
    dim as single fScaleX, fScaleY

    '' GetFile will allocate a buffer of the required size, assign
    '' the address of the buffer to <buffer>, copy the file data to
    '' the buffer, and return whatever GET # returned, either 0 or
    '' an error code.
    ''
    if GetFile( filename, buffer ) then
        print "Error getting file"
        sleep
        deallocate( buffer )
        return 0
    endif

    '' Set up the necessary buffer pointers. A BMP file starts with
    '' a 14-byte BITMAPFILEHEADER structure, followed immediately by
    '' a BITMAPINFO (or BITMAPCOREINFO) structure.
    ''
    lpbmfh = cast( LPBITMAPFILEHEADER, buffer )
    lpbmi = cast( LPBITMAPINFO, buffer + 14 )

    '' Initialize the PRINTDLG and DOCINFO structures.
    ''
    pd.lStructSize = sizeof( PRINTDLG )
    pd.Flags = PD_RETURNDC or PD_USEDEVMODECOPIES
    pd.nCopies = 1

    di.cbSize = sizeof( DOCINFO )
    di.lpszDocName = strptr( "Print BMP Test" )

    '' Get a printer device context, or return an error.
    ''
    if PrintDlg( @pd ) = 0 then
        if CommDlgExtendedError() then
            print "Print Dialog returned error"
            sleep
            deallocate( buffer )
            return 0
        else
            print "Print Dialog was canceled or closed"
            sleep
            deallocate( buffer )
            return 0
        endif
    else
        if GetDeviceCaps( pd.hDC, RASTERCAPS ) and RC_STRETCHDIB = 0 then
            print "Printer does not support StretchDIBits"
            sleep
            DeleteDC( pd.hDC )
            deallocate( buffer )
            return 0
        endif
    endif

    #ifdef USE_ACTUAL_SIZE

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the bitmap.
    ''
    fLogPelsX1 = lpbmi->bmiHeader->biXPelsPerMeter * .0254
    fLogPelsY1 = lpbmi->bmiHeader->biYPelsPerMeter * .0254

    #else

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the current display.
    ''
    hDesktopDC = GetDC( 0 )
    fLogPelsX1 = GetDeviceCaps( hDesktopDC, LOGPIXELSX )
    fLogPelsY1 = GetDeviceCaps( hDesktopDC, LOGPIXELSY )
    ReleaseDC( 0, hDesktopDC )

    #endif

    print fLogPelsX1, fLogPelsY1

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the selected printer.
    ''
    fLogPelsX2 = cast( single, GetDeviceCaps( pd.hDC, LOGPIXELSX ) )
    fLogPelsY2 = cast( single, GetDeviceCaps( pd.hDC, LOGPIXELSY ) )

    print fLogPelsX2, fLogPelsY2

    '' Calc the scaling factors required to maintain the original
    '' proportions when the bitmap is printed.
    ''
    if fLogPelsX1 > fLogPelsX2 then
        fScaleX = fLogPelsX1 / fLogPelsX2
    else
        fScaleX = fLogPelsX2 / fLogPelsX1
    endif
    if fLogPelsY1 > fLogPelsY2 then
        fScaleY = fLogPelsY1 / fLogPelsY2
    else
        fScaleY = fLogPelsY2 / fLogPelsY1
    endif

    print fScaleX, fScaleY

    '' Start a print job.
    ''
    if StartDoc( pd.hDC, @di ) = SP_ERROR then
        print "StartDoc returned error"
        sleep
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return 0
    endif

    '' Prepare the printer driver to accept data.
    ''
    if StartPage( pd.hDC ) <= 0 then
        print "StartPage returned error"
        sleep
        EndDoc( pd.hDC )
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return 0
    endif

    '' Use StretchDIBits to copy the bitmap to the printer device
    '' context, stretching or compressing as necessary to maintain
    '' its original proportions.
    ''
    '' declare function StretchDIBits( hdc byval as HDC,
    ''                                 destX byval as integer,
    ''                                 destY byval as integer,
    ''                                 destWidth byval as integer,
    ''                                 destHeight byval as integer,
    ''                                 srcX byval as integer,
    ''                                 srcY byval as integer,
    ''                                 srcWidth byval as integer,
    ''                                 srcHeight byval as integer,
    ''                                 lpbits byval as any ptr,
    ''                                 lpbmi byval as BITMAPINFO ptr,
    ''                                 options byval as UINT,
    ''                                 rasterop byval as DWORD )
    ''                                 as integer
    ''
    if StretchDIBits( pd.hDC, _
                      0, _
                      0, _
                      cint( lpbmi->bmiHeader.biWidth * fScaleX ), _
                      cint( lpbmi->bmiHeader.biHeight * fScaleY ), _
                      0, _
                      0, _
                      lpbmi->bmiHeader.biWidth, _
                      lpbmi->bmiHeader.biHeight, _
                      buffer + lpbmfh->bfOffBits, _
                      cast( LPBITMAPINFO, buffer + 14 ), _
                      DIB_RGB_COLORS, _
                      SRCCOPY ) = GDI_ERROR then

        print "StretchDIBits returned error"
        sleep
        EndPage( pd.hDC )
        EndDoc( pd.hDC )
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return 0
    endif

    '' Notify the printer driver that the page is complete.
    ''
    if EndPage( pd.hDC ) <= 0 then
        print "EndPage returned error"
        sleep
        EndDoc( pd.hDC )
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return 0
    endif

    '' End the print job.
    ''
    if EndDoc( pd.hDC ) <= 0 then
        print "EndDoc returned error"
        sleep
        DeleteDC( pd.hDC )
        deallocate( buffer )
        return 0
    endif

    DeleteDC( pd.hDC )
    deallocate( buffer )

    return 1

end function

print PrintBMP( "r:\image.bmp" )

sleep

'' type BITMAPFILEHEADER field=2
''    bfType as WORD
''    bfSize as DWORD
''    bfReserved1 as WORD
''    bfReserved2 as WORD
''    bfOffBits as DWORD
'' end type
''
'' type BITMAPINFO
''    bmiHeader as BITMAPINFOHEADER
''    bmiColors(0 to 1-1) as RGBQUAD
'' end type
''
'' type BITMAPINFOHEADER
''    biSize as DWORD
''    biWidth as LONG
''    biHeight as LONG
''    biPlanes as WORD
''    biBitCount as WORD
''    biCompression as DWORD
''    biSizeImage as DWORD
''    biXPelsPerMeter as LONG
''    biYPelsPerMeter as LONG
''    biClrUsed as DWORD
''    biClrImportant as DWORD
'' end type
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » May 08, 2007 15:35

counting_pine wrote:I think it's better to set the empty returns to 0

I agree. Thanks for fixing my sloppy code.
ejc.cryptography
Posts: 268
Joined: Dec 16, 2006 20:52
Contact:

Postby ejc.cryptography » May 13, 2007 11:16

How can I alter this code so that the print dialog is not displayed, and that the default printer is used? Also, can this be done by having the printer name predefined in a variable?

Thanks.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » May 14, 2007 1:42

The seems to work OK, tested with CVS from March23 only.

Code: Select all

'====================================================================
#include "windows.bi"
#include "win\commdlg.bi"

'#define USE_ACTUAL_SIZE 1
'====================================================================

function FileLength( byref filename as string ) as integer

    dim as integer handle, length

    handle = freefile
    open filename for input as #handle
    length = lof( handle )
    close #handle
    return length

end function

'====================================================================

function GetFile( byref filename as string, _
                  byref buffer as byte ptr ) as integer

    dim as integer handle, length, res

    length = FileLength( filename )
    buffer = allocate( length )
    handle = freefile
    open filename for binary as #handle
    res = get( #handle, , *buffer, length )
    close #handle
    return res

end function

'====================================================================

function PrintBMP( byref filename as string ) as integer

    dim as LPBITMAPFILEHEADER lpbmfh
    dim as LPBITMAPINFO lpbmi
    dim as byte ptr buffer
    dim as HANDLE hDesktopDC

    dim as DOCINFO di

    dim as single fLogPelsX1, fLogPelsX2, fLogPelsY1, fLogPelsY2
    dim as single fScaleX, fScaleY

    '' GetFile will allocate a buffer of the required size, assign
    '' the address of the buffer to <buffer>, copy the file data to
    '' the buffer, and return whatever GET # returned, either 0 or
    '' an error code.
    ''
    if GetFile( filename, buffer ) then
        print "Error getting file"
        sleep
        deallocate( buffer )
        return 0
    endif

    '' Set up the necessary buffer pointers. A BMP file starts with
    '' a 14-byte BITMAPFILEHEADER structure, followed immediately by
    '' a BITMAPINFO (or BITMAPCOREINFO) structure.
    ''
    lpbmfh = cast( LPBITMAPFILEHEADER, buffer )
    lpbmi = cast( LPBITMAPINFO, buffer + 14 )

    '' Initialize the DOCINFO structure.
    ''
    di.cbSize = sizeof( DOCINFO )
    di.lpszDocName = strptr( "Print BMP Test" )

    '' Get a printer device context for the default printer, or
    '' return an error.

    '' Code like this can be used to get the name of the default
    '' printer for any version of Windows from 95 to XP. For Windows
    '' 2000 and up use the GetDefaultPrinter function.
    ''
    dim as zstring * 100 profileString
    if GetProfileString( "windows", _
                         "device", _
                         "default", _
                         profileString, _
                         100 ) = 99 then
      print "GetProfileString failed"
      sleep
      deallocate( buffer )
      return 0
    end if

    dim as string printerName
    printerName = mid(profileString,1,instr(profileString,",")-1)

    '' Code like this can be used to create a device context for
    '' the printer, starting with the printer name.
    ''
    dim as HDC hPrinterDC
    hPrinterDC = CreateDC( null, printerName, null, null )
    if hPrinterDC = 0 then
      print "CreateDC failed"
      sleep
      deallocate( buffer )
      return 0
    end if


    '' Ensure that the printer supports StretchDIBits.
    ''
    if GetDeviceCaps(hPrinterDC,RASTERCAPS) and RC_STRETCHDIB=0 then
      print "Printer does not support StretchDIBits"
      sleep
      DeleteDC( hPrinterDC )
      deallocate( buffer )
      return 0
    endif

    #ifdef USE_ACTUAL_SIZE

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the bitmap.
    ''
    '' The original coding of this was wrong:
    '' fLogPelsX1 = lpbmi->bmiHeader->biXPelsPerMeter * .0254
    '' fLogPelsY1 = lpbmi->bmiHeader->biYPelsPerMeter * .0254
    ''
    fLogPelsX1 = lpbmi->bmiHeader.biXPelsPerMeter * .0254
    fLogPelsY1 = lpbmi->bmiHeader.biYPelsPerMeter * .0254

    #else

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the current display.
    ''
    hDesktopDC = GetDC( 0 )
    fLogPelsX1 = GetDeviceCaps( hDesktopDC, LOGPIXELSX )
    fLogPelsY1 = GetDeviceCaps( hDesktopDC, LOGPIXELSY )
    ReleaseDC( 0, hDesktopDC )

    #endif

    print fLogPelsX1, fLogPelsY1

    '' Get the pixels-per-logical-inch in the horizontal
    '' and vertical directions for the selected printer.
    ''
    fLogPelsX2 = cast(single,GetDeviceCaps( hPrinterDC, LOGPIXELSX ))
    fLogPelsY2 = cast(single,GetDeviceCaps( hPrinterDC, LOGPIXELSY ))

    print fLogPelsX2, fLogPelsY2

    '' Calc the scaling factors required to maintain the original
    '' proportions when the bitmap is printed.
    ''
    if fLogPelsX1 > fLogPelsX2 then
        fScaleX = fLogPelsX1 / fLogPelsX2
    else
        fScaleX = fLogPelsX2 / fLogPelsX1
    endif
    if fLogPelsY1 > fLogPelsY2 then
        fScaleY = fLogPelsY1 / fLogPelsY2
    else
        fScaleY = fLogPelsY2 / fLogPelsY1
    endif

    print fScaleX, fScaleY

    '' Start a print job.
    ''
    if StartDoc( hPrinterDC, @di ) = SP_ERROR then
        print "StartDoc returned error"
        sleep
        DeleteDC( hPrinterDC )
        deallocate( buffer )
        return 0
    endif

    '' Prepare the printer driver to accept data.
    ''
    if StartPage( hPrinterDC ) <= 0 then
        print "StartPage returned error"
        sleep
        EndDoc( hPrinterDC )
        DeleteDC( hPrinterDC )
        deallocate( buffer )
        return 0
    endif

    '' Use StretchDIBits to copy the bitmap to the printer device
    '' context, stretching or compressing as necessary to maintain
    '' its original proportions.
    ''
    '' declare function StretchDIBits( hdc byval as HDC,
    ''                                 destX byval as integer,
    ''                                 destY byval as integer,
    ''                                 destWidth byval as integer,
    ''                                 destHeight byval as integer,
    ''                                 srcX byval as integer,
    ''                                 srcY byval as integer,
    ''                                 srcWidth byval as integer,
    ''                                 srcHeight byval as integer,
    ''                                 lpbits byval as any ptr,
    ''                                 lpbmi byval as BITMAPINFO ptr,
    ''                                 options byval as UINT,
    ''                                 rasterop byval as DWORD )
    ''                                 as integer
    ''
    if StretchDIBits( hPrinterDC, _
                      0, _
                      0, _
                      cint( lpbmi->bmiHeader.biWidth * fScaleX ), _
                      cint( lpbmi->bmiHeader.biHeight * fScaleY ), _
                      0, _
                      0, _
                      lpbmi->bmiHeader.biWidth, _
                      lpbmi->bmiHeader.biHeight, _
                      buffer + lpbmfh->bfOffBits, _
                      cast( LPBITMAPINFO, buffer + 14 ), _
                      DIB_RGB_COLORS, _
                      SRCCOPY ) = GDI_ERROR then

        print "StretchDIBits returned error"
        sleep
        EndPage( hPrinterDC )
        EndDoc( hPrinterDC )
        DeleteDC( hPrinterDC )
        deallocate( buffer )
        return 0
    endif

    '' Notify the printer driver that the page is complete.
    ''
    if EndPage( hPrinterDC ) <= 0 then
        print "EndPage returned error"
        sleep
        EndDoc( hPrinterDC )
        DeleteDC( hPrinterDC )
        deallocate( buffer )
        return 0
    endif

    '' End the print job.
    ''
    if EndDoc( hPrinterDC ) <= 0 then
        print "EndDoc returned error"
        sleep
        DeleteDC( hPrinterDC )
        deallocate( buffer )
        return 0
    endif

    DeleteDC( hPrinterDC )
    deallocate( buffer )

    return 1

end function

'====================================================================

print PrintBMP( "image.bmp" )

sleep

'' type BITMAPFILEHEADER field=2
''    bfType as WORD
''    bfSize as DWORD
''    bfReserved1 as WORD
''    bfReserved2 as WORD
''    bfOffBits as DWORD
'' end type
''
'' type BITMAPINFO
''    bmiHeader as BITMAPINFOHEADER
''    bmiColors(0 to 1-1) as RGBQUAD
'' end type
''
'' type BITMAPINFOHEADER
''    biSize as DWORD
''    biWidth as LONG
''    biHeight as LONG
''    biPlanes as WORD
''    biBitCount as WORD
''    biCompression as DWORD
''    biSizeImage as DWORD
''    biXPelsPerMeter as LONG
''    biYPelsPerMeter as LONG
''    biClrUsed as DWORD
''    biClrImportant as DWORD
'' end type

I don't see any way to do this with a predefined name because the name of the default printer is printer specific.

Return to “Windows”

Who is online

Users browsing this forum: No registered users and 1 guest