Call default constructor first, then call following 2 functions:Parameters of above functions:
BOOL Encode39(const char*pszCodeIn);
void Draw39(HDC hDC,int iX,int iY0,int iY1,const COLORREF clrBar,const COLORREF clrSpace,const int iPenW);
pszCodeIn: string to be encoded, i.e. "1234567890"Sample program:
iX: start horizontal position to draw the barcode
iY0,iY1: start and end vertical positions to draw the barcode
clrBar, clrSpace: colors of bar and space
iPenW: width of pen to draw the barcode
The sample is a dialog based MFC program.
Main dialog is in borderless style, when edit-box Move (refer to picture bellow) 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.
Disappoint:
This sample and library file are my test program for barcode, which doesn't include second part: dynamical bitmap of barcode generated from encoding.
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 good barcode is by fonts.
If you try to use the code for commercial purposes, result is very disappointed because this program is not using fonts.
References