by Richard Russell, February 2014

(see also High quality hardcopy output (LBB))

LB Booster uses a conventional double-buffered method of outputting graphics: objects, images, text etc. are drawn to a 'memory' bitmap which is then blitted to the screen when required. This has the advantage that graphics automatically 'stick', that is they are redrawn when a window is restored or uncovered, without any extra effort by the programmer.

In LBB there is no need to use flush, discard, segment, delsegment etc. to manage graphics segments (although those commands will do no harm if you leave them in the program for compatibility with LB). You cannot run out of memory, or cause your program to slow down, if you are outputting animated graphics and don't follow the rules correctly.

There is however one disadvantage of using this conventional scheme: when you dump a graphics window to the printer ("print" command) the resulting quality on the paper will be no better than it was on the screen. Commonly this will not be noticeable, especially if your screen has a relatively high resolution and your printer driver does its job well. But occasionally the reduction of quality may be apparent, especially on small sized text.

If this is an issue there is a relatively straightforward solution. Below is listed a modified version of the printform.bas program supplied with Liberty BASIC. Instead of using the native "print" command it creates a metafile, which it then outputs to the printer. The program behaves exactly like the original, but the quality of the printed output from LBB will be identical to what it would be from Liberty BASIC itself.

This technique has another advantage, in that there is no need to output the graphics to the screen at all if you don't want to. If you delete the section labelled Display the metafile (optional) the graphics will be sent only to the printer:

    'printform.bas
    'This example program shows how to use a graphics window to produce
    'printable form without using PCL or graphics characters.  Different
    'fonts and colors are used.
 
    nomainwin
    WindowWidth = 800
    WindowHeight = DisplayHeight
    open "Printable Form" for graphics as #form
    #form "trapclose [quit]"
 
    ' Create the metafile:
    hw = hwnd(#form)
    calldll #user32, "GetDC", hw as ulong, DC as ulong
    calldll #gdi32, "GetDeviceCaps", DC as ulong, _HORZSIZE as long, mm as long
    calldll #gdi32, "GetDeviceCaps", DC as ulong, _HORZRES as long, pel as long
    calldll #user32, "ReleaseDC", hw as ulong, DC as ulong, r as long
    struct rect, left as long, top as long, right as long, bottom as long
    rect.right.struct = WindowWidth * 100 * mm / pel
    rect.bottom.struct = WindowHeight * 100 * mm / pel
    calldll #gdi32, "CreateEnhMetaFileA", 0 as long, 0 as long, _
      rect as struct, 0 as long, hDC as ulong
    calldll #user32, "SetWindowLongA", hw as ulong, _GWL_USERDATA as long, _
      hDC as ulong, oldDC as ulong
 
    #form "down"
    #form "backcolor 220 220 220"
    #form "size 2"
    #form "place 1 1 ; boxfilled 700 110"
    #form "font arial 16 bold"
 
    #form "place 20 34"
    #form "\Software Mail-in Order Form"
    #form "font arial 10"
    #form "\Mega2 Super Corporation\PO Box 1029391\Industrialtown, PA 11701\"
 
    #form "backcolor white"
    #form "place 1 110"
    #form "boxfilled 700 471"
 
    #form "place 1 471"
    #form "boxfilled 700 970"
 
    #form "font courier_new 10"
    #form "size 1"
    for a = 1 to 9
        y = 111+a*30
        #form "place 250 "; y
        #form "box 650 "; y + 22
        read label$
        #form "place 50 "; y + 13
        #form "\"; label$
    next a
 
    #form "place 150 431"
    #form "font courier_new 10 italic"
    #form "\Make sure to provide your email address so we can send"
    #form "\your registration code promptly!"
 
    #form "place 50 501"
    #form "\ 1) Widget Tools SILVER license:"
    #form "\    "
    #form "\                $29.95 x ____ copies          = $______________.___"
    #form "\"
    #form "\ 2) Widget Tools GOLD license:"
    #form "\"
    #form "\                $49.95 x ____ copies          = $______________.___"
    #form "\"
    #form "\ 3) Upgrade to SILVER license.  You will receive a special"
    #form "\    registration code which works with your v1.x or v2.x or 3.x"
    #form "\    license code to upgrade to v4.0 SILVER!"
    #form "\"
    #form "\                $14.95 x ____ copies          = $______________.___"
    #form "\"
    #form "\ 4) Upgrade to GOLD license.  You will receive a special"
    #form "\    registration code which works with your v1.x or v2.x or v3.0x"
    #form "\    license code to upgrade to v4.0 GOLD!"
    #form "\"
    #form "\                $19.95 x ____ copies          = $______________.___"
    #form "\"
    #form "\    Circle YES below if you want us to mail you an optional CDROM."
    #form "\    Your registration code will be printed clearly on the disk."
    #form "\"
    #form "\    YES  Send me the optional CDROM!          = $            10.00"
    #form "\"
    #form "\"
    #form "\                                Total         = $______________.___"
 
    ' Close the metafile:
    calldll #user32, "SetWindowLongA", hw as ulong, _GWL_USERDATA as long, _
      oldDC as ulong, hDC as ulong
    calldll #gdi32, "CloseEnhMetaFile", hDC as ulong, hEMF as ulong
 
    ' Display the metafile (optional):
    rect.right.struct = WindowWidth
    rect.bottom.struct = WindowHeight
    calldll #gdi32, "PlayEnhMetaFile", oldDC as ulong, _
      hEMF as ulong, rect as struct, r as long
    calldll #user32, "InvalidateRect", hw as ulong, _
      0 as long, 0 as long, r as long
 
    confirm "Send to printer?"; answer
    if answer then
      printerdialog 
      if PrinterName$ <> "" then
        ' Print the metafile:
        !printerDC = @prthdc%
        calldll #gdi32, "GetDeviceCaps", printerDC as ulong, _
          _HORZRES as long, printWidth as long
        rect.right.struct = printWidth
        rect.bottom.struct = printWidth * WindowHeight / WindowWidth
        lprint " "
        calldll #gdi32, "PlayEnhMetaFile", printerDC as ulong, _
          hEMF as ulong, rect as struct, r as long
        dump
      end if
    end if
 
    ' Delete the metafile:
    calldll #gdi32, "DeleteEnhMetaFile", hEMF as ulong, r as long
    wait
 
    data "Name:", "Address 1:", "Address 2:", "City:", "State:", "Zip Code:"
    data "Email Address:", "Special Instructions:", "Comments:"
 
[quit]
    close #form
    end