Barcode Generation (FWER_BarCode)
Fuente: source/classes/fwbarcod.prg, source/function/fwzebra.prg
FWER_BarCode is FiveWin's built-in barcode rendering engine. It supports 17 barcode symbologies
through a native GDI engine, with optional fallback to the hbzebra library for 2D codes
(QR, DataMatrix, PDF417). Barcodes can be rendered on windows, dialogs, printers, and PDF output.
Symbology Reference
| nBCodeType | Symbology | Description |
|---|---|---|
| 1 | Code 39 | Standard Code 39 (3-of-9) alphanumeric |
| 2 | Code 39 + check | Code 39 with mandatory check digit |
| 3 | Code 128 auto | Code 128 with automatic mode selection (A/B/C) |
| 4 | Code 128 A | Code 128 mode A (uppercase, control chars) |
| 5 | Code 128 B | Code 128 mode B (full ASCII) |
| 6 | Code 128 C | Code 128 mode C (numeric pairs, highest density) |
| 7 | EAN-8 | EAN-8 (8-digit product code) |
| 8 | EAN-13 | EAN-13 (13-digit product code, most common retail) |
| 9 | UPC-A | UPC-A (12-digit US product code) |
| 10 | Codabar | Codabar (libraries, blood banks, FedEx) |
| 11 | Supplement 5 | 5-digit supplement for EAN/UPC |
| 12 | Industrial 2 of 5 | Industrial 2 of 5 numeric |
| 13 | Industrial 2 of 5 + check | Industrial 2 of 5 with check digit |
| 14 | Interleaved 2 of 5 | Interleaved 2 of 5 (high-density numeric) |
| 15 | Interleaved 2 of 5 + check | Interleaved 2 of 5 with check digit |
| 16 | Matrix 2 of 5 | Matrix 2 of 5 numeric |
| 17 | Matrix 2 of 5 + check | Matrix 2 of 5 with check digit |
DATA Members
| DATA | Default | Description |
|---|---|---|
hDC | -- | Device context handle (window, dialog, printer) |
cText | "" | Barcode text to encode |
nTop, nLeft | -- | Position coordinates |
nWidth, nHeight | 200, 20 | Barcode dimensions |
nColText | 0 (black) | Bar (pin) color |
nColPane | RGB(255,255,255) | Background color |
lHorizontal | .T. | Horizontal (.T.) or vertical (.F.) orientation |
lTransparent | .F. | Transparent background |
nPinWidth | -- | Individual bar (pin) width in pixels |
Methods
| Method | Description |
|---|---|
New( hDC, cText, nTop, nLeft, nW, nH, nType, nClrT, nClrP, lHorz, lTransp, nPinW, nFlags, lPrinter ) | Create a barcode object. Accepts numeric type (1-17) or string alias ("EAN13", "128", "39", etc.) |
ShowBarcode() | Render the barcode to the device context using the configured parameters |
CreateBarcode( cCode ) | Generate the bar pattern string for a given code |
CheckDigit() | Compute and append the appropriate check digit for the current symbology |
Free Funciones
FW_SayBarCode()
Direct barcode rendering without creating an object instance:
FW_SayBarCode( oWnd, cText, aRect, cType, nClrT, nClrB, lVert, lTransp )
Parameters: oWnd (window/dialog/printer), cText (data to encode), aRect (array { nTop, nLeft, nBottom, nRight }), cType (symbology string), nClrT/nClrB (fore/back colors), lVert (vertical orientation), lTransp (transparent background).
FW_BarCodeBmp()
Generates a standalone bitmap handle of the barcode for use in reports or image controls.
Example: EAN-13 on Printer
#include "FiveWin.ch"
FUNCTION PrintBarcode()
LOCAL oPrn, nRow := 2.0 // cm from top
PRINT oPrn NAME "Barcode Test"
PAGE
oPrn:Say( nRow, 1.0, "Product Barcode:" )
nRow += 0.8
// Method 1: Using FWER_BarCode directly
FWER_BarCode():New( oPrn:hDC, "5901234567890", ;
oPrn:CmToPix( nRow ), // nTop
oPrn:CmToPix( 1.0 ), // nLeft
oPrn:CmToPix( 5.0 ), // nWidth
oPrn:CmToPix( 2.5 ), // nHeight
8, 0, 16777215, .T., .F. ):ShowBarcode()
// Method 2: Using FW_SayBarCode convenience function
nRow += 3.0
FW_SayBarCode( oPrn, "5901234567890", ;
{ oPrn:CmToPix( nRow ), oPrn:CmToPix( 1.0 ), ;
oPrn:CmToPix( nRow + 2.5 ), oPrn:CmToPix( 6.0 ) }, ;
"EAN13", 0, 16777215 )
ENDPAGE
ENDPRINT
RETURN NIL
Notes
- String type names are case-insensitive and normalized by removing
"CODE"prefix, spaces, underscores, and hyphens. Example:"CODE128","code 128", and"128"all resolve to Code 128 auto. - When the
hbzebralibrary is linked, 2D symbologies (QR, DataMatrix, PDF417) are automatically routed through the Zebra engine, which also supports direct PDF output viaTPDFobject detection. - Use
FWER_BarCode:lUseZebraLib := .T.at class level to force the Zebra engine for all supported symbologies. - Printer output uses GDI
FillRectfor bars andFillRectExfor background, ensuring correct scaling on high-DPI devices.