---------------------------------------------------------
      LBPRNT01.DLL FOR PRINTING IN LIBERTY BASIC
                   BY ALYCE WATSON
                  awatson@wctc.net
                 Alyce Watson, 2000
                 ALL RIGHTS RESERVED

LBprnt01.dll is being released as shareware.  It is not crippled
or time limited, and it contains no nags.  The released version
is the only version there is.  Registration will be on the
honor system.  For use in commercial applications, the one-time
registration fee is $15.00.  For all other uses, the registration
fee is determined by the individual user, with a suggested value
of $1.00.  This will help defray the cost of the many ink
cartridges reams of printer paper that were consumed in writing 
and testing this.  Note that anyone who has purchased the 
CDROM, Windows Programming for Everybody with Liberty BASIC
need not register the DLL, except for commercial use.  Send 
registration fee to:

Alyce Watson
3030 Buchberger Road
Wisconsin Rapids, WI 54494     USA

REQUIRES WIN 3.11 OR BETTER
---------------------------------------------------------

Thanks to these special people, who gave so unselfishly
of their time, their energy, their patience, and their
goodwill:

Carl Courtney  mailto:CarlCourt@aol.com
Eldron Gill    mailto:egill@eritter.net
Bill Jennings  mailto:bbjen@tir.com
Brian Pugh     mailto:bdpugh@hipperholme19.freeserve.co.uk
Dean Hodgson   mailto:dhodgson@nexus.edu.au

Without their help, this DLL would never have seen the
light of day.

Thank you, friends.

---------------------------------------------------------

FUNCTION LIST

PrinterDialog               PrinterInit
EndPrint                    NewPage
PrintTextLocate             PrintTextLine
PrintBlankLine              SetBottomMargin
SetTopMargin                SetLeftMargin
SetRightMargin              GetLineYPos
GetTextLineHeight           ChooseTextRGB
PointSizeFont               PrinterFont
EasyFont                    GetMaxChars
GetMaxCharsTotalWidth       GetAveCharWidth
GetMaxCharWidth             GetNumberCopies
GetDotsInchWidth            GetDotsInchHeight
GetDotsTotalWidth           GetDotsTotalHeight
PrinterNullBrush            PrinterBrush
PrinterPen                  PrintRectangle
PrintLine                   PrintRoundRectangle
PrintEllipse                PrintWindowArea
BitmapWidth                 BitmapHeight
PrintBitmap 

'------------------------------------------------------------------------
'                FUNCTIONS IN LBPRNT01.DLL
'------------------------------------------------------------------------
'NOTES
'Margins for PrintTextLine are one inch unless set by programmer.
'Default Courier New 10pt font is used unless a font is chosen by programmer.
'Text is printed in black unless changed by programmer.
'Objects are drawn with black lines unless changed by programmer.
'Objects are hollow outlines unless changed by programmer.
'Most measurements are hundredths of an inch, except where noted.
'PrintTextLine will move the cursor down for each new line and
'    eject pages and start new pages when needed.
'PrintBlankLine to move down page when using PrintTextLine.
'
'PrintTextLocate allows complete freedom to locate text on page.
'
'Must call PrinterDialog or PrinterInit to start and EndPrint to end job.
'All other calls are optional.  Any combination of text and graphics is okay.

'------------------------------------------------------------------------
'------------------------------------------------------------------------
'INITIALIZE AND CLOSE:

'INITIALIZE WITH EITHER PRINTER DIALOG OR PRINTER INIT -- NOT BOTH!

    CallDll #lb, "PrinterDialog",_  'must call this to start a document
        h as short,_                'handle of program window
        pDC as short                'nozero if successful = printer DC

    CallDll #lb, "PrinterInit",_    'init with no print dialog
        h as short,_                'window handle
        pDC as short                'nonzero if successful = printer DC


    CallDll #lb, "GetNumberCopies",_ 'only works with PrinterDialog call
        h as short,_            'window handle
        numbercopies as short   'number of copies chosen by user

    CallDll #lb, "EndPrint",_   'ends document, ejects final page
        h as short,_            'window handle
        r as short              'nonzero if successful



'SET TEXT COLOR
    struct col,_                'holds info for text color
        red as short,_          'red value = 0-255
        green as short,_        'green value = 0-255
        blue as short           'blue value = 0-255

        col.red.struct = 255       '0-255
        col.green.struct = 0       '0-255
        col.blue.struct = 0        '0-255

    CallDll #lb, "ChooseTextRGB",_
        h as short,_             'handle of window
        col as struct,_          'struct of color info
        r as long                'nonzero if successful



'CREATE FONTS
    pfontname$="Courier New" + chr$(0)  'must be null terminated -
                                        'no underscores between words
    height=30                           'in hundredths of inch
    bold=0                              'do not make it bold
    italic=1                            'make it italic
    underline=1                         'make it underlined
    strikeout=0                         'do not make it strikeout

    CallDll #lb, "PrinterFont",_        'create a font with many attributes
        h as short,_                    'window handle
        height as short,_               'height in hundredths of inch
        bold as short,_                 '0=normal  1=bold
        italic as short,_               '0=normal  1=italic
        underline as short,_            '0=normal  1=underline
        strikeout as short,_            '0=normal  1=strikeout
        pfontname$ as ptr,_             'null terminated, no LB underscores
        hfont as short                  'returns handle of font

    CallDll #lb, "PointSizeFont",_      'create a font with many attributes
        h as short,_                    'window handle
        height as short,_               'height in points - 72 pts per inch
        bold as short,_                 '0=normal  1=bold
        italic as short,_               '0=normal  1=italic
        underline as short,_            '0=normal  1=underline
        strikeout as short,_            '0=normal  1=strikeout
        pfontname$ as ptr,_             'null terminated, no LB underscores
        hfont as short                  'returns handle of font

    CallDll #lb, "EasyFont",_           'easy create font
        h as short,_                    'window handle
        height as short,_               'height in hundedths of inch
        pfontname$ as ptr,_             'null terminated, no LB underscores
        hfont as short                  'returns handle of font


'PRINTER SETUP
        top=100     'top margin in hundredths of inch
    CallDll #lb, "SetTopMargin",_
        h as short,_    'window handle
        top as short,_  'top margin in hundredths of inch
        r as short      'nonzero if successful

        right=80    'right margin in hundredths of inch
    CallDll #lb, "SetRightMargin",_ 'OPTIONAL
        h as short,_         'window handle
        right as short,_     'right margin in hundredths of inch
        r as short           'nonzero if successful

        bottom=100  'bottom margin in hundredths of inch
    CallDll #lb, "SetBottomMargin",_
        h as short,_          'window handle
        bottom as short,_     'bottom margin in hundredths of inch
        r as short            'nonzero if successful

        left=150    'left margin in hundredths of inch
    CallDll #lb, "SetLeftMargin",_
        h as short,_     'window handle
        left as short,_  'left margin in hundredths of inch
        r as short       'nonzero if successful


    CallDll #lb, "GetMaxCharWidth",_    'maximum width of char in current font
        h as short,_                    'window handle
        maxwidth as short               'max char width in printer dots


    CallDll #lb, "GetAveCharWidth",_    'average width of char in current font
        h as short,_                    'window handle
        avewidth as short               'ave char width in printer dots


'PRINTING TEXT

    text$="Some words."+chr$(0)
    length=len(text$)-1
    xloc=100:yloc=200
    CallDll #lb, "PrintTextLocate",_    'print one line of text
        h as short,_                    'window handle
        text$ as ptr,_                  'text string to print
        xloc as short,_                 'x location in hundredths of inch
        yloc as short,_                 'y location in hundredths of inch
        length as short,_               'length of text string
        r as short                      'nonzero if successful

    CallDll #lb, "GetMaxCharsTotalWidth",_ 'total characters from edge to edge
        h as short,_                       'window handle
        totalmax as short                  'total number of chars that will fit,
                                           'if text starts at left edge

    text$="Some words."+chr$(0)
    length=len(text$)-1
    CallDll #lb, "PrintTextLine",_  'prints line, moves down automatically each line
        h as short,_                'window handle
        text$ as ptr,_              'text string to print
        length as short,_           'length of text string
        r as short                  'nonzero if successful

    CallDll #lb, "GetMaxChars",_    'max for PrintTextLine, current margins
        h as short,_                'window handle
        maxchar as short            'total number of characters that will fit
                                    'in a line within current page margins


    CallDll #lb, "GetLineYPos",_    'cursor position for PrintTextLine
        h as short,_                'window handle
        linepos as short            'position of y cursor in hundredths


    CallDll #lb, "GetTextLineHeight",_  'height for lines in current font
        h as short,_                    'window handle
        lineheight as short             'height in hundredths of text line


    CallDll #lb, "PrintBlankLine",_ 'move cursor down page the height of one line
        h as short,_                'window handle
        r as void                   'no return


    CallDll #lb, "NewPage",_    'ejects page, starts new one
        h as short,_            'window handle
        r as short              'nonzero if sucessful



'GRAPHICS COLOR

    '0 = _PS_SOLID       PS = PEN STYLE
    '1 = _PS_DASH
    '2 = _PS_DOT;
    '3 = _PS_DASHDOT
    '4 = _PS_DASHDOTDOT
    '> 4 THEN default is _PS_SOLID

'NOTE if style > 0 then size reverts to 1 pixel
    CallDll #lb, "PrinterPen",_ 'shapes outlined with pen
        h as short,_        'window handle
        size as short,_     'size in dots
        style as short,_    'pen style
        pred as short,_     'red value 0-255
        pgreen as short,_   'green 0-255
        pblue as short,_    'blue 0-255
        hPen as short       'returns handle of pen

    '0 = _HS_HORIZONTAL    HS = HATCH STYLE
    '1 = _HS_VERTICAL
    '2 = _HS_FDIAGONAL
    '3 = _HS_BDIAGONAL
    '4 = _HS_CROSS
    '5 = _HS_DIAGCROSS
    '6 will give a solid fill = no pattern

    CallDll #lb, "PrinterBrush",_ 'fills graphics entities
        h as short,_        'window handle
        style as short,_    '6=solid, 0-5 are hatch styles
        pred as short,_     'red value 0-255
        pgreen as short,_   'green 0-255
        pblue as short,_    'blue 0-255
        hBrush as short     'returns handle of brush

    CallDll #lb, "PrinterNullBrush",_  'allows you to return to default hollow figure
        h as short,_    'window handle
        hBrush as short 'returns handle of brush



'GRAPHICS ENTITIES

    CallDll #lb, "PrintLine",_
        h as short,_        'window handle
        x1 as short,_       'x origin in hundredths of inch
        y1 as short,_       'y origin in hundredths of inch
        x2 as short,_       'x end    in hundredths of inch
        y2 as short,_       'y end    in hundredths of inch
        r as short          'nonzero if successful

    CallDll #lb, "PrintRectangle",_ 'measure in hundredths of inch
        h as short,_        'window handle
        x1 as short,_       'x origin corner
        y1 as short,_       'y origin corner
        x2 as short,_       'x end opposite corner
        y2 as short,_       'y end oppposite corner
        r as short          'nonzero if successful

    CallDll #lb, "PrintRoundRectangle",_  'measure in hundredths of inch
        h as short,_        'window handle
        x1 as short,_       'x origin corner
        y1 as short,_       'y origin corner
        x2 as short,_       'x end opposite corner
        y2 as short,_       'y end oppposite corner
        x3 as short,_       'corner ellipse width
        y3 as short,_       'corner ellipse height
        r as short          'nonzero if successful

    CallDll #lb, "PrintEllipse",_  'measure in hundredths of inch
        h as short,_        'window handle
        x1 as short,_       'x origin corner - bounding rectangle
        y1 as short,_       'y origin corner - bounding rectangle
        x2 as short,_       'x end opposite corner - bounding rectangle
        y2 as short,_       'y end oppposite corner - bounding rectangle
        r as short          'nonzero if successful


'GRAPHICS IMAGES

    CallDll #lb, "PrintWindowArea",_'MAY PRINT IN GRAYSCALE
        h as short,_        'window handle
        xorg as short,_     'starting x pixel for print
        yorg as short,_     'starting y pixel for print
        width as short,_    'pixel width from screen
        height as short,_   'pixel height from screen
        pxorg as short,_    'x loc on page in hundredths of inch
        pyorg as short,_    'y loc on page in hundredths of inch
        pwidth as short,_   'width of image on page in hundredths of inch
        pheight as short,_  'height of image on page in hundredths of inch
        r as short          'nonzero if successful

    CallDll #lb, "BitmapWidth",_
        h as short,_        'window handle
        hbitmap as short,_  'bitmap handle
        bmpwidth as short   'bitmap width

    CallDll #lb, "BitmapHeight",_
        h as short,_        'window handle
        hbitmap as short,_  'bitmap handle
        bmpheight as short  'bitmap height

    CallDll #lb, "PrintBitmap",_
        h as short,_        'window handle
        hbitmap as short,_  'bitmap handle
        x1 as short,_       'org x on page in hundredths
        y1 as short,_       'org y on page in hundredths
        pwidth as short,_   'hundredths of inch wide to print
        pheight as short,_  'hundredths of inch high to print
        r as short          'nonzero if successful



'PRINTER INFORMATION

    CallDll #lb, "GetDotsInchWidth",_
        h as short,_    'window handle
        dpix as short   'dots per inch in width

    CallDll #lb, "GetDotsInchHeight",_
        h as short,_    'window handle
        dpiy as short   'dots per inch in height

    CallDll #lb, "GetDotsTotalWidth",_
        h as short,_       'window handle
        dotswide as short  'total dots in width

    CallDll #lb, "GetDotsTotalHeight",_
        h as short,_       'window handle
        dotshigh as short  'total dots in height

    
    InchesWide = dotswide/dpix
    InchesHigh = dotshigh/dpiy

