Array for Bars and Spaces

A byte array is defined in BarcodeBase class as BYTE ia_Buf[4096];Each byte of the array represents a bar or space, bits of the byte are encoded in the format: [n/a][n/a][n/a][n/a][n/a][n/a][w-n][b-s] First 6 bits are not used.Last bit is flagged for bar or space.Last second bit is flagged for wide or narrow.

So, value of the byte means:

0x00 = a narrow space

0x01 = a narrow bar

0x02 = a wide space

0x03 = a wide bar

Note: Class BarcodeEan13 is special: Last third bit is used by the class to indicate if the bar (space) is longer than others.

Sample Program

The sample is a dialog based MFC program. The main dialog is in borderless style, when edit-box Move (refer to picture below) gets focus, user can use arrow keys of up, down, left and right to move main dialog. This feature allows you to compare barcode drawn on main dialog with other barcode programs easily. You also can use mouse to drag main dialog by clicking on it as clicking on caption of normal windows.

Controls

Buttons

OnTop/OnNormal: Set the program as top-most-window or not

Close: Close the program

Help: Display this HTML file

Print: Print barcode

Others

Style: Barcode styles or symbologies

Map: Map-mode used

Move: Move main dialog by arrow keys once it gets focus

Code: String to be encoded

X,Y,Height: For print positions, unit is in logic points

Pen width: Width of one bar or space

Please note:

Some MapModes (such as MM_HIENGLISH) cannot be displayed properly on screen, you have to test them by printing.

Disappointing

This sample and library file are my test program for barcode, which doesn't include second part: dynamical bitmap of barcode generated from encoding.

Why do I test barcode with bitmap? Here is the answer:As we know, there are three methods for printing:

By drawing such as LineTo()

By Bitmap such as BitBlt()

By fonts such as TextOut()

Barcode must be printed clearly with high qualities. The only way to print a good barcode is by fonts. If you try to use the code for commercial purposes, the result is very disappointing because this program does not use fonts.

This is my first article, currently upload files are OK, you can download them now.

Second part: Dynamical bitmapThe second part (Dynamical bitmap) has been deleted because I think readers like simple code.

If more than 5 readers ask for second part, I will modify the program and add dynamical-bitmap-barcode to it.

Be-careful code insideA byte array is defined this way in BarcodeBase class:BYTE ia_Buf[4096];So total number of bars and spaces of one barcode can be upto 4096 only.4096 is enough for barcode, but in case you need more, please simply use larger number for the array.Anyway, this piece of code is not good from programming tech view - as I said, this sample is my test program, it is good enough for tesing purposes.