' Printer.BAS was programmed by John White (danilo_yoingco@yahoo.co.uk).

$OPTIMIZE ON
$APPTYPE GUI
$TYPECHECK ON
$ESCAPECHARS ON

' Printer.BAS`s own CONST Values.
Const DATA_TO_PRINTER=0
Const DATA_TO_OUTPUT=1
Const DDM_COPYTO_PI2DM=0
Const PI2DM_COPYTO_DDM=1
Const ENUMERATE_PRINTERS=0
Const ENUMERATE_DEFAULT_PRINTER=1
Const SET_DDM=0
Const SET_PI2DM=1
Const SET_BOTH_DM=2

CONST fmCreate = 65535
CONST fmOpenRead = 0
CONST fmOpenWrite = 1
CONST fmOpenReadWrite = 2

Const ERROR_INSUFFICIENT_BUFFER = 122
Const PRINTER_ENUM_LOCAL = &H2
Const DM_UPDATE = 1
Const DM_COPY = 2
Const DM_PROMPT = 4
Const DM_MODIFY = 8
Const IDOK = 1
Const IDCANCEL = 2
Const IDABORT = 3
Const IDRETRY = 4
Const IDIGNORE = 5
Const IDYES = 6
Const IDNO = 7
Const GMEM_FIXED = &H0
Const GMEM_MOVEABLE = &H2
Const GMEM_ZEROINIT = &H40
Const GMEM_INVALID_HANDLE = &H8000
Const PS_SOLID = 0
Const GDI_ERROR = &HFFFF
Const PRINTER_ACCESS_ADMINISTER = &H4
Const PRINTER_ACCESS_USE = &H8
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const STANDARD_RIGHTS_ALL = &H1F0000
Const DC_FIELDS = 1
Const DC_PAPERS = 2
Const DC_PAPERSIZE = 3
Const DC_MINEXTENT = 4
Const DC_MAXEXTENT = 5
Const DC_BINS = 6
Const DC_DUPLEX = 7
Const DC_SIZE = 8
Const DC_EXTRA = 9
Const DC_VERSION = 10
Const DC_DRIVER = 11
Const DC_BINNAMES = 12
Const DC_ENUMRESOLUTIONS = 13
Const DC_FILEDEPENDENCIES = 14
Const DC_TRUETYPE = 15
Const DC_PAPERNAMES = 16
Const DC_ORIENTATION = 17
Const DC_COPIES = 18
Const DC_BINADJUST = 19
Const DC_EMF_COMPLIANT = 20
Const DC_DATATYPE_PRODUCED = 21
Const DC_COLLATE = 22
Const DCTT_BITMAP = 1            '  print TT fonts as graphics
Const DCTT_DOWNLOAD = 2          '  download TT fonts as soft fonts
Const DCTT_SUBDEV = 3            '  substitute device fonts for TT fonts
Const DI_APPBANDING = &H1
Const DI_ROPS_READ_DESTINATION = &H2
Const PHYSICALWIDTH = 110 '  Physical Width in device units
Const PHYSICALHEIGHT = 111 '  Physical Height in device units
Const PHYSICALOFFSETX = 112 '  Physical Printable Area x margin
Const PHYSICALOFFSETY = 113 '  Physical Printable Area y margin
Const SCALINGFACTORX = 114 '  Scaling factor x
Const SCALINGFACTORY = 115 '  Scaling factor y
Const CURVECAPS = 28         '  Curve capabilities
Const LINECAPS = 30          '  Line capabilities
Const POLYGONALCAPS = 32     '  Polygonal capabilities
Const TEXTCAPS = 34          '  Text capabilities
Const CLIPCAPS = 36          '  Clipping capabilities
Const RASTERCAPS = 38        '  Bitblt capabilities
Const PRINTER_ATTRIBUTE_QUEUED = &H1
Const PRINTER_ATTRIBUTE_DIRECT = &H2
Const PRINTER_ATTRIBUTE_DEFAULT = &H4
Const PRINTER_ATTRIBUTE_SHARED = &H8
Const PRINTER_ATTRIBUTE_NETWORK = &H10
Const PRINTER_ATTRIBUTE_HIDDEN = &H20
Const PRINTER_ATTRIBUTE_LOCAL = &H40
Const JOB_STATUS_PAUSED = &H1
Const JOB_STATUS_ERROR = &H2
Const JOB_STATUS_DELETING = &H4
Const JOB_STATUS_SPOOLING = &H8
Const JOB_STATUS_PRINTING = &H10
Const JOB_STATUS_OFFLINE = &H20
Const JOB_STATUS_PAPEROUT = &H40
Const JOB_STATUS_PRINTED = &H80
Const NO_PRIORITY = 0
Const MAX_PRIORITY = 99
Const MIN_PRIORITY = 1
Const DEF_PRIORITY = 1
Const JOB_CONTROL_PAUSE = 1
Const JOB_CONTROL_RESUME = 2
Const JOB_CONTROL_CANCEL = 3
Const JOB_CONTROL_RESTART = 4
Const JOB_POSITION_UNSPECIFIED = 0
Const PT_CLOSEFIGURE = &H1
Const PT_LINETO = &H2
Const PT_BEZIERTO = &H4
Const PT_MOVETO = &H6
Const BS_SOLID = 0
Const BS_NULL = 1
Const BS_HOLLOW = BS_NULL
Const BS_HATCHED = 2
Const BS_PATTERN = 3
Const BS_INDEXED = 4
Const BS_DIBPATTERN = 5
Const BS_DIBPATTERNPT = 6
Const BS_PATTERN8X8 = 7
Const BS_DIBPATTERN8X8 = 8
Const HS_HORIZONTAL = 0              '  -----
Const HS_VERTICAL = 1                '  |||||
Const HS_FDIAGONAL = 2               '  \\\\\
Const HS_BDIAGONAL = 3               '  /////
Const HS_CROSS = 4                   '  +++++
Const WHITE_BRUSH = 0
Const BLACK_BRUSH = 4
Const WHITE_PEN = 6
Const BLACK_PEN = 7
Const NULL_PEN = 8
Const OEM_FIXED_FONT = 10
Const ANSI_FIXED_FONT = 11
Const ANSI_VAR_FONT = 12
Const SYSTEM_FONT = 13
Const DEVICE_DEFAULT_FONT = 14
Const DEFAULT_PALETTE = 15
Const SYSTEM_FIXED_FONT = 16
Const CLR_INVALID = &HFFFF
Const TRANSPARENT = 1
Const OPAQUE = 2
Const DT_TOP = &H0
Const DT_LEFT = &H0
Const DT_CENTER = &H1
Const DT_RIGHT = &H2
Const DT_VCENTER = &H4
Const DT_BOTTOM = &H8
Const DT_WORDBREAK = &H10
Const DT_SINGLELINE = &H20
Const DT_EXPANDTABS = &H40
Const DT_TABSTOP = &H80
Const DT_NOCLIP = &H100
Const DT_EXTERNALLEADING = &H200
Const DT_CALCRECT = &H400
Const DT_NOPREFIX = &H800
Const DT_INTERNAL = &H1000
Const FW_DONTCARE = 0
Const FW_THIN = 100
Const FW_EXTRALIGHT = 200
Const FW_LIGHT = 300
Const FW_NORMAL = 400
Const FW_MEDIUM = 500
Const FW_SEMIBOLD = 600
Const FW_BOLD = 700
Const FW_EXTRABOLD = 800
Const FW_HEAVY = 900
Const ITALIC_OFF = 0
Const ITALIC_ON = 1
Const UNDERLINE_OFF = 0
Const UNDERLINE_ON = 1
Const STRIKEOUT_OFF = 0
Const STRIKEOUT_ON = 1
Const OUT_DEFAULT_PRECIS = 0
Const OUT_STRING_PRECIS = 1
Const OUT_CHARACTER_PRECIS = 2
Const OUT_STROKE_PRECIS = 3
Const OUT_TT_PRECIS = 4
Const OUT_DEVICE_PRECIS = 5
Const OUT_RASTER_PRECIS = 6
Const OUT_TT_ONLY_PRECIS = 7
Const OUT_OUTLINE_PRECIS = 8
Const CLIP_DEFAULT_PRECIS = 0
Const CLIP_CHARACTER_PRECIS = 1
Const CLIP_STROKE_PRECIS = 2
Const CLIP_MASK = &HF
Const CLIP_LH_ANGLES = 16
Const CLIP_TT_ALWAYS = 32
Const CLIP_EMBEDDED = 128
Const DEFAULT_QUALITY = 0
Const DRAFT_QUALITY = 1
Const PROOF_QUALITY = 2
Const DEFAULT_PITCH = 0
Const FIXED_PITCH = 1
Const VARIABLE_PITCH = 2
Const ANSI_CHARSET = 0
Const DEFAULT_CHARSET = 1
Const SYMBOL_CHARSET = 2
Const SHIFTJIS_CHARSET = 128
Const HANGEUL_CHARSET = 129
Const CHINESEBIG5_CHARSET = 136
Const OEM_CHARSET = 255
Const FF_DONTCARE = 0
Const FF_ROMAN = 16
Const FF_SWISS = 32
Const FF_MODERN = 48
Const FF_SCRIPT = 64
Const FF_DECORATIVE = 80
Const LOGPIXELSX = 88        '  Logical pixels/inch in X
Const LOGPIXELSY = 90        '  Logical pixels/inch in Y
Const MM_TEXT = 1
Const MM_LOMETRIC = 2
Const MM_HIMETRIC = 3
Const MM_LOENGLISH = 4
Const MM_HIENGLISH = 5
Const MM_TWIPS = 6
Const MM_ISOTROPIC = 7
Const MM_ANISOTROPIC = 8
Const GM_COMPATIBLE = 1
Const GM_ADVANCED = 2
Const TA_NOUPDATECP = 0
Const TA_UPDATECP = 1
Const TA_LEFT = 0
Const TA_RIGHT = 2
Const TA_CENTER = 6
Const TA_TOP = 0
Const TA_BOTTOM = 8
Const TA_BASELINE = 24
Const TA_MASK = (TA_BASELINE + TA_CENTER + TA_UPDATECP)
Const VTA_BASELINE = TA_BASELINE
Const VTA_LEFT = TA_BOTTOM
Const VTA_RIGHT = TA_TOP
Const VTA_CENTER = TA_CENTER
Const VTA_BOTTOM = TA_RIGHT
Const VTA_TOP = TA_LEFT
Const DM_ORIENTATION = &H1&
Const DM_PAPERSIZE = &H2&
Const DM_PAPERLENGTH = &H4&
Const DM_PAPERWIDTH = &H8&
Const DM_SCALE = &H10&
Const DM_COPIES = &H100&
Const DM_DEFAULTSOURCE = &H200&
Const DM_PRINTQUALITY = &H400&
Const DM_COLOR = &H800&
Const DM_DUPLEX = &H1000&
Const DM_YRESOLUTION = &H2000&
Const DM_TTOPTION = &H4000&
Const DM_COLLATE As Long = &H8000
Const DM_FORMNAME As Long = &H10000
Const DMORIENT_PORTRAIT = 1
Const DMORIENT_LANDSCAPE = 2
Const HWND_BROADCAST = &HFFFF
Const SMTO_NORMAL = &H0
Const WM_DEVMODECHANGE = &H1B
Const WM_SETTINGCHANGE = 26
Const PSD_MINMARGINS = &H1 '  use caller's
Const PSD_MARGINS = &H2 '  use caller's
Const PSD_INTHOUSANDTHSOFINCHES = &H4 '  2nd of 4 possible
Const PSD_INHUNDREDTHSOFMILLIMETERS = &H8 '  3rd of 4 possible
Const PSD_DISABLEMARGINS = &H10
Const PSD_DISABLEPRINTER = &H20
Const PSD_NOWARNING = &H80 '  must be same as PD_*
Const PSD_DISABLEORIENTATION = &H100
Const PSD_RETURNDEFAULT = &H400 '  must be same as PD_*
Const PSD_DISABLEPAPER = &H200
Const PSD_SHOWHELP = &H800 '  must be same as PD_*
Const PSD_ENABLEPAGESETUPHOOK = &H2000 '  must be same as PD_*
Const PSD_ENABLEPAGESETUPTEMPLATE = &H8000 '  must be same as PD_*
Const PSD_ENABLEPAGESETUPTEMPLATEHANDLE = &H20000 '  must be same as PD_*
Const PSD_ENABLEPAGEPAINTHOOK = &H40000
Const PSD_DISABLEPAGEPAINTING = &H80000
Const DN_DEFAULTPRN = &H1
Const PD_ALLPAGES = &H0
Const PD_SELECTION = &H1
Const PD_PAGENUMS = &H2
Const PD_NOSELECTION = &H4
Const PD_NOPAGENUMS = &H8
Const PD_COLLATE = &H10
Const PD_PRINTTOFILE = &H20
Const PD_PRINTSETUP = &H40
Const PD_NOWARNING = &H80
Const PD_RETURNDC = &H100
Const PD_RETURNIC = &H200
Const PD_RETURNDEFAULT = &H400
Const PD_SHOWHELP = &H800
Const PD_ENABLEPRINTHOOK = &H1000
Const PD_ENABLESETUPHOOK = &H2000
Const PD_ENABLEPRINTTEMPLATE = &H4000
Const PD_ENABLESETUPTEMPLATE = &H8000
Const PD_ENABLEPRINTTEMPLATEHANDLE = &H10000
Const PD_ENABLESETUPTEMPLATEHANDLE = &H20000
Const PD_USEDEVMODECOPIES = &H40000
Const PD_USEDEVMODECOPIESANDCOLLATE = &H40000
Const PD_DISABLEPRINTTOFILE = &H80000
Const PD_HIDEPRINTTOFILE = &H100000
Const PD_NONETWORKBUTTON = &H200000
Const RC_NONE = 0
Const RC_BITBLT = 1                  '  Can do standard BLT.
Const RC_BANDING = 2                 '  Device requires banding support
Const RC_SCALING = 4                 '  Device requires scaling support
Const RC_BITMAP64 = 8                '  Device can support >64K bitmap
Const RC_GDI20_OUTPUT = &H10             '  has 2.0 output calls
Const RC_GDI20_STATE = &H20
Const RC_SAVEBITMAP = &H40
Const RC_DI_BITMAP = &H80                '  supports DIB to memory
Const RC_PALETTE = &H100                 '  supports a palette
Const RC_DIBTODEV = &H200                '  supports DIBitsToDevice
Const RC_BIGFONT = &H400                 '  supports >64K fonts
Const RC_STRETCHBLT = &H800              '  supports StretchBlt
Const RC_FLOODFILL = &H1000              '  supports FloodFill
Const RC_STRETCHDIB = &H2000             '  supports StretchDIBits
Const RC_OP_DX_OUTPUT = &H4000
Const RC_DEVBITS = &H8000
Const SRCCOPY = &HCC0020         ' (DWORD) dest = source
Const SRCPAINT = &HEE0086        ' (DWORD) dest = source OR dest
Const SRCAND = &H8800C6          ' (DWORD) dest = source AND dest
Const SRCINVERT = &H660046       ' (DWORD) dest = source XOR dest
Const SRCERASE = &H440328        ' (DWORD) dest = source AND (NOT dest )
Const NOTSRCCOPY = &H330008      ' (DWORD) dest = (NOT source)
Const NOTSRCERASE = &H1100A6     ' (DWORD) dest = (NOT src) AND (NOT dest)
Const MERGECOPY = &HC000CA       ' (DWORD) dest = (source AND pattern)
Const MERGEPAINT = &HBB0226      ' (DWORD) dest = (NOT source) OR dest
Const PATCOPY = &HF00021         ' (DWORD) dest = pattern
Const PATPAINT = &HFB0A09        ' (DWORD) dest = DPSnoo
Const PATINVERT = &H5A0049       ' (DWORD) dest = pattern XOR dest
Const DSTINVERT = &H550009       ' (DWORD) dest = (NOT dest)
Const BLACKNESS = &H42           ' (DWORD) dest = BLACK
Const WHITENESS = &HFF0062       ' (DWORD) dest = WHITE
Const HGDI_ERROR = &HFFFF
Const BLACKONWHITE = 1
Const WHITEONBLACK = 2
Const COLORONCOLOR = 3
Const HALFTONE = 4
Const MAXSTRETCHBLTMODE = 4
Const BDR_RAISEDOUTER = &H1
Const BDR_SUNKENOUTER = &H2
Const BDR_RAISEDINNER = &H4
Const BDR_SUNKENINNER = &H8
Const BDR_OUTER = &H3
Const BDR_INNER = &HC
Const BDR_RAISED = &H5
Const BDR_SUNKEN = &HA
Const EDGE_RAISED = (BDR_RAISEDOUTER Or BDR_RAISEDINNER)
Const EDGE_SUNKEN = (BDR_SUNKENOUTER Or BDR_SUNKENINNER)
Const EDGE_ETCHED = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
Const EDGE_BUMP = (BDR_RAISEDOUTER Or BDR_SUNKENINNER)
Const BF_LEFT = &H1
Const BF_TOP = &H2
Const BF_RIGHT = &H4
Const BF_BOTTOM = &H8
Const BF_TOPLEFT = (BF_TOP Or BF_LEFT)
Const BF_TOPRIGHT = (BF_TOP Or BF_RIGHT)
Const BF_BOTTOMLEFT = (BF_BOTTOM Or BF_LEFT)
Const BF_BOTTOMRIGHT = (BF_BOTTOM Or BF_RIGHT)
Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
Const BF_DIAGONAL = &H10
Const BF_DIAGONAL_ENDTOPRIGHT = (BF_DIAGONAL Or BF_TOP Or BF_RIGHT)
Const BF_DIAGONAL_ENDTOPLEFT = (BF_DIAGONAL Or BF_TOP Or BF_LEFT)
Const BF_DIAGONAL_ENDBOTTOMLEFT = (BF_DIAGONAL Or BF_BOTTOM Or BF_LEFT)
Const BF_DIAGONAL_ENDBOTTOMRIGHT = (BF_DIAGONAL Or BF_BOTTOM Or BF_RIGHT)
Const BF_MIDDLE = &H800    ' Fill in the middle.
Const BF_SOFT = &H1000     ' Use for softer buttons.
Const BF_ADJUST = &H2000   ' Calculate the space left over.
Const BF_FLAT = &H4000     ' For flat rather than 3-D borders.
Const BF_MONO = &H8000     ' For monochrome borders.
Const PORT_TYPE_WRITE=1
Const PORT_TYPE_READ=2
Const PORT_TYPE_REDIRECTED=4
Const PORT_TYPE_NET_ATTACHED=8
Const DCBA_FACEUPNONE = &H0
Const DCBA_FACEUPCENTER = &H1
Const DCBA_FACEUPLEFT = &H2
Const DCBA_FACEUPRIGHT = &H3
Const DCBA_FACEDOWNNONE = &H100
Const DCBA_FACEDOWNCENTER = &H101
Const DCBA_FACEDOWNLEFT = &H102
Const DCBA_FACEDOWNRIGHT = &H103
Const DMDITHER_NONE = 1          '  No dithering
Const DMDITHER_COARSE = 2        '  Dither with a coarse brush
Const DMDITHER_FINE = 3          '  Dither with a fine brush
Const DMDITHER_LINEART = 4       '  LineArt dithering
Const DMDITHER_GRAYSCALE = 5     '  Device does grayscaling
Const DMDITHER_USER = 256        '  Device-specific dithers start here
Const DMCOLOR_MONOCHROME = 1
Const DMCOLOR_COLOR = 2
Const DMDUP_SIMPLEX = 1
Const DMDUP_VERTICAL = 2
Const DMDUP_HORIZONTAL = 3
Const DMPAPER_LETTER = 1                        '  Letter 8 1/2 x 11 in
Const DMPAPER_LETTERSMALL = 2            '  Letter Small 8 1/2 x 11 in
Const DMPAPER_TABLOID = 3                '  Tabloid 11 x 17 in
Const DMPAPER_LEDGER = 4                 '  Ledger 17 x 11 in
Const DMPAPER_LEGAL = 5                  '  Legal 8 1/2 x 14 in
Const DMPAPER_STATEMENT = 6              '  Statement 5 1/2 x 8 1/2 in
Const DMPAPER_EXECUTIVE = 7              '  Executive 7 1/4 x 10 1/2 in
Const DMPAPER_A3 = 8                     '  A3 297 x 420 mm
Const DMPAPER_A4 = 9                     '  A4 210 x 297 mm
Const DMPAPER_A4SMALL = 10               '  A4 Small 210 x 297 mm
Const DMPAPER_A5 = 11                    '  A5 148 x 210 mm
Const DMPAPER_B4 = 12                    '  B4 250 x 354
Const DMPAPER_B5 = 13                    '  B5 182 x 257 mm
Const DMPAPER_FOLIO = 14                 '  Folio 8 1/2 x 13 in
Const DMPAPER_QUARTO = 15                '  Quarto 215 x 275 mm
Const DMPAPER_10X14 = 16                 '  10x14 in
Const DMPAPER_11X17 = 17                 '  11x17 in
Const DMPAPER_NOTE = 18                  '  Note 8 1/2 x 11 in
Const DMPAPER_ENV_9 = 19                 '  Envelope #9 3 7/8 x 8 7/8
Const DMPAPER_ENV_10 = 20                '  Envelope #10 4 1/8 x 9 1/2
Const DMPAPER_ENV_11 = 21                '  Envelope #11 4 1/2 x 10 3/8
Const DMPAPER_ENV_12 = 22                '  Envelope #12 4 \276 x 11
Const DMPAPER_ENV_14 = 23                '  Envelope #14 5 x 11 1/2
Const DMPAPER_CSHEET = 24                '  C size sheet
Const DMPAPER_DSHEET = 25                '  D size sheet
Const DMPAPER_ESHEET = 26                '  E size sheet
Const DMPAPER_ENV_DL = 27                '  Envelope DL 110 x 220mm
Const DMPAPER_ENV_C5 = 28                '  Envelope C5 162 x 229 mm
Const DMPAPER_ENV_C3 = 29                '  Envelope C3  324 x 458 mm
Const DMPAPER_ENV_C4 = 30                '  Envelope C4  229 x 324 mm
Const DMPAPER_ENV_C6 = 31                '  Envelope C6  114 x 162 mm
Const DMPAPER_ENV_C65 = 32               '  Envelope C65 114 x 229 mm
Const DMPAPER_ENV_B4 = 33                '  Envelope B4  250 x 353 mm
Const DMPAPER_ENV_B5 = 34                '  Envelope B5  176 x 250 mm
Const DMPAPER_ENV_B6 = 35                '  Envelope B6  176 x 125 mm
Const DMPAPER_ENV_ITALY = 36             '  Envelope 110 x 230 mm
Const DMPAPER_ENV_MONARCH = 37           '  Envelope Monarch 3.875 x 7.5 in
Const DMPAPER_ENV_PERSONAL = 38          '  6 3/4 Envelope 3 5/8 x 6 1/2 in
Const DMPAPER_FANFOLD_US = 39            '  US Std Fanfold 14 7/8 x 11 in
Const DMPAPER_FANFOLD_STD_GERMAN = 40    '  German Std Fanfold 8 1/2 x 12 in
Const DMPAPER_FANFOLD_LGL_GERMAN = 41    '  German Legal Fanfold 8 1/2 x 13 in
Const DMPAPER_USER = 256
Const DMBIN_ONLYONE = 1
Const DMBIN_LOWER = 2
Const DMBIN_MIDDLE = 3
Const DMBIN_MANUAL = 4
Const DMBIN_ENVELOPE = 5
Const DMBIN_ENVMANUAL = 6
Const DMBIN_AUTO = 7
Const DMBIN_TRACTOR = 8
Const DMBIN_SMALLFMT = 9
Const DMBIN_LARGEFMT = 10
Const DMBIN_LARGECAPACITY = 11
Const DMBIN_CASSETTE = 14
Const DMBIN_USER = 256
Const DMRES_DRAFT = (-1)
Const DMRES_LOW = (-2)
Const DMRES_MEDIUM = (-3)
Const DMRES_HIGH = (-4)
Const DMTT_BITMAP = 1            '  print TT fonts as graphics
Const DMTT_DOWNLOAD = 2          '  download TT fonts as soft fonts
Const DMTT_SUBDEV = 3            '  substitute device fonts for TT fonts
Const DMTT_DOWNLOAD_OUTLINE = 4 '  download TT fonts as outline soft
Const DMCOLLATE_FALSE = 0
Const DMCOLLATE_TRUE = 1
Const DMICMMETHOD_NONE = 1       '  ICM disabled
Const DMICMMETHOD_SYSTEM = 2     '  ICM handled by system
Const DMICMMETHOD_DRIVER = 3     '  ICM handled by driver
Const DMICMMETHOD_DEVICE = 4     '  ICM handled by device
Const DMICMMETHOD_USER = 256     '  Device-specific methods start here
Const DMICM_SATURATE = 1         '  Maximize color saturation
Const DMICM_CONTRAST = 2         '  Maximize color contrast
Const DMICM_COLORMETRIC = 3      '  Use specific color metric
Const DMICM_USER = 256           '  Device-specific intents start here
Const DMMEDIA_STANDARD = 1       '  Standard paper
Const DMMEDIA_TRANSPARENCY = 2   '  Transparency
Const DMMEDIA_GLOSSY = 3         '  Glossy paper
Const DMMEDIA_SPECIALPAPER=269   ' A driver-specific value, for the
Const DMMEDIA_BOND=268           ' HP DeskJet 680C printer-driver.

Declare Function AbortDoc Lib "gdi32.dll" Alias "AbortDoc" (hdc As Long) As Long
Declare Function AbortPrinter Lib "winspool.drv" Alias "AbortPrinter" (hPrinter As Long) As Long
Declare Function AdvancedDocumentProperties Lib "winspool.drv" Alias "AdvancedDocumentPropertiesA" (hwnd As Long, hPrinter As Long, deviceName As String, devmodeOutput As long, devmodeInput As long) As Long
Declare Function AngleArc Lib "gdi32.dll" Alias "AngleArc" (hdc As Long, x As Long, y As Long, radius As Long, startAngle As Double, sweepAngle As Double) As Long
Declare Function Arc Lib "gdi32.dll" Alias "Arc" (hdc As Long, x As Long, y As Long, x1 As Long, y1 As Long, x2 As Long, y2 As Long, x3 As Long, y3 As Long) As Long
Declare Function ArcTo Lib "gdi32.dll" Alias "ArcTo" (hdc As Long, x As Long, y As Long, x1 As Long, y1 As Long, x2 As Long, y2 As Long, x3 As Long, y3 As Long) As Long
Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (destDC As Long, x As Long, y As Long, width As Long, height As Long, sourceDC As Long, xSource As Long, ySource As Long, rop As Long) As Long
Declare Function Chord Lib "gdi32.dll" Alias "Chord" (hdc As Long, left As Long, top As Long, right As Long, bottom As Long, r1 As Long, r2 As Long, r3 As Long, r4 As Long) As Long
Declare Function ClosePrinter Lib "winspool.drv" Alias "ClosePrinter" (handle As Long) As Long
Declare Function CommDlgExtendedError Lib "comdlg32.dll" Alias "CommDlgExtendedError" () As Long
Declare Function ConfigurePort Lib "winspool.drv" Alias "ConfigurePortA" (serverName As Long, hwnd As Long, portName As Long) As Long
Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dest As LONG, ByVal source As LONG, ByVal numBytes As LONG)
Declare Function CreateBitmap Lib "gdi32.dll" Alias "CreateBitmap" (width As Long, height As Long, planes As Long, bitCount As Long, bits As Word) As Long
Declare Function CreateBrushIndirect Lib "gdi32.dll" Alias "CreateBrushIndirect" (Brush As long) As Long
Declare Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (driverName As String, deviceName As String, portName As String, initData As long) As Long
Declare Function CreateFont Lib "gdi32.dll" Alias "CreateFontA" (H As Long, W As Long, E As Long, O As Long, Weight As Long, I As Long, U As Long, S As Long, CharSet As Long, OP As Long, CP As Long, Q As Long, PAF As Long, Font As long) As Long
Declare Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (fontData As long) As Long
Declare Function CreatePatternBrush Lib "gdi32.dll" Alias "CreatePatternBrush" (hBitmap As Long) As Long
Declare Function CreatePen Lib "gdi32.dll" Alias "CreatePen" (penStyle As Long, nWidth As Long, colour As Long) As Long
Declare Function CreateSolidBrush Lib "gdi32.dll" Alias "CreateSolidBrush" (colour As Long) As Long
Declare Function DeleteDC Lib "gdi32.dll" Alias "DeleteDC" (hdc As Long) As Long
Declare Function DeleteObject Lib "gdi32.dll" Alias "DeleteObject" (hObject As Long) As Long
Declare Function DeletePrinter Lib "winspool.drv" Alias "DeletePrinter" (hPrinter As Long) As Long
Declare Function DeletePrinterDriver Lib "winspool.drv" Alias "DeletePrinterDriverA" (serverName As long, environment As long, driverName As long) As Long
Declare Function DeviceCapabilities Lib "winspool.drv" Alias "DeviceCapabilitiesA" (deviceName As String, portName As String, query_flag As Long, buffer As long, devMode As long) As Long
Declare Function DocumentProperties Lib "winspool.drv" Alias "DocumentPropertiesA" (hwindow As Long, hprinter As Long, deviceName As String, outDevMode As long, inDevMode As long, fMode As Long) As Long
Declare Function DrawEdge Lib "user32.dll" Alias "DrawEdge" (hdc As Long, edgeRect As Long, edge As Long, flags As Long) As Long
Declare Function DrawText Lib "user32.dll" Alias "DrawTextA" (hdc As Long, buf As BYTE, bufsize As Long, rect As long, format As Long) As Long
Declare Function Ellipse Lib "gdi32.dll" Alias "Ellipse" (hdc As Long, X1 As Long, Y1 As Long, X2 As Long, Y2 As Long) As Long
Declare Function EndDoc Lib "gdi32.dll" Alias "EndDoc" (hdc As Long) As Long
Declare Function EndDocPrinter Lib "winspool.drv" Alias "EndDocPrinter" (hPrinter As Long) As Long
Declare Function EndPage Lib "gdi32.dll" Alias "EndPage" (hdc as long) As Long
Declare Function EndPagePrinter Lib "winspool.drv" Alias "EndPagePrinter" (hPrinter As Long) As Long
Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (handle As Long, firstJob As Long, numJobs As Long, level As Long, buf As long, bufsize as Long, needed As Long, returned As Long) As Long
Declare Function EnumPorts Lib "winspool.drv" Alias "EnumPortsA" (serverName As String, level As Long, buffer As Long, bufsize As Long, needed As Long, returned As Long) As Long
Declare Function EnumPrinterDrivers Lib "winspool.drv" Alias "EnumPrinterDriversA" (serverName As String, environment As long, level As Long, buffer As long, bufsize As Long, needed As Long, retruned As Long) As Long
Declare Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA" (flags As Long, name As String, level As Long, buf As long, bufsize As Long, needed As Long, returned As Long) As Long
Declare Function Escape Lib "gdi32.dll" Alias "Escape" (hdc As Long, escape As Long, bufsize As Long, buffer As long, outData As Long) As Long
Declare Function ExtEscape Lib "gdi32.dll" Alias "ExtEscape" (hdc As Long, escape As Long, bufsize1 As Long, buffer1 As Long, bufsize2 As Long, buffer2 As Long) As Long
Declare Function FillRect Lib "user32.dll" Alias "FillRect" (hdc As Long, rect As long, hBrush As Long) As Long
Declare Function FrameRect Lib "user32.dll" Alias "FrameRect" (hdc As Long, frameRect As Long, hBrush As Long) As Long
Declare Function GetBkColor Lib "gdi32.dll" Alias "GetBkColor" (hdc As Long) As Long
Declare Function GetBkMode Lib "gdi32.dll" Alias "GetBkMode" (hdc As Long) As Long
Declare Function GetDC Lib "user32.dll" Alias "GetDC" (hwnd As Long) As Long
Declare Function GetDesktopWindow Lib "user32.dll" Alias "GetDesktopWindow" () As Long
Declare Function GetDeviceCaps Lib "gdi32.dll" Alias "GetDeviceCaps" (hdc As Long, query_flag As Long) As Long
Declare Function GetJob Lib "winspool.drv" Alias "GetJobA" (hPrinter As Long, jobId As Long, level As Long, buf as long, bufsize As Long, needed As Long) As Long
Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As Long
Declare Function GetGraphicsMode Lib "gdi32.dll" Alias "GetGraphicsMode" (hdc As Long) As Long
Declare Function GetMapMode Lib "gdi32.dll" Alias "GetMapMode" (hdc As Long) As Long
Declare Function GetPixel Lib "gdi32.dll" Alias "GetPixel" (hdc As Long, x As Long, y As Long) As Long
Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" (handle As Long, level As Long, buf as long, bufsize As Long, needed As Long) As Long
Declare Function GetPrinterDriver Lib "winspool.drv" Alias "GetPrinterDriverA" (hPrinter As Long, environment As String, level As Long, buffer As long, bufsize As Long, needed As Long) As Long
Declare Function GetStockObject Lib "gdi32.dll" Alias "GetStockObject" (object As Long) As Long
Declare Function GetStretchBltMode Lib "gdi32.dll" Alias "GetStretchBltMode" (hdc As Long) As Long
Declare Function GetTextAlign Lib "gdi32.dll" Alias "GetTextAlign" (hdc As Long) As Long
Declare Function GetTextCharacterExtra Lib "gdi32.dll" Alias "GetTextCharacterExtraA" (hdc As Long) As Long
Declare Function GetTextColor Lib "gdi32.dll" Alias "GetTextColor" (hdc As Long) As Long
Declare Function GlobalAlloc Lib "kernel32.dll" Alias "GlobalAlloc" (flags As Long, numBytes As Long) As Long
Declare Function GlobalFree Lib "kernel32.dll" Alias "GlobalFree" (hMem As Long) As Long
Declare Function GlobalLock Lib "kernel32.dll" Alias "GlobalLock" (hMem As Long) As Long
Declare Function GlobalUnlock Lib "kernel32.dll" Alias "GlobalUnlock" (hMem As Long) As Long
Declare Function LineTo Lib "gdi32.dll" Alias "LineTo" (hdc As Long, x As Long, y As Long) As Long
Declare Function MoveToEx Lib "gdi32.dll" Alias "MoveToEx" (hdc As Long, x As Long, y As Long, curPos As long) As Long
Declare Function MulDiv Lib "kernel32.dll" Alias "MulDiv" (number As Long, numerator As Long, denominator As Long) As Long
Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (printerName As String, handle As Long, pDefault As Long) As Long
Declare Function PageSetupDlg Lib "comdlg32.dll" Alias "PageSetupDlgA" (pageSetupDialog As long) As Long
Declare Function PatBlt Lib "gdi32.dll" Alias "PatBlt" (hdc As Long, x As Long, y As Long, width As Long, height As Long, rop As Long) As Long
Declare Function PolyBezier Lib "gdi32.dll" Alias "PolyBezier" (hdc As Long, points As long, numPoints As Long) As Long
Declare Function PolyBezierTo Lib "gdi32.dll" Alias "PolyBezierTo" (hdc As Long, points As long, numPoints As Long) As Long
Declare Function Polyline Lib "gdi32.dll" Alias "Polyline" (hdc As Long, points As long, numPoints As Long) As Long
Declare Function PolylineTo Lib "gdi32.dll" Alias "PolylineTo" (hdc As Long, points As long, numPoints As Long) As Long
Declare Function PrintDlg Lib "comdlg32.dll" Alias "PrintDlgA" (printDlg As long) As Long
Declare Function PrinterProperties Lib "winspool.drv" Alias "PrinterProperties" (hWindow As Long, hPrinter As Long) As Long
Declare Function ReadPrinter Lib "winspool.drv" Alias "ReadPrinter" (hPrinter As Long, buffer as long, bufsize As Long, bytesRead As Long) As Long
Declare Function Rectangle Lib "gdi32.dll" Alias "Rectangle" (hdc As Long, X1 As Long, Y1 As Long, X2 As Long, Y2 As Long) As Long
Declare Function ReleaseDC Lib "user32.dll" Alias "ReleaseDC" (hwnd As Long, hdc As Long) As Long
Declare Function ResetDC Lib "gdi32.dll" Alias "ResetDCA" (hdc As Long, initData As long) As Long
Declare Function RoundRect Lib "gdi32.dll" Alias "RoundRect" (hdc As Long, X1 As Long, Y1 As Long, X2 As Long, Y2 As Long, X3 As Long, Y3 As Long) As Long
Declare Function SelectObject Lib "gdi32.dll" Alias "SelectObject" (hdc As Long, hObject As Long) As Long
Declare Function SetBkColor Lib "gdi32.dll" Alias "SetBkColor" (hdc As Long, colour As Long) As Long
Declare Function SetBkMode Lib "gdi32.dll" Alias "SetBkMode" (hdc As Long, mode As Long) As Long
Declare Function SetGraphicsMode Lib "gdi32.dll" Alias "SetGraphicsMode" (hdc As Long, mode As Long) As Long
Declare Function SetJob Lib "winspool.drv" Alias "SetJobA" (hPrinter As Long, jobId As Long, level As Long, buf as long, command As Long) As Long
Declare Function SetLastError Lib "kernel32" Alias "SetLastError" (errorCode As Long) as long
Declare Function SetMapMode Lib "gdi32.dll" Alias "SetMapMode" (hdc As Long, mapMode As Long) As Long
Declare Function SetMapperFlags Lib "gdi32.dll" Alias "SetMapperFlags" (hdc As Long, flag As Long) As Long
Declare Function SetPixel Lib "gdi32.dll" Alias "SetPixel" (hdc As Long, x As Long, y As Long, colour As Long) As Long
Declare Function SetPrinter Lib "winspool.drv" Alias "SetPrinterA" (hPrinter As Long, level As Long, buffer As long, command As Long) As Long
Declare Function SetStretchBltMode Lib "gdi32.dll" Alias "SetStretchBltMode" (hdc As Long, stretchMode As Long) As Long
Declare Function SetTextAlign Lib "gdi32.dll" Alias "SetTextAlign" (hdc As Long, flags As Long) As Long
Declare Function SetTextCharacterExtra Lib "gdi32.dll" Alias "SetTextCharacterExtraA" (hdc As Long, spacing As Long) As Long
Declare Function SetTextColor Lib "gdi32.dll" Alias "SetTextColor" (hdc As Long, colour As Long) As Long
Declare Function StartDoc Lib "gdi32.dll" Alias "StartDocA" (hdc As Long, docInfo As long) As Long
Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (hPrinter As Long, level As Long, docInfo As long) As Long
Declare Function StartPage Lib "gdi32.dll" Alias "StartPage" (hdc As Long) As Long
Declare Function StartPagePrinter Lib "winspool.drv" Alias "StartPagePrinter" (hPrinter As Long) As Long
Declare Function StretchBlt Lib "gdi32.dll" Alias "StretchBlt" (hdc As Long, x As Long, y As Long, width As Long, height As Long, sourceDC As Long, xSource As Long, ySource As Long, wSource As Long, hSource As Long, rop As Long) As Long
Declare Function TextOut Lib "gdi32.dll" Alias "TextOutA" (hdc As Long, x As Long, y As Long, buffer As long, bufsize As Long) As Long
Declare Function WritePrinter Lib "winspool.drv" Alias "WritePrinter" (hPrinter As Long, buf AS BYTE, bufsize As LONG, bytesWritten As Long) As Long

' IN GENERAL, PLEASE DO NOT TOUCH THE VARIABLES BELOW.

' Printer/Function Variables.
DIM prt_Handle AS LONG, prt_DC AS LONG
DIM prt_opened AS BYTE, prt_error AS BYTE
DIM needed AS LONG, rtnval AS LONG, jobID AS LONG
DIM dm_Memory AS LONG, dm_Default AS LONG, dm_mem AS BYTE
DIM pi2_Memory AS LONG, pi2_Default AS LONG, pi2_mem AS BYTE
DIM jobs_Memory AS LONG, jobs_Default AS LONG, jobs_mem AS BYTE
DIM jobs_Lock AS LONG
DIM job_Memory AS LONG, job_Default AS LONG, job_mem AS BYTE
DIM job_Lock AS LONG
DIM pd_Memory AS LONG, pd_Default AS LONG, pd_mem AS BYTE
DIM pd_Lock AS LONG
DIM pi2_DevMode
DIM wsize AS LONG, hsize AS LONG, FAdr AS LONG, FLen AS LONG
DIM FInt AS INTEGER, FLong AS LONG, FWord AS WORD, FByte AS BYTE
DIM FLock AS LONG, pi2Lock AS LONG, dmLock AS LONG
DIM FFour AS LONG, FTwo AS WORD, FOne AS BYTE

' Printer/Function Strings.
DIM prt_Name$ AS STRING, prt_Port$ AS STRING, device_Name$ AS STRING
DIM emf$ AS STRING, raw$ AS STRING, prt_Error$ AS STRING
DIM driver_Name$ AS STRING, emf_Title$ AS STRING, raw_Title$ AS STRING
DIM document_Dir$ AS STRING, document_File$ AS STRING
DIM document_Name$ AS STRING, output_File$ AS STRING

' Printer/Memory Structure Variables.
DIM ports(0 TO 500) AS LONG,drivers(0 TO 500) AS LONG
DIM printers(0 TO 500) AS LONG,pDefault(0 TO 2) AS LONG
DIM dtypes(0 TO 30) AS LONG
DIM bins(0 TO 30) AS WORD, bin_Name$(0 TO 30) AS STRING
DIM papers(0 TO 30) AS WORD, papersizes(0 TO 60) AS LONG
DIM paper_Name$(0 TO 30) AS STRING
DIM point(0 TO 1) AS LONG,resolutions(0 TO 30) AS LONG

DIM brush(0 TO 2) AS LONG
DIM rect(0 TO 3) AS LONG, curves(0 TO 50) AS long, dtRect(0 TO 1) AS LONG
DIM raw_buffer(0 TO 1000) AS BYTE, points(0 TO 50) AS LONG
DIM text_buffer(0 TO 1000) AS BYTE
DIM dn(0 TO 4) AS LONG
DIM eRect(0 TO 3) AS LONG, fRect(0 TO 3) AS LONG
DIM bm_Handle AS LONG, bm_bitsArray(0 TO 200) AS WORD

' Printer Drawing variables.
DIM pen AS LONG, oldpen AS LONG, pen_set AS BYTE
DIM hbrush AS LONG, oldhbrush AS LONG, hbrush_set AS BYTE
DIM sbrush AS LONG, oldsbrush AS LONG, sbrush_set AS BYTE
DIM pbrush AS LONG, oldpbrush AS LONG, pbrush_set AS BYTE
DIM sfont AS LONG, oldsfont AS LONG, sfont_set AS BYTE
DIM sobject AS LONG, oldsobject AS LONG, sobject_set AS BYTE
DIM oldBGColour AS LONG, bgColour AS LONG
DIM oldBGMode AS LONG, bgMode AS LONG, pixelRGB AS LONG
DIM oldMapFlags AS LONG, oldSM AS LONG, currentSM AS LONG
DIM oldMapMode AS LONG, mapMode AS LONG
DIM oldGraphicsMode AS LONG, graphicsMode AS LONG
DIM oldtextalign AS LONG, textalign AS LONG
DIM oldtextcolour AS LONG, textcolour AS LONG
DIM oldtextspacing AS LONG, textspacing AS LONG
DIM bm_Window AS LONG, bm_DC AS LONG

' Generic variables.
DIM stg$ AS STRING, rtn AS LONG, count AS LONG
DIM size AS LONG, file AS QFILESTREAM

emf$="EMF" : emf_title$="EMF Data Document"
raw$="RAW" : raw_title$="RAW Data Document"

document_Dir$="C:\\My Documents\\"
document_Name$="Test.txt"
document_File$=document_Dir$+document_Name$
output_File$=document_Dir$+"OutputFile.txt"

FOR count=0 TO 30
bin_Name$(count)=String$(26, 0)
paper_Name$(count)=String$(66, 0)
NEXT

' Fill the RAW buffer with random characters.
Randomize(-5)
FOR count=0 TO 999 : raw_buffer(count)=32+Rnd(85) : NEXT

SUB Show_DevMode
IF ((prt_opened=1) AND (dm_mem=1)) THEN
showmessage("DevMode - DeviceName: "+varptr$(dm_Default))
CopyMemory VarPtr(FWord), dm_Default+32, 2
showmessage("DevMode - Specification Version: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+34, 2
showmessage("DevMode - Driver Version: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+36, 2
showmessage("DevMode - dmSize: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+38, 2
showmessage("DevMode - Driver Extra Size: "+str$(FWord))
CopyMemory VarPtr(FFour), dm_Default+40, 4
showmessage("DevMode - Fields: "+str$(FFour))
CopyMemory VarPtr(FWord), dm_Default+44, 2
showmessage("DevMode - Orientation: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+46, 2
showmessage("DevMode - Paper Size: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+48, 2
showmessage("DevMode - Paper Length: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+50, 2
showmessage("DevMode - Paper Width: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+52, 2
showmessage("DevMode - Scale: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+54, 2
showmessage("DevMode - Copies: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+56, 2
showmessage("DevMode - Bins: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+58, 2
showmessage("DevMode - Quality: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+60, 2
showmessage("DevMode - Colour: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+62, 2
showmessage("DevMode - Duplex: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+64, 2
showmessage("DevMode - YResolution: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+66, 2
showmessage("DevMode - TrueType Option: "+str$(FWord))
CopyMemory VarPtr(FWord), dm_Default+70, 2
showmessage("DevMode - Collate: "+str$(FWord))

' 72 DeviceName - 30 characters stored here (not a pointer).

CopyMemory VarPtr(FWord), dm_Default+102, 2
showmessage("DevMode - LogicalPixels: "+str$(FWord))
CopyMemory VarPtr(FFour), dm_Default+104, 4
showmessage("DevMode - BitsPerPixel: "+str$(FFour))
CopyMemory VarPtr(FFour), dm_Default+108, 4
showmessage("DevMode - PixelWidth: "+str$(FFour))
CopyMemory VarPtr(FFour), dm_Default+112, 4
showmessage("DevMode - PixelHeight: "+str$(FFour))
CopyMemory VarPtr(FFour), dm_Default+116, 4
showmessage("DevMode - DisplayFlags: "+str$(FFour))
CopyMemory VarPtr(FFour), dm_Default+120, 4
showmessage("DevMode - DisplayFrequency: "+str$(FFour))
CopyMemory VarPtr(FFour), dm_Default+124, 4
showmessage("DevMode - ICMMethod: "+str$(FFour))
CopyMemory VarPtr(FFour), dm_Default+128, 4
showmessage("DevMode - ICMIntent: "+str$(FFour))
CopyMemory VarPtr(FFour), dm_Default+132, 4
showmessage("DevMode - MediaType: "+str$(FFour))
CopyMemory VarPtr(FFour), dm_Default+136, 4
showmessage("DevMode - DitherType: "+str$(FFour))

' 140 and 144 are reserved.
END IF
END SUB

SUB Show_PI2
IF ((prt_opened=1) AND (pi2_mem=1)) THEN
CopyMemory VarPtr(FAdr), pi2_Default, 4
showmessage("PI2 - ServerName: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+4, 4
showmessage("PI2 - PrinterName: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+8, 4
showmessage("PI2 - ShareName: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+12, 4
showmessage("PI2 - PortName: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+16, 4
showmessage("PI2 - DriverName: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+20, 4
showmessage("PI2 - Comment: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+24, 4
showmessage("PI2 - Location: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+32, 4
showmessage("PI2 - Seperator File: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+36, 4
showmessage("PI2 - PrintProcessor: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+40, 4
showmessage("PI2 - DataType: "+varptr$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+44, 4
showmessage("PI2 - Parameters: "+varptr$(FAdr))
' 48 SECURITY DESCRIPTOR
CopyMemory VarPtr(FAdr), pi2_Default+52, 4
showmessage("PI2 - Attributes: "+str$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+56, 4
showmessage("PI2 - Priority: "+str$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+60, 4
showmessage("PI2 - Default Priority: "+str$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+64, 4
showmessage("PI2 - Start Time: "+str$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+68, 4
showmessage("PI2 - Until Time: "+str$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+72, 4
showmessage("PI2 - Status: "+str$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+76, 4
showmessage("PI2 - Jobs: "+str$(FAdr))
CopyMemory VarPtr(FAdr), pi2_Default+80, 4
showmessage("PI2 - AveragePPM: "+str$(FAdr))

showmessage("DevMode - DeviceName: "+varptr$(pi2_Default+96))
CopyMemory VarPtr(FWord), pi2_Default+128, 2
showmessage("DevMode - Specification Version: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+130, 2
showmessage("DevMode - Driver Version: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+132, 2
showmessage("DevMode - dmSize: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+134, 2
showmessage("DevMode - Driver Extra Size: "+str$(FWord))
CopyMemory VarPtr(FFour), pi2_Default+136, 4
showmessage("DevMode - Fields: "+str$(FFour))
CopyMemory VarPtr(FWord), pi2_Default+140, 2
showmessage("DevMode - Orientation: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+142, 2
showmessage("DevMode - Paper Size: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+144, 2
showmessage("DevMode - Paper Length: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+146, 2
showmessage("DevMode - Paper Width: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+148, 2
showmessage("DevMode - Scale: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+150, 2
showmessage("DevMode - Copies: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+152, 2
showmessage("DevMode - Bins: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+154, 2
showmessage("DevMode - Quality: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+156, 2
showmessage("DevMode - Colour: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+158, 2
showmessage("DevMode - Duplex: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+160, 2
showmessage("DevMode - YResolution: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+162, 2
showmessage("DevMode - TrueType Option: "+str$(FWord))
CopyMemory VarPtr(FWord), pi2_Default+166, 2
showmessage("DevMode - Collate: "+str$(FWord))

' 168 DeviceName - 30 characters stored here (not a pointer).

CopyMemory VarPtr(FWord), pi2_Default+198, 2
showmessage("DevMode - LogicalPixels: "+str$(FWord))
CopyMemory VarPtr(FFour), pi2_Default+200, 4
showmessage("DevMode - BitsPerPixel: "+str$(FFour))
CopyMemory VarPtr(FFour), pi2_Default+204, 4
showmessage("DevMode - PixelWidth: "+str$(FFour))
CopyMemory VarPtr(FFour), pi2_Default+208, 4
showmessage("DevMode - PixelHeight: "+str$(FFour))
CopyMemory VarPtr(FFour), pi2_Default+212, 4
showmessage("DevMode - DisplayFlags: "+str$(FFour))
CopyMemory VarPtr(FFour), pi2_Default+216, 4
showmessage("DevMode - DisplayFrequency: "+str$(FFour))
CopyMemory VarPtr(FFour), pi2_Default+220, 4
showmessage("DevMode - ICMMethod: "+str$(FFour))
CopyMemory VarPtr(FFour), pi2_Default+224, 4
showmessage("DevMode - ICMIntent: "+str$(FFour))
CopyMemory VarPtr(FFour), pi2_Default+228, 4
showmessage("DevMode - MediaType: "+str$(FFour))
CopyMemory VarPtr(FFour), pi2_Default+232, 4
showmessage("DevMode - DitherType: "+str$(FFour))

' 236 and 240 are reserved.
END IF
END SUB

SUB Show_Jobs
IF ((prt_opened=1) AND (jobs_mem=1)) THEN
CopyMemory VarPtr(FFour), jobs_Default, 4
showmessage("GJ - JobID: "+str$(FFour))
CopyMemory VarPtr(FAdr), jobs_Default+4, 4
showmessage("GJ - PrinterName: "+Varptr$(FAdr))
CopyMemory VarPtr(FAdr), jobs_Default+8, 4
showmessage("GJ - MachineName: "+Varptr$(FAdr))
CopyMemory VarPtr(FAdr), jobs_Default+12, 4
showmessage("GJ - UserName: "+Varptr$(FAdr))
CopyMemory VarPtr(FAdr), jobs_Default+16, 4
showmessage("GJ - DocumentName: "+Varptr$(FAdr))
CopyMemory VarPtr(FAdr), jobs_Default+20, 4
showmessage("GJ - NotifyName: "+Varptr$(FAdr))
CopyMemory VarPtr(FAdr), jobs_Default+24, 4
showmessage("GJ - DataType: "+Varptr$(FAdr))
CopyMemory VarPtr(FAdr), jobs_Default+28, 4
showmessage("GJ - PrintProcessor: "+Varptr$(FAdr))
CopyMemory VarPtr(FAdr), jobs_Default+32, 4
showmessage("GJ - Parameters: "+Varptr$(FAdr))
CopyMemory VarPtr(FAdr), jobs_Default+36, 4
showmessage("GJ - DriverName: "+Varptr$(FAdr))

' jobs_Default+40 = pointer to DevMode.

CopyMemory VarPtr(FAdr), jobs_Default+44, 4
showmessage("GJ - Status String: "+Varptr$(FAdr))

' jobs_Default+48 = pointer to Security Descriptor.

CopyMemory VarPtr(FFour), jobs_Default+52, 4
showmessage("GJ - Status DWORD: "+hex$(FFour))
CopyMemory VarPtr(FFour), jobs_Default+56, 4
showmessage("GJ - Priority: "+hex$(FFour))
CopyMemory VarPtr(FFour), jobs_Default+60, 4
showmessage("GJ - Position: "+hex$(FFour))
CopyMemory VarPtr(FFour), jobs_Default+64, 4
showmessage("GJ - Start Time: "+hex$(FFour))
CopyMemory VarPtr(FFour), jobs_Default+68, 4
showmessage("GJ - Until Time: "+hex$(FFour))
CopyMemory VarPtr(FFour), jobs_Default+72, 4
showmessage("GJ - Total Pages: "+hex$(FFour))
CopyMemory VarPtr(FFour), jobs_Default+76, 4
showmessage("GJ - Size: "+hex$(FFour))

' SystemTime Structure - Time the documented started printing.
CopyMemory VarPtr(FWord), jobs_Default+80, 2
showmessage("GJ - Year: "+str$(FWord))
CopyMemory VarPtr(FWord), jobs_Default+82, 2
showmessage("GJ - Month: "+str$(FWord))
CopyMemory VarPtr(FWord), jobs_Default+84, 2
showmessage("GJ - Day Of The Week: "+str$(FWord+1))
CopyMemory VarPtr(FWord), jobs_Default+86, 2
showmessage("GJ - Day: "+str$(FWord))
CopyMemory VarPtr(FWord), jobs_Default+88, 2
showmessage("GJ - Hour: "+str$(FWord+1))
CopyMemory VarPtr(FWord), jobs_Default+90, 2
showmessage("GJ - Minute: "+str$(FWord))
CopyMemory VarPtr(FWord), jobs_Default+92, 2
showmessage("GJ - Seconds: "+str$(FWord))
CopyMemory VarPtr(FWord), jobs_Default+94, 2
showmessage("GJ - MilliSeconds: "+str$(FWord))

CopyMemory VarPtr(FFour), jobs_Default+96, 4
showmessage("GJ - Time: "+hex$(FFour))
CopyMemory VarPtr(FFour), jobs_Default+100, 4
showmessage("GJ - Pages Printed: "+hex$(FFour))

' The next jobs is at 104 - Example....
'CopyMemory VarPtr(FFour), jobs_Default+104, 4
'showmessage("GJ - JobID: "+str$(FFour))
'CopyMemory VarPtr(FAdr), jobs_Default+108, 4
'showmessage("GJ - PrinterName: "+Varptr$(FAdr))
' ......
' Etc Etc

END IF
END SUB

SUB Free_dmMemory
IF dm_mem=1 THEN
rtn=GlobalUnlock(dmLock)
IF ((rtn=0) AND (GetLastError()=0)) THEN
'MEM UNLOCKED
ELSE
'MEM NOT UNLOCK
END IF
rtn=GlobalFree(dm_Memory)
IF rtn=0 THEN
'MEM FREED
dm_mem=0
ELSE
'MEM NOT FREED
END IF
END IF
END SUB

SUB Free_pi2Memory
IF pi2_mem=1 THEN
rtn=GlobalUnlock(pi2Lock)
IF ((rtn=0) AND (GetLastError()=0)) THEN
'MEM UNLOCKED
ELSE
'MEM NOT UNLOCK
END IF
rtn=GlobalFree(pi2_Memory)
IF rtn=0 THEN
'MEM FREED
pi2_mem=0
ELSE
'MEM NOT FREED
END IF
END IF
END SUB

SUB Free_jobsMemory
IF jobs_mem=1 THEN
rtn=GlobalUnlock(jobs_Lock)
IF ((rtn=0) AND (GetLastError()=0)) THEN
'MEM UNLOCKED
ELSE
'MEM NOT UNLOCK
END IF
rtn=GlobalFree(jobs_Memory)
IF rtn=0 THEN
'MEM FREED
jobs_mem=0
ELSE
'MEM NOT FREED
END IF
END IF
END SUB

SUB Free_jobMemory
IF job_mem=1 THEN
rtn=GlobalUnlock(job_Lock)
IF ((rtn=0) AND (GetLastError()=0)) THEN
'MEM UNLOCKED
ELSE
'MEM NOT UNLOCK
END IF
rtn=GlobalFree(job_Memory)
IF rtn=0 THEN
'MEM FREED
job_mem=0
ELSE
'MEM NOT FREED
END IF
END IF
END SUB

SUB UnLock_DefaultMemory
rtn=GlobalUnlock(FLock)
IF ((rtn=0) AND (GetLastError()=0)) THEN
'MEM UNLOCKED
ELSE
'MEM NOT UNLOCK
END IF
END SUB

SUB Free_DefaultMemory
rtn=GlobalFree(FLong)
IF rtn=0 THEN
'MEM FREED
ELSE
'MEM NOT FREED
END IF
END SUB

SUB Free_pdMemory
IF pd_mem=1 THEN
rtn=GlobalUnlock(pd_Lock)
IF ((rtn=0) AND (GetLastError()=0)) THEN
'PD_MEM UNLOCKED
ELSE
'PD_MEM NOT UNLOCK
END IF
rtn=GlobalFree(pd_Memory)
IF rtn=0 THEN
'PD_MEM FREED
ELSE
'PD_MEM NOT FREED
END IF
END IF
END SUB

SUB Set_Orientation(landscape AS WORD, setFlag AS BYTE)
FWord=landscape
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+44, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+140, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+44, VarPtr(FWord), 2
CopyMemory pi2_Default+140, VarPtr(FWord), 2
END IF
END SUB

SUB Set_PaperSize(papersize AS WORD, setFlag AS BYTE)
FWord=papersize
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+46, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+142, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+46, VarPtr(FWord), 2
CopyMemory pi2_Default+142, VarPtr(FWord), 2
END IF
END SUB

SUB Set_PaperLength(paperlength AS WORD, setFlag AS BYTE)
FWord=paperlength
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+48, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+144, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+48, VarPtr(FWord), 2
CopyMemory pi2_Default+144, VarPtr(FWord), 2
END IF
END SUB

SUB Set_PaperWidth(paperwidth AS WORD, setFlag AS BYTE)
FWord=paperwidth
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+50, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+146, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+50, VarPtr(FWord), 2
CopyMemory pi2_Default+146, VarPtr(FWord), 2
END IF
END SUB

SUB Set_Scale(scaleFactor AS WORD, setFlag AS BYTE)
FWord=scaleFactor
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+52, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+148, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+52, VarPtr(FWord), 2
CopyMemory pi2_Default+148, VarPtr(FWord), 2
END IF
END SUB

SUB Set_Copies(numCopies AS WORD, setFlag AS BYTE)
FWord=numCopies
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+54, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+150, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+54, VarPtr(FWord), 2
CopyMemory pi2_Default+150, VarPtr(FWord), 2
END IF
END SUB

SUB Set_PaperFeed(bin AS WORD, setFlag AS BYTE)
FWord=bin
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+56, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+152, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+56, VarPtr(FWord), 2
CopyMemory pi2_Default+152, VarPtr(FWord), 2
END IF
END SUB

SUB Set_PrintQuality(quality AS WORD, setFlag AS BYTE)
FWord=quality
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+58, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+154, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+58, VarPtr(FWord), 2
CopyMemory pi2_Default+154, VarPtr(FWord), 2
END IF
END SUB

SUB Set_ColourMode(mode AS WORD, setFlag AS BYTE)
FWord=mode
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+60, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+156, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+60, VarPtr(FWord), 2
CopyMemory pi2_Default+156, VarPtr(FWord), 2
END IF
END SUB

SUB Set_Duplex(mode AS WORD, setFlag AS BYTE)
FWord=mode
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+62, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+158, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+62, VarPtr(FWord), 2
CopyMemory pi2_Default+158, VarPtr(FWord), 2
END IF
END SUB

SUB Set_YResolution(yDPI AS WORD, setFlag AS BYTE)
FWord=yDPI
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+64, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+160, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+64, VarPtr(FWord), 2
CopyMemory pi2_Default+160, VarPtr(FWord), 2
END IF
END SUB

SUB Set_TTOption(option AS WORD, setFlag AS BYTE)
FWord=option
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+66, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+162, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+66, VarPtr(FWord), 2
CopyMemory pi2_Default+162, VarPtr(FWord), 2
END IF
END SUB

SUB Set_Collate(option AS WORD, setFlag AS BYTE)
FWord=option
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+70, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+166, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+70, VarPtr(FWord), 2
CopyMemory pi2_Default+166, VarPtr(FWord), 2
END IF
END SUB

SUB Set_PixelsPerLogicalInch(numPixels AS WORD, setFlag AS BYTE)
FWord=numPixels
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+102, VarPtr(FWord), 2
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+198, VarPtr(FWord), 2
ELSE
CopyMemory dm_Default+102, VarPtr(FWord), 2
CopyMemory pi2_Default+198, VarPtr(FWord), 2
END IF
END SUB

SUB Set_ICMMethod(method AS LONG, setFlag AS BYTE)
FFour=method
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+124, VarPtr(FFour), 4
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+220, VarPtr(FFour), 4
ELSE
CopyMemory dm_Default+124, VarPtr(FFour), 4
CopyMemory pi2_Default+220, VarPtr(FFour), 4
END IF
END SUB

SUB Set_ICMIntent(intent AS LONG, setFlag AS BYTE)
FFour=intent
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+128, VarPtr(FFour), 4
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+224, VarPtr(FFour), 4
ELSE
CopyMemory dm_Default+128, VarPtr(FFour), 4
CopyMemory pi2_Default+224, VarPtr(FFour), 4
END IF
END SUB

SUB Set_MediaType(mediaType AS LONG, setFlag AS BYTE)
FFour=mediaType
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+132, VarPtr(FFour), 4
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+228, VarPtr(FFour), 4
ELSE
CopyMemory dm_Default+132, VarPtr(FFour), 4
CopyMemory pi2_Default+228, VarPtr(FFour), 4
END IF
END SUB

SUB Set_DitherType(dither AS LONG, setFlag AS BYTE)
FFour=dither
IF setFlag=SET_DDM THEN
CopyMemory dm_Default+136, VarPtr(FFour), 4
ELSEIF setFlag=SET_PI2DM THEN
CopyMemory pi2_Default+232, VarPtr(FFour), 4
ELSE
CopyMemory dm_Default+136, VarPtr(FFour), 4
CopyMemory pi2_Default+232, VarPtr(FFour), 4
END IF
END SUB

SUB Set_ServerName(name$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default, 4
stg$=name$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_PrinterName(name$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+4, 4
stg$=name$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_ShareName(name$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+8, 4
stg$=name$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_PortName(name$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+12, 4
stg$=name$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_DriverName(name$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+16, 4
stg$=name$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_Location(location$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+24, 4
stg$=location$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_SeperatorFile(sfile$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+32, 4
stg$=sfile$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_PrintProcessor(name$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+36, 4
stg$=name$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_DataType(name$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+40, 4
stg$=name$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Set_Parameters(name$ AS STRING)
CopyMemory VarPtr(FAdr), pi2_Default+44, 4
stg$=name$+CHR$(0)
CopyMemory FAdr, VarPtr(stg$), LEN(stg$)
END SUB

SUB Advanced_Document_Properties
IF prt_opened=1 THEN
rtn=AdvancedDocumentProperties(0, prt_Handle, device_Name$, dm_Default, dm_Default)
IF rtn=1 THEN

END IF
END IF
END SUB

SUB Properties_Window
IF prt_opened=1 THEN
rtn=PrinterProperties(0, prt_Handle)
IF rtn<>0 THEN

END IF
END IF
END SUB

SUB Configure_Port(serverAdr AS LONG, portAdr AS LONG)
IF prt_opened=1 THEN
rtn=ConfigurePort(serverAdr, 0, portAdr)
IF rtn<>0 THEN

END IF
END IF
END SUB

SUB Document_Properties
IF prt_opened=1 THEN
rtn=DocumentProperties(0, prt_Handle, device_Name$, dm_Default, dm_Default, DM_MODIFY OR DM_PROMPT OR DM_COPY)
IF rtn>-1 THEN
IF rtn=IDOK THEN
ShowMessage("User Pressed: OKAY or Exit")
ELSEIF rtn=IDCANCEL THEN
ShowMessage("User Pressed: CANCEL")
END IF
END IF
END IF
END SUB

SUB PageSetupDialog
IF prt_opened=1 THEN
FLong=GlobalAlloc(GMEM_MOVEABLE OR GMEM_ZEROINIT, 3000)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
FFour=84
CopyMemory FInt, VarPtr(FFour), 4
FFour=PD_RETURNDEFAULT
CopyMemory FInt+16, VarPtr(FFour), 4
rtn=PageSetupDlg(FInt)
IF rtn<>0 THEN

' Note: Here I have disabled most options as you can get/set them from
' other features in this code. Also. This dialog does not initialize
' the devmode - it just utilizes certain values from the computer`s
' default printer. Although it returns a global pointer to a DevMode
' this is not neccessarily a valid devmode (depending on user input).
' Therefore. Just use this dialog to setup (calculate) the Margins only.
'
' Personally, if it wasn`t for the Margins feature, I wouldn`t use
' this dialogat all.

' Flags
FFour=PSD_INTHOUSANDTHSOFINCHES OR PSD_MINMARGINS OR PSD_MARGINS OR PSD_DISABLEORIENTATION OR PSD_DISABLEPRINTER OR PSD_DISABLEPAPER
CopyMemory FInt+16, VarPtr(FFour), 4

' Paper Size  -  These two values are really for the callback hook with
' WM_PSD_PAGESETUPDLG. Ignore them.
FFour=0
CopyMemory FInt+20, VarPtr(FFour), 4
FFour=0
CopyMemory FInt+24, VarPtr(FFour), 4

' 1000`s of an Inch. 1000 = 1 Inch. Below I use an half-inch (0.5)
' margin as the minimum the user can specify.
'
' You will not get an error if user specifies less than
' 500 (0.5 / half-inch) but the return will be 500, as default, in
' this case.

' Minimum values for the Margins
FFour=500
CopyMemory FInt+28, VarPtr(FFour), 4
FFour=500
CopyMemory FInt+32, VarPtr(FFour), 4
FFour=500
CopyMemory FInt+36, VarPtr(FFour), 4
FFour=500
CopyMemory FInt+40, VarPtr(FFour), 4

' Maximum values for the Margins  -  The max margins I have set below
' are 1 inch (left), 1.5 inch (top), 1.5 inch (right) and 1 inch (bottom).
FFour=1000
CopyMemory FInt+44, VarPtr(FFour), 4
FFour=1250
CopyMemory FInt+48, VarPtr(FFour), 4
FFour=1250
CopyMemory FInt+52, VarPtr(FFour), 4
FFour=1000
CopyMemory FInt+56, VarPtr(FFour), 4

rtn=PageSetupDlg(FInt)
IF rtn=1 THEN

' Show the user`s minimum margin settings.
CopyMemory VarPtr(FFour), FInt+28, 4
showmessage(str$(FFour))
CopyMemory VarPtr(FFour), FInt+32, 4
showmessage(str$(FFour))
CopyMemory VarPtr(FFour), FInt+36, 4
showmessage(str$(FFour))
CopyMemory VarPtr(FFour), FInt+40, 4
showmessage(str$(FFour))

' Show the user`s maximum margin settings.
CopyMemory VarPtr(FFour), FInt+44, 4
showmessage(str$(FFour))
CopyMemory VarPtr(FFour), FInt+48, 4
showmessage(str$(FFour))
CopyMemory VarPtr(FFour), FInt+52, 4
showmessage(str$(FFour))
CopyMemory VarPtr(FFour), FInt+56, 4
showmessage(str$(FFour))

ELSEIF rtn=0 THEN

' User pressed Cancel or there was an error.

ELSE
rtn=CommDlgExtendedError
showmessage(hex$(rtn))
END IF
ELSE
rtn=CommDlgExtendedError
showmessage(hex$(rtn))
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Print_Dialog
IF prt_opened=1 THEN
FLong=GlobalAlloc(GMEM_MOVEABLE OR GMEM_ZEROINIT, 3000)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
FFour=66
CopyMemory FInt, VarPtr(FFour), 4
FFour=PD_RETURNDEFAULT OR PD_RETURNDC
CopyMemory FInt+20, VarPtr(FFour), 4
rtn=PrintDlg(FInt)
IF rtn=1 THEN

' The PrintDlg works on a Input/Output basis. This means what you
' initialize (setup) for the user/Dialog is known as the Input. And
' what the dialog returns is known as the Output.
'
' The following is a case of mix `n` match to suit your particular
' Printer. For example:
'
' PD_USEDEVMODECOPIESANDCOLLATE should be used to use your real printer
' settings. This will disable/hide the Copies and Collate buttons if
' they are not supported by your printer driver. This is true of my
' Epson RX-80. In this case you go by the number-of-pages to print
' rather than the number of copies. This just said scenario can be over
' ridden by not specify USEDEVMODECOPIESANDCOLLATE and specifying
' PD_SELECTION OR PD_COLLATE instead. If you do not use the
' USEDEVMODECOPIESANDCOLLATE flag though the copies and collate result
' goes into the devmode (devmode pointer).
'
' Flags:  PD_SELECTION means selection button is default
'         PD_PAGENUMS ......    pages   ................
'         PD_ALLPAGES ......     all    ................
' If none are selected then ALL is the default.
'
' PRINTOTFILE means Print to the FILE: port.

FFour=PD_SELECTION OR PD_COLLATE OR PD_PAGENUMS OR PD_PRINTTOFILE
CopyMemory FInt+20, VarPtr(FFour), 4
FWord=1 ' from page
CopyMemory FInt+24, VarPtr(FWord), 2
FWord=6 ' to page
CopyMemory FInt+26, VarPtr(FWord), 2
FWord=1  ' minimum range for the pages
CopyMemory FInt+28, VarPtr(FWord), 2
FWord=9  ' maximum range for the pages
CopyMemory FInt+30, VarPtr(FWord), 2
FWord=4  ' number of copies to print
CopyMemory FInt+32, VarPtr(FWord), 2
rtn=PrintDlg(FInt)
IF rtn=1 THEN

' show the flags value. If collate is set it means collate is not
' supported (like on my Epson RX-80).
CopyMemory VarPtr(FFour), FInt+20, 4
showmessage(HEX$(FFour))

' show the min. page and max. page the user specified.
CopyMemory VarPtr(FWord), FInt+24, 2
showmessage(HEX$(FWord))
CopyMemory VarPtr(FWord), FInt+26, 2
showmessage(HEX$(FWord))

' show the number of copies to print that the user specified.
CopyMemory VarPtr(FWord), FInt+32, 2
showmessage(HEX$(FWord))

ELSEIF rtn=0 THEN

' User pressed Cancel or there was an error.

ELSE
rtn=CommDlgExtendedError
showmessage(hex$(rtn))
END IF
ELSE
rtn=CommDlgExtendedError
showmessage(hex$(rtn))
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Enum_Ports(serverName AS STRING, level AS LONG)
prt_error=1
rtn=EnumPorts(serverName, level, 0, 0, @needed, @rtnval)
IF ((rtn=0) AND (GetLastError()=ERROR_INSUFFICIENT_BUFFER)) THEN
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, needed)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
rtn=EnumPorts(serverName, level, FInt, needed, @needed, @rtnval)
IF rtn=1 THEN
prt_error=0
FOR count=0 TO rtnval-1
IF level=1 THEN
CopyMemory VarPtr(ports(count)), FInt, 4
INC (FInt, 4)
ELSE
CopyMemory VarPtr(ports((0+(count*5)))), FInt, 4
CopyMemory VarPtr(ports((1+(count*5)))), FInt+4, 4
CopyMemory VarPtr(ports((2+(count*5)))), FInt+8, 4
CopyMemory VarPtr(ports((3+(count*5)))), FInt+12, 4
CopyMemory VarPtr(ports((4+(count*5)))), FInt+16, 4
INC (FInt, 20)
END IF
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Enum_Drivers(serverName AS STRING, level AS LONG)
prt_error=1
rtn=EnumPrinterDrivers(serverName, 0, level, 0, 0, @needed, @rtnval)
IF ((rtn=0) AND (GetLastError()=ERROR_INSUFFICIENT_BUFFER)) THEN
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, needed)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
rtn=EnumPrinterDrivers(serverName, 0, level, FInt, needed, @needed, @rtnval)
IF rtn=1 THEN
prt_error=0
FOR count=0 TO rtnval-1
IF level=1 THEN
CopyMemory VarPtr(drivers(count)), FInt, 4
INC (FInt, 4)
ELSEIF level=2 THEN
CopyMemory VarPtr(drivers((0+(count*6)))), FInt, 4
CopyMemory VarPtr(drivers((1+(count*6)))), FInt+4, 4
CopyMemory VarPtr(drivers((2+(count*6)))), FInt+8, 4
CopyMemory VarPtr(drivers((3+(count*6)))), FInt+12, 4
CopyMemory VarPtr(drivers((4+(count*6)))), FInt+16, 4
CopyMemory VarPtr(drivers((5+(count*6)))), FInt+20, 4
INC (FInt, 24)
ELSE
CopyMemory VarPtr(drivers((0+(count*10)))), FInt, 4
CopyMemory VarPtr(drivers((1+(count*10)))), FInt+4, 4
CopyMemory VarPtr(drivers((2+(count*10)))), FInt+8, 4
CopyMemory VarPtr(drivers((3+(count*10)))), FInt+12, 4
CopyMemory VarPtr(drivers((4+(count*10)))), FInt+16, 4
CopyMemory VarPtr(drivers((5+(count*10)))), FInt+20, 4
CopyMemory VarPtr(drivers((6+(count*10)))), FInt+24, 4
CopyMemory VarPtr(drivers((7+(count*10)))), FInt+28, 4
CopyMemory VarPtr(drivers((8+(count*10)))), FInt+32, 4
CopyMemory VarPtr(drivers((9+(count*10)))), FInt+36, 4
INC (FInt, 40)
END IF
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Enum_Printers(flag AS LONG, name AS STRING, level AS LONG, get_default AS BYTE, default_printer$ AS STRING, default_port$ AS STRING)
prt_error=1
rtn=EnumPrinters(flag, name, level, 0, 0, @needed, @rtnval)
IF ((rtn=0) AND (GetLastError()=ERROR_INSUFFICIENT_BUFFER)) THEN
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, needed)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
rtn=EnumPrinters(flag, name, level, FInt, needed, @needed, @rtnval)
IF rtn=1 THEN
IF get_Default=0 THEN
prt_error=0
FOR count=0 TO rtnval-1
IF level=1 THEN
CopyMemory VarPtr(printers((0+(count*4)))), FInt, 4
CopyMemory VarPtr(printers((1+(count*4)))), FInt+4, 4
CopyMemory VarPtr(printers((2+(count*4)))), FInt+8, 4
CopyMemory VarPtr(printers((3+(count*4)))), FInt+12, 4
INC (FInt, 16)
ELSEIF level=2 THEN

ELSEIF level=4 THEN
CopyMemory VarPtr(printers((0+(count*3)))), FInt, 4
CopyMemory VarPtr(printers((1+(count*3)))), FInt+4, 4
CopyMemory VarPtr(printers((2+(count*3)))), FInt+8, 4
INC (FInt, 12)
ELSEIF level=5 THEN
CopyMemory VarPtr(printers((0+(count*5)))), FInt, 4
CopyMemory VarPtr(printers((1+(count*5)))), FInt+4, 4
CopyMemory VarPtr(printers((2+(count*5)))), FInt+8, 4
CopyMemory VarPtr(printers((3+(count*5)))), FInt+12, 4
CopyMemory VarPtr(printers((4+(count*5)))), FInt+16, 4
INC (FInt, 20)
END IF
NEXT
ELSE
' check the Attributes element/field to get the Default Printer.
count=0
WHILE ((count<rtnval) AND (prt_error=1))
CopyMemory VarPtr(FFour), FInt+8, 4
IF (FFour AND PRINTER_ATTRIBUTE_DEFAULT)=PRINTER_ATTRIBUTE_DEFAULT THEN
prt_error=0
' Copy the printer name into prt_Name$ string.
CopyMemory VarPtr(FAdr), FInt, 4
FLen=LEN(VarPtr$(FAdr))
prt_Name$=String$(FLen, 0)
CopyMemory VarPtr(prt_Name$), FAdr, FLen
' Copy the port name into prt_Port$ string.
CopyMemory VarPtr(FAdr), FInt+4, 4
FLen=LEN(VarPtr$(FAdr))
prt_Port$=String$(FLen, 0)
CopyMemory VarPtr(prt_Port$), FAdr, FLen
END IF
INC (FInt, 20)
INC count
WEND
IF prt_error=1 THEN
' Could not get Default Printer - So use a default printer-driver instead.
prt_error=0
prt_Name$=default_printer$
prt_Port$=default_port$
END IF
ShowMessage("Default Printer: "+prt_Name$+"\n\nDefault Port: "+prt_Port$)
END IF
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Create_DC()
' The Printer Device Context tells the computer what your Printer is
' capable of doing (Printing Circles, Using Fonts, Pens, etc). When you
' want to change the Printer`s pen for example you pass it this pointer.
prt_error=1
prt_DC=0
prt_DC=CreateDC("", prt_Name$, "", 0)
IF prt_DC<>0 THEN
prt_error=0

ELSE
ShowMessage("DC - Not Created")
END IF
END SUB

SUB Open_Printer()
prt_opened=0
prt_error=1
pDefault(0)=""
pDefault(1)=0
pDefault(2)=PRINTER_ACCESS_ADMINISTER OR PRINTER_ACCESS_USE OR STANDARD_RIGHTS_REQUIRED
rtn=OpenPrinter(prt_Name$, @prt_Handle, @pd_Default)
IF rtn<>0 THEN
prt_opened=1
prt_error=0

ELSE
ShowMessage("Printer - Not Opened")
END IF
END SUB

SUB Get_Driver(environment AS STRING, level AS LONG)
prt_error=1
IF prt_opened=1 THEN
rtn=GetPrinterDriver(prt_Handle, environment, level, 0, 0, @needed)
IF ((rtn=0) AND (GetLastError()=ERROR_INSUFFICIENT_BUFFER)) THEN
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, needed)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
rtn=GetPrinterDriver(prt_Handle, environment, level, FInt, needed, @needed)
IF rtn=1 THEN
prt_error=0
IF level=1 THEN
CopyMemory VarPtr(drivers(count)), FInt, 4
INC (FInt, 4)
ELSEIF level=2 THEN
CopyMemory VarPtr(drivers((0+(count*6)))), FInt, 4
CopyMemory VarPtr(drivers((1+(count*6)))), FInt+4, 4
CopyMemory VarPtr(drivers((2+(count*6)))), FInt+8, 4
CopyMemory VarPtr(drivers((3+(count*6)))), FInt+12, 4
CopyMemory VarPtr(drivers((4+(count*6)))), FInt+16, 4
CopyMemory VarPtr(drivers((5+(count*6)))), FInt+20, 4
INC (FInt, 24)
ELSE
CopyMemory VarPtr(drivers((0+(count*10)))), FInt, 4
CopyMemory VarPtr(drivers((1+(count*10)))), FInt+4, 4
CopyMemory VarPtr(drivers((2+(count*10)))), FInt+8, 4
CopyMemory VarPtr(drivers((3+(count*10)))), FInt+12, 4
CopyMemory VarPtr(drivers((4+(count*10)))), FInt+16, 4
CopyMemory VarPtr(drivers((5+(count*10)))), FInt+20, 4
CopyMemory VarPtr(drivers((6+(count*10)))), FInt+24, 4
CopyMemory VarPtr(drivers((7+(count*10)))), FInt+28, 4
CopyMemory VarPtr(drivers((8+(count*10)))), FInt+32, 4
CopyMemory VarPtr(drivers((9+(count*10)))), FInt+36, 4
INC (FInt, 40)
END IF
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END IF
END SUB

SUB Get_PI2
pi2_mem=0
pi2_DevMode=0
prt_error=1
IF prt_opened=1 THEN
rtn=GetPrinter(prt_Handle, 2, 0, 0, @needed)
IF ((rtn=0) AND (GetLastError()=ERROR_INSUFFICIENT_BUFFER)) THEN
pi2_Memory=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, needed)
IF pi2_Memory<>0 THEN
pi2_mem=1
pi2_Default=GlobalLock(pi2_Memory)
IF pi2_Default<>0 THEN
pi2Lock=pi2_Default
rtn=GetPrinter(prt_Handle, 2, pi2_Default, needed, @rtnval)
IF rtn=1 THEN
CopyMemory VarPtr(pi2_DevMode), pi2_Default+28, 4
IF pi2_DevMode<>0 THEN  ' Check for a valid DEVMODE structure
prt_error=0

END IF
END IF
END IF
END IF
END IF
END IF
END SUB

SUB Copy_DevMode(flag AS BYTE)
IF flag=0 THEN
CopyMemory pi2_Default+128, dm_Default+32, 2
CopyMemory pi2_Default+130, dm_Default+34, 2
CopyMemory pi2_Default+132, dm_Default+36, 2
CopyMemory pi2_Default+134, dm_Default+38, 2
CopyMemory pi2_Default+136, dm_Default+40, 4
CopyMemory pi2_Default+140, dm_Default+44, 2
CopyMemory pi2_Default+142, dm_Default+46, 2
CopyMemory pi2_Default+144, dm_Default+48, 2
CopyMemory pi2_Default+146, dm_Default+50, 2
CopyMemory pi2_Default+148, dm_Default+52, 2
CopyMemory pi2_Default+150, dm_Default+54, 2
CopyMemory pi2_Default+152, dm_Default+56, 2
CopyMemory pi2_Default+154, dm_Default+58, 2
CopyMemory pi2_Default+156, dm_Default+60, 2
CopyMemory pi2_Default+158, dm_Default+62, 2
CopyMemory pi2_Default+160, dm_Default+64, 2
CopyMemory pi2_Default+162, dm_Default+66, 2
CopyMemory pi2_Default+164, dm_Default+68, 2

CopyMemory pi2_Default+198, dm_Default+102, 2
CopyMemory pi2_Default+200, dm_Default+104, 4
CopyMemory pi2_Default+204, dm_Default+108, 4
CopyMemory pi2_Default+208, dm_Default+112, 4
CopyMemory pi2_Default+212, dm_Default+116, 4
CopyMemory pi2_Default+216, dm_Default+120, 4
CopyMemory pi2_Default+220, dm_Default+124, 4
CopyMemory pi2_Default+224, dm_Default+128, 4
CopyMemory pi2_Default+228, dm_Default+132, 4
CopyMemory pi2_Default+232, dm_Default+136, 4
ELSE
CopyMemory dm_Default+32, pi2_Default+128, 2
CopyMemory dm_Default+34, pi2_Default+130, 2
CopyMemory dm_Default+36, pi2_Default+132, 2
CopyMemory dm_Default+38, pi2_Default+134, 2
CopyMemory dm_Default+40, pi2_Default+136, 4
CopyMemory dm_Default+44, pi2_Default+140, 2
CopyMemory dm_Default+46, pi2_Default+142, 2
CopyMemory dm_Default+48, pi2_Default+144, 2
CopyMemory dm_Default+50, pi2_Default+146, 2
CopyMemory dm_Default+52, pi2_Default+148, 2
CopyMemory dm_Default+54, pi2_Default+150, 2
CopyMemory dm_Default+56, pi2_Default+152, 2
CopyMemory dm_Default+58, pi2_Default+154, 2
CopyMemory dm_Default+60, pi2_Default+156, 2
CopyMemory dm_Default+62, pi2_Default+158, 2
CopyMemory dm_Default+64, pi2_Default+160, 2
CopyMemory dm_Default+66, pi2_Default+162, 2
CopyMemory dm_Default+68, pi2_Default+164, 2

CopyMemory dm_Default+102, pi2_Default+198, 2
CopyMemory dm_Default+104, pi2_Default+200, 4
CopyMemory dm_Default+108, pi2_Default+204, 4
CopyMemory dm_Default+112, pi2_Default+208, 4
CopyMemory dm_Default+116, pi2_Default+212, 4
CopyMemory dm_Default+120, pi2_Default+216, 4
CopyMemory dm_Default+124, pi2_Default+220, 4
CopyMemory dm_Default+128, pi2_Default+224, 4
CopyMemory dm_Default+132, pi2_Default+228, 4
CopyMemory dm_Default+136, pi2_Default+232, 4
END IF
END SUB

SUB Get_Jobs(firstJob AS LONG, numJobs AS LONG)
jobs_mem=0
prt_error=1
IF prt_opened=1 THEN
rtn=EnumJobs(prt_Handle, firstJob, numJobs, 2, 0, 0, @needed, @rtnval)
IF ((rtn=0) AND (GetLastError()=ERROR_INSUFFICIENT_BUFFER)) THEN
jobs_Memory=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, needed)
IF jobs_Memory<>0 THEN
jobs_mem=1
jobs_Default=GlobalLock(jobs_Memory)
IF jobs_Default<>0 THEN
jobs_Lock=jobs_Default
rtn=EnumJobs(prt_Handle, firstJob, numJobs, 2, jobs_Default, needed, @needed, @rtnval)
IF rtn=1 THEN
prt_error=0

END IF
END IF
END IF
ELSE
showmessage("No Jobs Printing")
END IF
END IF
END SUB

SUB Get_DCVersion
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_VERSION, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_VERSION, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
'rtn is the value.
END IF
END SUB

SUB Get_DCDriver
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_DRIVER, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_DRIVER, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
'rtn is the value.
END IF
END SUB

SUB Get_DCSize
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_SIZE, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_SIZE, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
'rtn is the value.
END IF
END SUB

SUB Get_DCExtra
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_EXTRA, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_EXTRA, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
'rtn is the value.
END IF
END SUB

SUB Get_DCFields
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_FIELDS, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_FIELDS, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
'rtn is the value.
END IF
END SUB

SUB Get_DCOrientation
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_ORIENTATION, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_ORIENTATION, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
IF rtn=0 THEN
'Landscape Orientation NOT Supported
ELSEIF rtn=90 THEN
'Landscape Orientation: 90 degrees (Dot Matrix Printers)
ELSEIF rtn=270 THEN
'Landscape Orientation: 270 degrees (Hewlett Packard PCL Printers)
END IF
END IF
END SUB

SUB Get_DCCopies
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_COPIES, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_COPIES, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
'rtn is the value.
END IF
END SUB

SUB Get_DCDuplex
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_DUPLEX, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_DUPLEX, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
IF rtn=0 THEN
'Duplex Printing NOT Supported
ELSEIF rtn=1 THEN
'Duplex Printing Supported
END IF
END IF
END SUB

SUB Get_DCEmf
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_EMF_COMPLIANT, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_EMF_COMPLIANT, 0, 0)
END IF
IF rtn=-1 THEN
'EMF Not Supported
ELSEIF rtn=1 THEN
prt_error=0
'EMF Supported
END IF
END SUB

SUB Get_DCDataType
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 1000)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_DATATYPE_PRODUCED, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_DATATYPE_PRODUCED, FInt, 0)
END IF
IF rtn=-1 THEN
'Only the RAW DataType Supported
ELSE
prt_error=0
FOR count=0 TO rtn-1
' Copy the datatype names (FInt values) into the dtypes() array.
dtypes(count)=FInt
INC (FInt, 64)
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCBins
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 300)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_BINS, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_BINS, FInt, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
FOR count=0 TO rtn-1
CopyMemory VarPtr(bins(count)), FInt, 2
INC (FInt, 2)
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCBinAdjust
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_BINADJUST, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_BINADJUST, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
'rtn is the value.
END IF
END SUB

SUB Get_DCBinNames
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 1000)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_BINNAMES, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_BINNAMES, FInt, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
FOR count=0 TO rtn-1
CopyMemory VarPtr(bin_Name$(count)), FInt, 24
INC (FInt, 24)
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCPapers
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 300)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_PAPERS, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_PAPERS, FInt, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
FOR count=0 TO rtn-1
CopyMemory VarPtr(papers(count)), FInt, 2
INC (FInt, 2)
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCPaperSize
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 300)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_PAPERSIZE, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_PAPERSIZE, FInt, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
FOR count=0 TO rtn-1
' Copy the X Y Points of the POINT structure into the papersizes array.
' POINT X and Y are measured in millimeters.
CopyMemory VarPtr(papersizes((count*2))), FInt, 4
CopyMemory VarPtr(papersizes((1+(count*2)))), FInt+4, 4
INC (FInt, 8)
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCMinPaperSize
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 300)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_MINEXTENT, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_MINEXTENT, FInt, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
CopyMemory VarPtr(point(0)), FInt, 4
CopyMemory VarPtr(point(1)), FInt+4, 4
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCMaxPaperSize
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 300)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_MAXEXTENT, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_MAXEXTENT, FInt, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
CopyMemory VarPtr(point(0)), FInt, 4
CopyMemory VarPtr(point(1)), FInt+4, 4
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCPaperNames
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 2500)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_PAPERNAMES, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_PAPERNAMES, FInt, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
FOR count=0 TO rtn-1
CopyMemory VarPtr(paper_Name$(count)), FInt, 64
INC (FInt, 64)
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCResolutions
prt_error=1
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 2500)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_ENUMRESOLUTIONS, FInt, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_ENUMRESOLUTIONS, FInt, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
FOR count=0 TO rtn-1
CopyMemory VarPtr(resolutions((count*2))), FInt, 4
CopyMemory VarPtr(resolutions((1+(count*2)))), FInt+4, 4
INC (FInt, 8)
NEXT
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END SUB

SUB Get_DCFontOptions
prt_error=1
IF dm_mem=1 THEN
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_TRUETYPE, 0, dm_Default)
ELSE
rtn=DeviceCapabilities(prt_Name$, prt_Port$, DC_TRUETYPE, 0, 0)
END IF
IF rtn<>-1 THEN
prt_error=0
' You will need to check each bit of rtn for each bit you are interested
' in.
IF (rtn AND DCTT_BITMAP)=DCTT_BITMAP THEN
'TrueType Fonts printed as Graphics (Dot Matrix Printer)
ELSE

END IF
END IF
END SUB

SUB Get_Devmode
dm_mem=0
prt_error=1
IF prt_opened=1 THEN
stg$=""
needed=DocumentProperties(0, prt_Handle, stg$, 0, 0, 0)
IF needed>0 THEN
dm_Memory=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, needed)
IF dm_Memory<>0 THEN
dm_mem=1
dm_Default=GlobalLock(dm_Memory)
IF dm_Default<>0 THEN
dmLock=dm_Default
' copy the current devmode settings in dm_default memory.
rtn=DocumentProperties(0, prt_Handle, stg$, dm_Default, 0, DM_COPY)
IF rtn>-1 THEN
prt_error=0

END IF
END IF
END IF
END IF
END IF
END SUB

SUB Set_NewHBrush(Colour AS LONG, Style AS LONG)
IF prt_DC<>0 THEN
hbrush_set=0
brush(0)=BS_HATCHED
brush(1)=Colour
brush(2)=Style
hbrush=CreateBrushIndirect(@brush(0))
IF hbrush<>0 THEN
oldhbrush=SelectObject(prt_DC, hbrush)
IF oldhbrush<>0 THEN
hbrush_set=1
ELSE
showmessage("SelectObject failed")
END IF
ELSE
showmessage("brush not created")
END IF
END IF
END SUB

SUB Restore_OldHBrush
IF prt_DC<>0 THEN
IF hbrush_set=1 THEN
rtn=DeleteObject(hbrush)
IF rtn=1 THEN
hbrush_set=0
ELSE
showmessage("DeleteObject failed")
END IF
END IF
END IF
END SUB

SUB Set_NewSBrush(colour AS LONG)
IF prt_DC<>0 THEN
sbrush_set=0
sbrush=CreateSolidBrush(colour)
IF sbrush<>0 THEN
oldsbrush=SelectObject(prt_DC, sbrush)
IF oldsbrush<>0 THEN
sbrush_set=1
ELSE
showmessage("SelectObject failed")
END IF
ELSE
showmessage("brush not created")
END IF
END IF
END SUB

SUB Restore_OldSBrush
IF prt_DC<>0 THEN
IF sbrush_set=1 THEN
rtn=DeleteObject(sbrush)
IF rtn=1 THEN
sbrush_set=0
ELSE
showmessage("DeleteObject failed")
END IF
END IF
END IF
END SUB

SUB Set_NewPBrush(bmw As Long, bmh As Long, bmp As Long, bmb As Long)
IF prt_DC<>0 THEN
pbrush_set=0
bm_Handle=0
bm_Handle=CreateBitmap(bmw, bmh, bmp, bmb, @bm_bitsArray(0))
IF bm_Handle<>0 THEN
pbrush=CreatePatternBrush(bm_Handle)
IF pbrush<>0 THEN
oldpbrush=SelectObject(prt_DC, pbrush)
IF oldpbrush<>0 THEN
pbrush_set=1
ELSE
showmessage("SelectObject failed")
END IF
ELSE
showmessage("brush not created")
END IF
ELSE
showmessage("CreateBitmap failed")
END IF
END IF
END SUB

SUB Restore_OldPBrush
IF prt_DC<>0 THEN
IF pbrush_set=1 THEN
rtn=DeleteObject(pbrush)
IF rtn=1 THEN
pbrush_set=0
rtn=DeleteObject(bm_Handle)
IF rtn=1 THEN
bm_Handle=0

ELSE
showmessage("DeleteObject bitmap failed")
END IF
ELSE
showmessage("DeleteObject brush failed")
END IF
END IF
END IF
END SUB

SUB Set_NewSFont(H As Long, W As Long, E As Long, O As Long, Weight As Long, I As Long, U As Long, S As Long, CS As Long, OP As Long, CP As Long, Q As Long, PAF As Long, Font As long)
IF prt_DC<>0 THEN
sfont_set=0
sfont=CreateFont(H, W, E, O, Weight, I, U, S, CS, OP, CP, Q, PAF, Font)
IF sfont<>0 THEN
oldsfont=SelectObject(prt_DC, sfont)
IF oldsfont<>0 THEN
sfont_set=1
ELSE
showmessage("SelectObject failed")
END IF
ELSE
showmessage("font not created")
END IF
END IF
END SUB

SUB Restore_OldSFont
IF prt_DC<>0 THEN
IF sfont_set=1 THEN
rtn=DeleteObject(sfont)
IF rtn=1 THEN
sfont_set=0
ELSE
showmessage("DeleteObject failed")
END IF
END IF
END IF
END SUB

SUB Set_NewPen(Thickness AS BYTE, Colour AS LONG)
IF prt_DC<>0 THEN
pen_set=0
pen=CreatePen(PS_SOLID, Thickness, Colour)
IF pen<>0 THEN
oldpen=SelectObject(prt_DC, pen)
IF oldpen<>0 THEN
pen_set=1
ELSE
showmessage("SelectObject failed")
END IF
ELSE
showmessage("pen not created")
END IF
END IF
END SUB

SUB Restore_OldPen
IF prt_DC<>0 THEN
IF pen_set=1 THEN
rtn=DeleteObject(pen)
IF rtn=1 THEN
pen_set=0
ELSE
showmessage("DeleteObject failed")
END IF
END IF
END IF
END SUB

SUB Set_NewSObject(object AS LONG)
IF prt_DC<>0 THEN
sobject_set=0
sobject=GetStockObject(object)
IF sobject<>0 THEN
oldsobject=SelectObject(prt_DC, sobject)
IF oldsobject<>0 THEN
sobject_set=1
ELSE
showmessage("SelectObject failed")
END IF
ELSE
showmessage("stock_object not created")
END IF
END IF
END SUB

SUB Restore_OldSObject
IF prt_DC<>0 THEN
IF sobject_set=1 THEN
rtn=DeleteObject(sobject)
IF rtn=1 THEN
sobject_set=0
ELSE
showmessage("DeleteObject failed")
END IF
END IF
END IF
END SUB

SUB Print_DrawText(bufsize AS LONG, format AS LONG, left AS LONG, top AS LONG, right AS LONG, bottom AS LONG)
IF prt_DC<>0 THEN
dtRect(0)=left
dtRect(1)=top
dtRect(2)=right
dtRect(3)=bottom
rtn=DrawText(prt_DC, @text_buffer(0), bufsize, @dtRect(0), format)
IF rtn<>0 THEN

ELSE
showmessage("DrawText failed")
END IF
END IF
END SUB

SUB Print_Ellipse(left AS LONG, top AS LONG, right AS LONG, bottom AS LONG)
IF prt_DC<>0 THEN
rtn=Ellipse(prt_DC, left, top, right, bottom)
IF rtn<>0 THEN

ELSE
showmessage("Ellipse failed")
END IF
END IF
END SUB

SUB Print_Rectangle(left AS LONG, top AS LONG, right AS LONG, bottom AS LONG)
IF prt_DC<>0 THEN
rtn=Rectangle(prt_DC, left, top, right, bottom)
IF rtn<>0 THEN

ELSE
showmessage("Rectangle failed")
END IF
END IF
END SUB

SUB Print_RoundRect(left AS LONG, top AS LONG, right AS LONG, bottom AS LONG, width AS LONG, height AS LONG)
IF prt_DC<>0 THEN
rtn=RoundRect(prt_DC, left, top, right, bottom, width, height)
IF rtn<>0 THEN

ELSE
showmessage("RoundRect failed")
END IF
END IF
END SUB

SUB Print_LineTo(x AS LONG, y AS LONG)
IF prt_DC<>0 THEN
rtn=LineTo(prt_DC, x, y)
IF rtn<>0 THEN

ELSE
showmessage("LineTo failed")
END IF
END IF
END SUB

SUB Print_MoveToEx(x AS LONG, y AS LONG)
IF prt_DC<>0 THEN
rtn=MoveToEx(prt_DC, x, y, 0)
IF rtn<>0 THEN

ELSE
showmessage("MoveToEx failed")
END IF
END IF
END SUB

SUB Get_BGColour
IF prt_DC<>0 THEN
bgColour=GetBkColor(prt_DC)
IF bgColour<>CLR_INVALID THEN

ELSE
showmessage("GetBkColor failed")
END IF
END IF
END SUB

SUB Set_BGColour(colour AS LONG)
IF prt_DC<>0 THEN
oldBGColour=SetBkColor(prt_DC, colour)
IF oldBGColour<>CLR_INVALID THEN

ELSE
showmessage("SetBkColor failed")
END IF
END IF
END SUB

SUB Get_BGMode
IF prt_DC<>0 THEN
bgMode=GetBkMode(prt_DC)
IF bgMode<>0 THEN

ELSE
showmessage("GetBkMode failed")
END IF
END IF
END SUB

SUB Set_BGMode(mode AS LONG)
IF prt_DC<>0 THEN
oldBGMode=SetBkMode(prt_DC, mode)
IF oldBGMode<>0 THEN

ELSE
showmessage("SetBkMode failed")
END IF
END IF
END SUB

SUB Print_PolyLine(numPoints AS LONG)
IF prt_DC<>0 THEN
rtn=PolyLine(prt_DC, @points(0), numPoints)
IF rtn<>0 THEN

ELSE
showmessage("PolyLine failed")
END IF
END IF
END SUB

SUB Print_PolyLineTo(numPoints AS LONG)
IF prt_DC<>0 THEN
rtn=PolyLineTo(prt_DC, @points(0), numPoints)
IF rtn<>0 THEN

ELSE
showmessage("PolyLineTo failed")
END IF
END IF
END SUB

SUB Print_FillRect(left AS LONG, top AS LONG, right AS LONG, bottom AS LONG)
IF prt_DC<>0 THEN
rect(0)=left
rect(1)=top
rect(2)=right
rect(3)=bottom
rtn=FillRect(prt_DC, @rect(0), hbrush)
IF rtn<>0 THEN

ELSE
showmessage("FillRect failed")
END IF
END IF
END SUB

SUB Print_PolyBezierTo(numCurves AS LONG)
IF prt_DC<>0 THEN
rtn=PolyBezierTo(prt_DC, @curves(0), numCurves)
IF rtn<>0 THEN

ELSE
showmessage("PolyBezierTo failed")
END IF
END IF
END SUB

SUB Print_AngleArc(x As Long, y As Long, radius As Long, startAngle As Double, sweepAngle As Double)
IF prt_DC<>0 THEN
rtn=AngleArc(prt_DC, x, y, radius, startAngle, sweepAngle)
IF rtn<>0 THEN

ELSE
showmessage("AngleArc failed")
END IF
END IF
END SUB

SUB Print_Arc(left As Long, top As Long, right As Long, bottom As Long, xpoint As Long, ypoint As Long, xarc As Long, yarc As Long)
IF prt_DC<>0 THEN
rtn=Arc(prt_DC, left, top, right, bottom, xpoint, ypoint, xarc, yarc)
IF rtn<>0 THEN

ELSE
showmessage("Arc failed")
END IF
END IF
END SUB

SUB Print_ArcTo(left As Long, top As Long, right As Long, bottom As Long, xpoint As Long, ypoint As Long, xarc As Long, yarc As Long)
IF prt_DC<>0 THEN
rtn=ArcTo(prt_DC, left, top, right, bottom, xpoint, ypoint, xarc, yarc)
IF rtn<>0 THEN

ELSE
showmessage("ArcTo failed")
END IF
END IF
END SUB

SUB Print_Edge(left As Long, top As Long, right As Long, bottom As Long, edge As Long, flags As Long)
IF prt_DC<>0 THEN
eRect(0)=left
eRect(1)=top
eRect(2)=right
eRect(3)=bottom
rtn=DrawEdge(prt_DC, @eRect(0), edge, flags)
IF rtn<>0 THEN

ELSE
showmessage("DrawEdge failed")
END IF
END IF
END SUB

SUB Print_FrameRectangle(left As Long, top As Long, right As Long, bottom As Long, brush As Long)
IF prt_DC<>0 THEN
fRect(0)=left
fRect(1)=top
fRect(2)=right
fRect(3)=bottom
rtn=FrameRect(prt_DC, @fRect(0), brush)
IF rtn<>0 THEN

ELSE
showmessage("FrameRect failed")
END IF
END IF
END SUB

SUB Print_Chord(left As Long, top As Long, right As Long, bottom As Long, r1 As Long, r2 As Long, r3 As Long, r4 As Long)
IF prt_DC<>0 THEN
rtn=Chord(prt_DC, left, top, right, bottom, r1, r2, r3, r4)
IF rtn<>0 THEN

ELSE
showmessage("Chord failed")
END IF
END IF
END SUB

SUB Get_PixelRGB(x As Long, y As Long)
IF prt_DC<>0 THEN
pixelRGB=GetPixel(prt_DC, x, y)
IF pixelRGB<>CLR_INVALID THEN

ELSE
showmessage("GetPixel failed")
END IF
END IF
END SUB

SUB Set_PixelRGB(x As Long, y As Long, colour As Long)
IF prt_DC<>0 THEN
pixelRGB=SetPixel(prt_DC, x, y, colour)
IF pixelRGB<>-1 THEN

ELSE
showmessage("SetPixel failed")
END IF
END IF
END SUB

SUB Get_StretchMode
IF prt_DC<>0 THEN
currentSM=GetStretchBltMode(prt_DC)
IF currentSM<>0 THEN

ELSE
showmessage("GetStretchBltMode failed")
END IF
END IF
END SUB

SUB Set_StretchMode(mode As Long)
IF prt_DC<>0 THEN
oldSM=SetStretchBltMode(prt_DC, mode)
IF oldSM<>0 THEN

ELSE
showmessage("SetStretchBltMode failed")
END IF
END IF
END SUB

SUB Pattern_BitMap(x As Long, y As Long, w As Long, h As Long, copyMode AS LONG)
IF prt_DC<>0 THEN
rtn=PatBlt(prt_DC, x, y, w, h, copyMode)
IF rtn<>0 THEN

ELSE
showmessage("PatBlt failed")
END IF
END IF
END SUB

SUB Blit_BitMap(x As Long, y As Long, w As Long, h As Long, sourceDC As Long, xSource As Long, ySource As Long, copyMode AS Long)
IF prt_DC<>0 THEN
rtn=BitBlt(prt_DC, x, y, w, h, sourceDC, xSource, ySource, copyMode)
IF rtn<>0 THEN

ELSE
' This will fail, as the code is, because I am using two different DC`s.
showmessage("BitBlt failed")
END IF
END IF
END SUB

SUB Stretch_BitMap(x As Long, y As Long, w As Long, h As Long, sourceDC As Long, xSource As Long, ySource As Long, wSource As Long, hSource As Long, copyMode As Long)
IF prt_DC<>0 THEN
rtn=StretchBlt(prt_DC, x, y, w, h, bm_DC, xSource, ySource, wSource, hSource, copyMode)
IF rtn<>0 THEN

ELSE
showmessage("StretchBlt failed")
END IF
END IF
END SUB

SUB Set_MapMode(mode AS LONG)
IF prt_DC<>0 THEN
oldMapMode=SetMapMode(prt_DC, mode)
IF oldMapMode<>0 THEN

ELSE
showmessage("SetMapMode failed")
END IF
END IF
END SUB

SUB Get_MapMode
IF prt_DC<>0 THEN
mapMode=GetMapMode(prt_DC)
IF mapMode<>0 THEN

ELSE
showmessage("GetMapMode failed")
END IF
END IF
END SUB

SUB Set_MapperFlags(flags AS LONG)
IF prt_DC<>0 THEN
oldMapFlags=SetMapperFlags(prt_DC, flags)
IF oldMapFlags<>GDI_ERROR THEN

ELSE
showmessage("SetMapperFlags failed")
END IF
END IF
END SUB

SUB Set_GraphicsMode(mode AS LONG)
IF prt_DC<>0 THEN
oldGraphicsMode=SetGraphicsMode(prt_DC, mode)
IF oldGraphicsMode<>GDI_ERROR THEN

ELSE
showmessage("SetGraphicsMode failed")
END IF
END IF
END SUB

SUB Set_TextColour(colour AS LONG)
IF prt_DC<>0 THEN
oldtextcolour=SetTextColor(prt_DC, colour)
IF oldtextcolour<>CLR_INVALID THEN

ELSE
showmessage("SetTextColor failed")
END IF
END IF
END SUB

SUB Set_TextAlignment(flag AS LONG)
IF prt_DC<>0 THEN
oldtextalign=SetTextAlign(prt_DC, flag)
IF oldtextalign<>GDI_ERROR THEN

ELSE
showmessage("SetTextAlign failed")
END IF
END IF
END SUB

SUB Set_TextSpacing(logicalunits AS LONG)
IF prt_DC<>0 THEN
oldtextspacing=SetTextCharacterExtra(prt_DC, logicalunits)
IF oldtextspacing<>&H80000000 THEN

ELSE
showmessage("SetTextCharacterExtra failed")
END IF
END IF
END SUB

SUB Get_GraphicsMode
IF prt_DC<>0 THEN
graphicsMode=GetGraphicsMode(prt_DC)
IF graphicsMode<>0 THEN

ELSE
showmessage("GetGraphicsMode failed")
END IF
END IF
END SUB

SUB Get_TextAlignment
IF prt_DC<>0 THEN
textalign=GetTextAlign(prt_DC)
IF textalign<>CLR_INVALID THEN

ELSE
showmessage("GetTextAlign failed")
END IF
END IF
END SUB

SUB Get_TextColour
IF prt_DC<>0 THEN
textcolour=GetTextColor(prt_DC)
IF textcolour<>CLR_INVALID THEN

ELSE
showmessage("GetTextColor failed")
END IF
END IF
END SUB

SUB Get_TextSpacing
IF prt_DC<>0 THEN
textspacing=GetTextCharacterExtra(prt_DC)
IF textspacing<>&H8000000 THEN

ELSE
showmessage("GetTextCharacterExtra failed")
END IF
END IF
END SUB

SUB Print_TextOut(x AS LONG, y AS LONG, buffer AS long, bufsize AS LONG)
prt_error=1
IF prt_DC<>0 THEN
rtn=TextOut(prt_DC, x, y, buffer, bufsize)
IF rtn=1 THEN
prt_error=0

ELSE
showmessage("Text not printed")
END IF
END IF
END SUB

SUB Set_Job

END SUB

SUB Get_Job
prt_error=1
job_mem=0
IF prt_opened=1 THEN
job_Memory=GlobalAlloc(GMEM_MOVEABLE OR GMEM_ZEROINIT, 3000)
IF job_Memory<>0 THEN
job_mem=1
job_Default=GlobalLock(job_Memory)
IF job_Default<>0 THEN
job_Lock=job_Default
rtn=GetJob(prt_Handle, jobID, 2, job_Default, 3000, @rtnval)
IF rtn<>0 THEN
prt_error=0

END IF
END IF
END IF
END IF
END SUB

SUB Modify_DevMode
prt_error=1
IF prt_opened=1 THEN
rtn=DocumentProperties(0, prt_Handle, device_Name$, dm_Default, dm_Default, DM_MODIFY OR DM_COPY)
IF rtn>-1 THEN
IF rtn=IDOK THEN
prt_error=0

END IF
END IF
END IF
END SUB

SUB Set_Printer
prt_error=1
IF prt_opened=1 THEN
FFour=0
CopyMemory pi2_Default+48, VarPtr(FFour), 4
SetPrinter(prt_Handle, 2, pi2_Default, 0)
IF rtn<>0 THEN
prt_error=0

ELSE
IF GetLastError()<>0 THEN
showmessage("SetPrinter() Error: "+str$(GetLastError()))
ELSE
' You may end up here if you set portname of pi2->portname to a
' non-printer port name (i.e "COM1:"). Other pi2 fields may cause
' you to end up here.
END IF
END IF
END IF
END SUB

SUB Abort_Printer
' This is one cool command! It really does STOP the printer`s jobs
' (including the current job).
prt_error=1
IF prt_opened=1 THEN
AbortPrinter(prt_Handle)
IF rtn<>0 THEN
prt_error=0
showmessage("Printer`s Spooler-File has been Deleted")
ELSE
showmessage(str$(getlasterror())+" "+str$(rtn))
END IF
END IF
END SUB

SUB Abort_Document
prt_error=1
IF prt_DC<>0 THEN
AbortDoc(prt_DC)
IF rtn>0 THEN
prt_error=0
showmessage("Document has been Aborted")
ELSE
showmessage(str$(getlasterror())+" "+str$(rtn))
END IF
END IF
END SUB

SUB Print_Text(useOutputFile AS BYTE)
IF prt_opened=1 THEN

' Allocate memory for the DocInfo structure.
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 20)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt

' Initialize the DocInfo Structure.
FFour=20
CopyMemory FInt, VarPtr(FFour), 4
FFour=VarPtr(emf_Title$)
CopyMemory FInt+4, VarPtr(FFour), 4
IF useOutputFile=0 THEN
output_File$=""
END IF
FFour=VarPtr(output_File$)
CopyMemory FInt+8, VarPtr(FFour), 4
FFour=VarPtr(emf$)
CopyMemory FInt+12, VarPtr(FFour), 4
FFour=0
CopyMemory FInt+16, VarPtr(FFour), 4

' Setup the Documentation Page.
jobID=StartDoc(prt_DC, FInt)
IF jobID>0 THEN

' Everything between StartPage and EndPage is one page. If you want
' to draw on another page (the next page) you must do another
' StartPage and EndPage after this one.

rtn=StartPage(prt_DC)
IF rtn>0 THEN

' Just play around with the font values below - I used most of the
' default values, but also used ITALIC, UNDERLINE etc to show they
' work. Note: CreateFontIndirect() isn`t that good for this code as
' it requires Byte format that doesn`t work properly (in this code only).
' Hence why I switched to CreateFont(), which shows that RapidQ can pass
' 14 arguments/parameters!!

' Note: The sizes reflect the fact that I am using a FINE setting on
' my printer (best quality).

' Font Height I would like is 36.
hsize=-MulDiv(36, GetDeviceCaps(prt_DC, LOGPIXELSX), 72)
' Font Width I would like is 16.
wsize=-MulDiv(16, GetDeviceCaps(prt_DC, LOGPIXELSY), 72)
' fontname.
stg$="Futura Black BT"

' Put the Font into the DC, Print the Text and then Restore the Old Font.
Set_NewSFont(hsize, wsize, 1, 1, FW_BOLD, ITALIC_ON, UNDERLINE_ON, STRIKEOUT_ON, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH OR FF_DONTCARE, VarPtr(stg$))
' TextOut() takes a buffer as an argument, not a string. Thus. You
' could pass the address of a buffer rather than the address of a String.
stg$="The quick brown fox jumps over the lazy dog."
Print_TextOut(0, 0, VarPtr(stg$), 44)
Restore_OldSFont

rtn=EndPage(prt_DC)
IF rtn>0 THEN

ELSE
showmessage("EndPage failed")
END IF
ELSE
showmessage("StartPage failed")
END IF

' Put another StartPage and EndPage here if you want to print another
' page.

rtn=EndDoc(prt_DC)
IF rtn>0 THEN
' Finish Here
ELSE
showmessage("EndDoc failed")
END IF
ELSE
showmessage("StartDoc failed")
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Print_Document(useOutputFile AS BYTE)
IF prt_opened=1 THEN

' Allocate memory for the DocInfo structure.
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 20)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt

' Initialize the DocInfo Structure.
FFour=20
CopyMemory FInt, VarPtr(FFour), 4
FFour=VarPtr(emf_Title$)
CopyMemory FInt+4, VarPtr(FFour), 4
IF useOutputFile=0 THEN
output_File$=""
END IF
FFour=VarPtr(output_File$)
CopyMemory FInt+8, VarPtr(FFour), 4
FFour=VarPtr(emf$)
CopyMemory FInt+12, VarPtr(FFour), 4
FFour=0
CopyMemory FInt+16, VarPtr(FFour), 4

' Setup the Documentation Page.
jobID=StartDoc(prt_DC, FInt)
IF jobID>0 THEN

' Everything between StartPage and EndPage is one page. If you want
' to draw on another page (the next page) you must do another
' StartPage and EndPage after this one.

rtn=StartPage(prt_DC)
IF rtn>0 THEN

' Print a Document. There are other ways to Allocate and Fill the buffer.
' You could fill/print one line at a time, change the buffer from LONG to
' STRING format, so that you can File.ReadStr() for example, etc.

IF DirExists (document_Dir$) <> 0 THEN
IF FileExists (document_File$) <> 0 THEN
IF File.Open (document_File$, fmOpenRead) <> 0 THEN
size=file.size
DEC (size, 2) ' The proper file-size
FOR count=0 TO size : text_buffer(count)=file.readnum(1) : NEXT
File.Close 
Print_DrawText(size, DT_LEFT OR DT_WORDBREAK OR DT_NOCLIP, 0, 0, 3200, 3200)
ELSE
File.Close
ShowMessage(document_File$+"\n\nThe above file was Not Loaded")
END IF
ELSE
ShowMessage(document_File$+"\n\nThe above file was Not Found")
END IF
ELSE
ShowMessage(document_Dir$+"\n\nThis Directory/Folder was Not Found")
END IF

rtn=EndPage(prt_DC)
IF rtn>0 THEN

ELSE
showmessage("EndPage failed")
END IF
ELSE
showmessage("StartPage failed")
END IF

' Put another StartPage and EndPage here if you want to print another
' page.

rtn=EndDoc(prt_DC)
IF rtn>0 THEN
' Finish Here
ELSE
showmessage("EndDoc failed")
END IF
ELSE
showmessage("StartDoc failed")
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Print_RAWBuffer(useOutputFile AS BYTE)
IF prt_opened=1 THEN

' Allocate memory for the DocInfo1 structure.
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 12)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt

' Initialize the DocInfo1 Structure.
FFour=VarPtr(raw_Title$)
CopyMemory FInt, VarPtr(FFour), 4
IF useOutputFile=0 THEN
output_File$=""
END IF
FFour=VarPtr(output_File$)
CopyMemory FInt+4, VarPtr(FFour), 4
FFour=VarPtr(raw$)
CopyMemory FInt+8, VarPtr(FFour), 4

jobID=StartDocPrinter(prt_Handle, 1, FInt)
IF jobID<>0 THEN
rtn=StartPagePrinter(prt_Handle)
IF rtn<>0 THEN

' PAUSE this Job (not the Printer).
rtn=SetJob(prt_Handle, jobID, 0, 0, JOB_CONTROL_PAUSE)
IF rtn<>0 THEN

' Get this Job`s info.
Get_Job

' Change this job`s Priority. The job_info_2 structure is the same
' as jobs_Default (see Show_Jobs).
FFour=67
CopyMemory job_Default+56, VarPtr(FFour), 4

' RESUME this Job.
rtn=SetJob(prt_Handle, jobID, 2, job_Default, JOB_CONTROL_RESUME)
IF rtn<>0 THEN

' Print some RAW data.
rtn=WritePrinter(prt_Handle, @raw_buffer(0), 1000, @rtnval)
IF rtn<>0 THEN

' FINISH here.

END IF
END IF

' Free this Job`s memory.
Free_jobMemory

END IF

rtn=EndPagePrinter(prt_Handle)
IF rtn<>0 THEN

ELSE
showmessage("EndPagePrinter failed")
END IF
ELSE
showmessage("StartPagePrinter failed")
END IF
rtn=EndDocPrinter(prt_Handle)
IF rtn<>0 THEN
' Finish here
ELSE
showmessage("EndDocPrinter failed")
END IF
ELSE
showmessage("StartDocPrinter failed")
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Print_Graphics(useOutputFile AS BYTE)
IF prt_opened=1 THEN

' Allocate memory for the DocInfo structure.
FLong=GlobalAlloc(GMEM_FIXED OR GMEM_ZEROINIT, 20)
IF FLong<>0 THEN
FInt=GlobalLock(FLong)
IF FInt<>0 THEN
FLock=FInt

' Initialize the DocInfo Structure.
FFour=20
CopyMemory FInt, VarPtr(FFour), 4
FFour=VarPtr(emf_Title$)
CopyMemory FInt+4, VarPtr(FFour), 4
IF useOutputFile=0 THEN
output_File$=""
END IF
FFour=VarPtr(output_File$)
CopyMemory FInt+8, VarPtr(FFour), 4
FFour=VarPtr(emf$)
CopyMemory FInt+12, VarPtr(FFour), 4
FFour=0
CopyMemory FInt+16, VarPtr(FFour), 4

' Setup the Documentation Page.
jobID=StartDoc(prt_DC, FInt)
IF jobID>0 THEN

' Everything between StartPage and EndPage is one page. If you want
' to draw on another page (the next page) you must do another
' StartPage and EndPage after this one.

rtn=StartPage(prt_DC)
IF rtn>0 THEN

' -------------- Information which you can Get and/or Set ------------

' These calls are to do with the DC. Things such as Colour, Modes,
' Text, etc. Similar calls are made within this Print_Graphics sub,
' that create Brushes, Pens, BitMap, etc.

'Get_GraphicsMode
'Get_MapMode
'Get_TextColour
'Get_TextAlignment
'Get_TextSpacing
'Get_BGColour
'Get_BGMode

'Set_GraphicsMode(GM_ADVANCED)
'Set_MapMode(MM_TEXT)
'Set_MapperFlags(&H00000000)
'Set_TextColour(&H00000000)
'Set_TextAlignment(TA_LEFT OR TA_TOP OR TA_UPDATECP)
'Set_BGColour(&H00000001)
'Set_BGMode(TRANSPARENT)

'Set_TextSpacing(??) <--- logicalunits.

' ------------------------------ Arc ---------------------------------

'Print_Arc(0, 50, 200, 150, 200, 100, 0, 100)
'Print_ArcTo(0, 50, 200, 150, 200, 100, 0, 100) ' windows NT only.
'Print_AngleArc(100, 150, 50, 0, 180) ' windows NT only.

' -------------------------- Chord Printing ---------------------------

'Print_Chord(0, 0, 100, 100, 50, 50, 50, 50)

' -------------------------- Draw Edge -------------------------------

' DrawEdge() is windows 95 and NT only.
'Print_Edge(0, 0, 100, 100, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMRIGHT OR BF_RECT)

' ---------------------------- Frame Rectangle -----------------------

' This call set the DC`s Brush to Solid, Prints a FrameRectangle and
' then restores the Old Brush. &H00000000 = Colour.

'Set_NewSBrush(&H00000000)
'Print_FrameRectangle(0, 0, 100, 100, sbrush)
'Restore_OldSBrush

' --------------------------- PolyBezierTo ----------------------------

' This calls gets a Stock Object (here a Pen), Prints a PolyBezier and
' then restores the Old Stock Object.

'Print_MoveToEx(0, 0)
'Set_NewSObject(BLACK_PEN)
curves(0)=125
curves(1)=75
curves(2)=150
curves(3)=125
curves(4)=175
curves(5)=100
curves(6)=225
curves(7)=50
curves(8)=300
curves(9)=150
curves(10)=250
curves(11)=200
'Print_PolyBezierTo(6)
'Restore_OldSObject

' ---------------------------- FillRect -------------------------------

' This calls sets the Brush to Hatched (Diagonal), Fills a Rectangle
' with the Hatched Brush (Pattern) and then restores the Old Brush.

'Set_NewHBrush(&H00000000, HS_FDIAGONAL)
'Print_FillRect(0, 0, 120, 120)
'Restore_OldHBrush

' This calls sets the Brush to Hatched (Diagonal), Fills a Rectangle
' with the Hatched Brush (Pattern) and then restores the Old Brush.

' There are two things to note here. 1 Always restore your old brushes,
' etc. And 2. The pre-defined (Hatched) Pattern. Both are Diagonal, but
' in two different directions.

'Set_NewHBrush(&H00000000, HS_BDIAGONAL)
'Print_FillRect(100, 100, 220, 220)
'Restore_OldHBrush

' ------------------------------ Lines --------------------------------

' This call sets the (Solid) Pen to a thickness of 5, draws Lines and
' then Restores the Old Pen.

'Set_NewPen(5, &H00000000)

'Print_LineTo(100, 0)   ' draw from current graphic cursor position (0,0)
                       ' to 100 across, 0 down.
'Print_LineTo(100, 100) ' draw from (above position) 100,0 to 100 across
                       ' 100 down. -----¬
                       '                 |
                       '                 |
                       
' draw a pair of steps maybe?!!! Each point represents a x and y co-ord.
points(0)=0     ' point 1
points(1)=0
points(2)=0     ' point 2
points(3)=100
points(4)=100   ' point 3
points(5)=100
points(6)=100   ' point 4
points(7)=200
points(8)=200   ' point 5
points(9)=200
'Print_PolyLine(5)  ' Doesn`t update the current graphic cursor position.
'Print_PolyLineTo(5) ' but this does!!!

'Restore_OldPen

' |
' |
' |------¬
'         |
'         |
'         --------

' Note. By doing lineto() and polyline() etc together the cursor position
' may cut across your page, to get back to its original place etc. This
' is normal (Anyone who owned a BBC Micro with Turtle will know this). It
' is not this program. The trick, in those days, was to set the Pen
' Colour to white (the colour of your Paper). Reset the graphic cursor
' and then set the Pen Colour back to black or whatever. Laziness has
' forbid me to try this! (my Epson RX-80 might have an heart attack
' if I push it too much). The Epson RX-80 is an old B/W 9 Pin Dot Matrix
' for those who don`t know - Alright for printing Bills and Code though!

' -------------------- Ellipse, Rectangle and RoundRect ---------------

' This call sets the (Solid) Pen to a thickness of 5, draws an Ellipse,
' draws a Round Rectangle within a normal Rectangle and then Restores
' the Old Pen.

' This call also shows Abort_Document. If you use this (anywhere) then
' EndDoc and EndPage naturally give a failed message/return. This is
' normal.

'Set_NewPen(5, &H00000000)

'Print_Ellipse(20, 0, 100, 100)

' STOP this document from Printing. Note. By the time the Ellipse
' command has begun the Abort_Document command has STOPPED the document.
' Nice and Fast!! Remember. The printer is a seperate task so the
' Abort_Document command will execute next (i.e Abort_Document will not
' and does not wait for Print_Ellipse to finish).
'
'Abort_Document

'Print_Rectangle(440, 200, 100, 100)
'Print_RoundRect(360, 200, 100, 100, 100, 100)

'Restore_OldPen

' ----------------------- BitMap Brush (Pattern------------------------

' This call draws two BitMap Patterned Rectangles. It shows how easy
' it is to create a BitMap.

' Set the bitmap`s pattern.
bm_bitsArray(0)=&HFFFFFFFF
bm_bitsArray(1)=&HFFFFFFFF
bm_bitsArray(2)=&H00000000
bm_bitsArray(3)=&H00000000
bm_bitsArray(4)=&H00000000
bm_bitsArray(5)=&H00000000
bm_bitsArray(6)=&HFFFFFFFF
bm_bitsArray(7)=&HFFFFFFFF
'Set_NewPBrush(8, 8, 1, 1)       ' put the bitmap pattern into the DC.
'Print_Rectangle(0, 0, 100, 100) ' Draw a Rectangle with bitmap pattern.

'Print_FrameRectangle(0, 0, 100, 100, pbrush) ' dont appear to work?
'Restore_OldPBrush

' Change the bitmap`s pattern.
bm_bitsArray(0)=&HF000000F
bm_bitsArray(1)=&HF000000F
bm_bitsArray(2)=&HF000000F
bm_bitsArray(3)=&HF000000F
bm_bitsArray(4)=&HF000000F
bm_bitsArray(5)=&HF000000F
bm_bitsArray(6)=&HF000000F
bm_bitsArray(7)=&HF000000F
'Set_NewPBrush(8, 8, 1, 1)         ' put the bitmap pattern into the DC.
'Print_Rectangle(0, 120, 100, 220) ' Draw a Rectangle with bitmap pattern.
'Restore_OldPBrush

' ---------------------------- BitMap ----------------------------------

' This call prints part of the DeskTop`s Bitmap to the Printer. It
' shows BitBlt(), PatBlt() and StretchBlt() in action.

rtn=GetDeviceCaps(prt_DC, RASTERCAPS)
IF rtn<>0 THEN
' Here you should check wether or not your Printer supports bitmap etc,
' but I haven`t because I know my Epson RX-80 does (I checked the rtn
' value anyway just to make sure!). Not unless you have a really old
' printer (text only for example) would you need to check the rtn value.

bm_Window=GetDesktopWindow()
bm_DC=GetDC(bm_Window) 'bm_Window)
IF bm_DC<>0 THEN

'Get_StretchMode
Set_StretchMode(BLACKONWHITE)

' Do a straight copy.
'Blit_BitMap(0, 0, 300, 200, bm_DC, 0, 0, SRCCOPY)

' Stretch the bitmap.
'Stretch_BitMap(0, 0, 400, 400, bm_DC, 0, 0, 200, 200, SRCCOPY)

' Shrink the bitmap.
'Stretch_BitMap(0, 0, 400, 300, bm_DC, 0, 0, 800, 600, SRCCOPY)

' Change the bitmap`s pattern.
bm_bitsArray(0)=&HF000000F
bm_bitsArray(1)=&HFFFFFFFF
bm_bitsArray(2)=&HF000000F
bm_bitsArray(3)=&HF000000F
bm_bitsArray(4)=&HFFFFFFFF
bm_bitsArray(5)=&HF000000F
bm_bitsArray(6)=&HF000000F
bm_bitsArray(7)=&HFFFFFFFF
'Set_NewPBrush(8, 8, 1, 1)         ' put the bitmap pattern into the DC.
'Pattern_BitMap(0, 0, 100, 100, PATCOPY)
'Restore_OldPBrush

rtn=ReleaseDC(bm_Window, bm_DC)
IF rtn<>0 THEN

ELSE
showmessage("ReleaseDC failed")
END IF
ELSE
showmessage("GetDC failed")
END IF
ELSE
showmessage("GetDeviceCaps failed")
END IF

rtn=EndPage(prt_DC)
IF rtn>0 THEN

ELSE
showmessage("EndPage failed")
END IF
ELSE
showmessage("StartPage failed")
END IF

' Put another StartPage and EndPage here if you want to print another
' page.

rtn=EndDoc(prt_DC)
IF rtn>0 THEN
' Finish Here
ELSE
showmessage("EndDoc failed")
END IF
ELSE
showmessage("StartDoc failed")
END IF
UnLock_DefaultMemory
END IF
Free_DefaultMemory
END IF
END IF
END SUB

SUB Close_Printer
IF prt_opened=1 THEN
rtn=ClosePrinter(prt_Handle)
IF rtn=1 THEN
prt_opened=0
prt_error=0
ELSE
prt_error=1
ShowMessage("Printer - Not Closed")
END IF
END IF
END SUB

SUB Delete_DC
IF prt_DC<>0 THEN
rtn=DeleteDC(prt_DC)
IF rtn=1 THEN
prt_DC=0
ELSE
ShowMessage("DC - Not Deleted")
END IF
END IF
END SUB

' Just remove the apostrophe for the function you want to use below.

' --------------------- Printer Setup Calls ---------------------------

'Enum_Ports("", 2)
'Enum_Drivers("", 2)
'Enum_Printers(PRINTER_ENUM_LOCAL, "", 5, ENUMERATE_PRINTERS, "", "")

' Change the Name field to your Printer`s Name.
' If your printer does not set the DEFAULT attribute upon calling
' Enum_Printers (perhaps because you have a Fax Printer attached)
' the name in the name field will act as a default printer name.
' This is so your computer is less likely to report an error and/or
' Crash, etc.
'
'Enum_Printers(PRINTER_ENUM_LOCAL, "", 5, ENUMERATE_DEFAULT_PRINTER, "Epson RX80", "LPT1:")

' Windows 2000 Pro:  I have used RapidQ`s own Printer.Printers(Number)
'                    array for the Printer Name, below. You should
'                    really search the array before calling
'                    Open_Printer() to get the correct array (printer)
'                    number.
'
prt_Name$=Printer.Printers(1) ' Fax is 0.

' So to clarify the above said. Win98/SE users need to Enum_Printers()
' from above - that`s it. Win2000Pro users do NOT use Enum_Printers().
' They use prt_Name$=Printer.Printers(printer_number) instead.
'
' The differences are to do with the way the pointers work in RapidQ.
' Also because in win98SE Printer.Printers() equals "Epson RX80 on LPT1:"
' (with my Printer for example) but in win2000pro printer.Printers()
' equals "Epson RX80". So it`s up to you which way you get your printer`s
' name in win98SE - trim Printer.Printers() or use Enum_Printers().
'
Open_Printer()
Create_DC()

'Get_DevMode
'Show_DevMode

' Get_Driver is the same as Enum_Drivers except it enumerates the
' currently opened printer (printer-driver), specified by prt_Handle.
'
'Get_Driver("", 2)

' Although you do not need to call this for general Printing, it is a
' good idea to call it - just in case other functions need its data.
' It gets the Printer_Info_2 structure.
'Get_PI2
'Show_PI2

'Get_Jobs(0, 1) ' If you need to use Get_Jobs, call Get_PI2 first.
'Show_Jobs
'Free_jobsMemory

'Copy_DevMode(DDM_COPYTO_PI2DM) ' Copy default DevMode to PI2->DevMode
'Set_Printer                    ' Globally tell windows of the copy (new
                               ' DevMode settings).
'Show_PI2                      ' Show the change worked!


' ----------------- Print Graphics (BitMap, Shapes, etc) ---------------

' This sub has many examples for you to see.
'
'Print_Graphics(DATA_TO_PRINTER)

' --------------- Print TEXT (with optional specified FONT) ------------

' see the Print_Text sub for more information.
'
'Print_Text(DATA_TO_PRINTER)

' -------------------------- Print a Document -------------------------

' This needs the file: C:\My Documents\Test.txt
'
'Print_Document(DATA_TO_PRINTER)

' ------------------------- Print a RAW Buffer -----------------------

' This sub also shows how to getjob() and setjob().
'
'Print_RawBuffer(DATA_TO_PRINTER)

' ------------------------- Device Capabilities ----------------------

' These calls get most of the, important, device capabilities.
' You would typically use these to check/find out what your or
' another machine`s printer is capable of. There are plenty of
' useful things here. BINS, DUPLEX, COPIES etc. Read win32api manual
' or something for more specific information.

'Get_DCVersion
'Get_DCDriver
'Get_DCSize
'Get_DCExtra
'Get_DCFields
'Get_DCOrientation
'Get_DCCopies
'Get_DCDuplex
'Get_DCEmf
'Get_DCDataType
'Get_DCBins
'Get_DCBinAdjust
'Get_DCBinNames
'Get_DCPapers
'Get_DCPaperSize
'Get_DCMinPaperSize
'Get_DCMaxPaperSize
'Get_DCPaperNames
'Get_DCResolutions
'Get_DCFontOPtions

' ---------------------------- Set Printer ----------------------------

' A demo to show SetPrinter() and PRINTER_INFO_2 working together.
' ConfigurePort is usually pointing to a normal string (i.e prt_Port$)
' but here I have changed it to look at PRINTER_INFO_2->PORTNAME (which
' is a pointer to a string).
'
' Note: Do not just change the PRINTER_INFO_2->PORTNAME element and
' then call ConfigurePort(). This will only allow you to configure
' the port but not affect/change the printer`s port. To affect/change
' the printer`s port aswell you should call SetPrinter().

' TECHNICAL NOTES (Below):
'
' pi2_Default+12 is storing a LONG value. That LONG value is the address
' of (pointer to) the PortName string. It is not the string itself.
' Therefore. CopyMemory() is copying the LONG value into the variable
' FAdr. You need CopyMemory() as FAdr=pi2_Default+12 won`t work, simply
' because that would be copying the value of pi2_Default+12 itself into
' the variable FAdr and not the Pointer pi2_Default+12 is storing.
'
' The second CopyMemory() copies the string "COM1:"+0 into the Pointer
' (Address) which FAdr is storing (pointing to). As FAdr is pointing
' to the place (Address) where pi2->PortName lives (pi2_Default+12)
' I am poking pi2_PortName with a new string ("COM1:"+0 - Instead of
' "LPT1:"+0).
'
' As I have now changed a field of pi2 (pi2->PortName) I SetPrinter()
' those changes - Globally telling the Printer Driver that the printer
' port is now COM1: and no longer LPT1:
'
' NOTE: SetPrinter() returns an error of 0 (NO_ERROR) for COM1: as it
'       knows COM1: is not a Printer Port!!

'CopyMemory VarPtr(FAdr), pi2_Default+12, 4
'stg$="COM1:"+CHR$(0)
'CopyMemory FAdr, VarPtr(stg$), 6
'Set_Printer
'Configure_Port(0, FAdr)

' -------- Set Default DevMode and/or PI2 and/or PI2-->DevMode --------

' Note: Not all printers support everything below (Consult your printer
' manual).

' DEVMODE.
'---------

'Set_Orientation(DMORIENT_LANDSCAPE, SET_DDM)
'Set_PaperSize(DMPAPER_USER, SET_DDM)
'Set_PaperWidth(500, SET_DDM)         ' DMPAPER_USER must be used if you
'Set_PaperLength(300, SET_DDM)        ' want to use paper width/length.
'Set_Scale(50, SET_DDM)
'Set_Copies(3, SET_DDM)
'Set_PaperFeed(DMBIN_ENVELOPE, SET_DDM)
'Set_PrintQuality(DMRES_HIGH, SET_DDM)  ' A positive number = X DPI.
'Set_ColourMode(DMCOLOR_COLOR, SET_DDM)
'Set_Duplex(DMDUP_SIMPLEX, SET_DDM)
'Set_PrintQuality(240, SET_DDM)          ' A positive number = X DPI.
'Set_YResolution(144, SET_DDM)           ' The Y DPI (Dots Per Inch).
'Set_TTOption(DMTT_BITMAP, SET_DDM)
'Set_Collate(DMCOLLATE_FALSE, SET_DDM)
'Set_PixelsPerLogicalInch(0, SET_DDM)
'Set_ICMMethod(DMICMMETHOD_NONE, SET_DDM)
'Set_ICMIntent(DMICM_SATURATE, SET_DDM)
'Set_MediaType(DMMEDIA_STANDARD, SET_DDM)
'Set_DitherType(DMDITHER_COARSE, SET_DDM)

' PI2
' ---

' Only use these if you know what you are doing.
'Set_ServerName("")
'Set_PrinterName("Epson RX-80")
'Set_ShareName("")
'Set_PortName("LPT1:")
'Set_DriverName("Epson RX-80")
'Set_Location("")
'Set_SeperatorFile("")
'Set_PrintProcessor("WinPrint")
'Set_DataType("RAW")
'Set_Parameters("")

' When you are ready to set any one/all of the above commands simply
' call Set_Printer.
'Copy_DevMode(DDM_COPYTO_PI2DM) ' Copy Default DevMode to PI2-->DevMode.
'Set_Printer                    ' Set all the PI2 fields, including
                               ' PI2-->DevMode fields.

' --------------------- Printer Setup Requesters ---------------------

'PageSetupDialog
'Print_Dialog
'Properties_Window
'Advanced_Document_Properties
'Document_Properties
'Configure_Port(0, VarPtr(prt_Port$))

' ---------------------------- Cleanup Calls --------------------------

' These cleanup calls take care of their own error checking, etc.

Delete_DC
Close_Printer
'Free_pdMemory
'Free_dmMemory
'Free_pi2Memory

' ------------------------------- THE END :( --------------------------
