Barcode EAN 8 and 13 Source Code

The class that I’m going to describe is the one we use in RGPSoft to create and print barcodes, in particular for the EAN 13 and EAN 8, the most commonly used. This class written in C++ was built with MFC, because the base class is a CStatic, but obviously a good programmer will certainly turn for the SDK for Windows, or Linux or Visual Basic or PHP, or Java, or C# or create a ActiveX component with ATL or MFC. Let’s say that you want to use MFC, you have to enter into a dialog, for example, a static control and then go through DoDataExchange subclassing of the control. To insert the code within the control you must use the SetCodix (bar code) will be drawn when the window will show the design of the bar code, the same attention as it is the control that automatically calculates the check code and then the final code to enter letters will be respectively 12 and 7 points.

class CBarCodeWnd : public CStatic
{
	DECLARE_DYNAMIC(CBarCodeWnd)

public:
	CBarCodeWnd();
	virtual ~CBarCodeWnd();

	char CharControl(CString strValue);
	bool SetCodix(CString strValue);
	bool SetStep(short nVal);
	void DrawNumber(CDC* pDC, CRect rc, wchar_t val);
	bool GetA(int number, int index);
	bool GetB(int number, int index);
	bool GetC(int number, int index);
	bool GetType(int number, int index);
protected:
	CString m_strCodix;
	short m_nStep;

protected:
	afx_msg void OnPaint();
	DECLARE_MESSAGE_MAP()
};

The complete source code of this control for draw barcode EAN 8 or 13 can be found in our download page.

This entry was posted in Programming and tagged , . Bookmark the permalink.