Introduction
Free for PERSONAL and COMMERCIAL use
Source Code
The SolidWidgets library includes functionality to create, preview, and print barcodes and mailing labels. It has support for most of the popular AVERY labels and barcode formats.
I found this functionality extremely easy to use, and with full support for various barcode types, in addition to all the other functionality available in this library, it makes it a very attractive
alternative to many of the popular UI and other types of libraries that are out there. There are
two components that are readily available for use in your application, which include a component that can display
a single barcode, and another that displays various AVERY label formats, which can be configured to display either a barcode, or text information such as addresses, etc.
Using the SolidWidgets Barcode and Mailing label components
Mailing labels control (swMailingLabels
):
swMailingLabels m_mailingLabels;
m_mailingLabels.addAddressLabel(L"Address Label",L"Address Line 2",L"Address Line 3");
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_DATAMATRIX);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_QRCODE);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_128A);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_128B);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_128C);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_39);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_93);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_EAN8);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_EAN13);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_UPCA);
m_mailingLabels.addBarcodeLabel(L"123456",BARCODEFORMAT_UPCE);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_CODABAR);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_I25);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_MSI);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_PLESSEY_UK);
The following is a complete example that shows how to add the mailing labels component to a dialog box:
#pragma once
#include <swDialog.h>
#include <swMailingLabels.h>
#include <swButton.h>
class BarcodesAndLabels: public swDialog
{
swMailingLabels m_mailingLabels;
swButton m_okBtn,m_cancelBtn;
public:
void windowOpening();
void windowOpened();
BOOL windowClosing();
void windowClosed();
void actionPerformed(long sourceId,long eventId,const swString& eventName);
};
#include "BarcodesAndLabels.h"
void BarcodesAndLabels::windowOpening()
{
setSize(700,600);
swPanel *contentPane = getContentPane();
if(contentPane!=NULL)
{
contentPane->setMargins(10,10,10,10);
contentPane->addRow(); contentPane->addRow(10);
contentPane->addRow(25);
contentPane->addColumn();
contentPane->addColumn(100); contentPane->addColumn(100);
contentPane->addChild(&m_mailingLabels,0,0,3,1);
contentPane->addChild(&m_okBtn,1,2,1,1);
contentPane->addChild(&m_cancelBtn,2,2,1,1);
}
m_mailingLabels.addAddressLabel(L"Address Label",L"Address Line 2",L"Address Line 3");
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_DATAMATRIX);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_QRCODE);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_128A);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_128B);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_128C);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_39);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_93);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_EAN8);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_EAN13);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_UPCA);
m_mailingLabels.addBarcodeLabel(L"123456",BARCODEFORMAT_UPCE);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_CODABAR);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_I25);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_MSI);
m_mailingLabels.addBarcodeLabel(L"1234567890",BARCODEFORMAT_PLESSEY_UK);
m_okBtn.setActionListener(this);
m_okBtn.setText(L"OK");
m_cancelBtn.setActionListener(this);
m_cancelBtn.setText(L"Cancel");
}
void BarcodesAndLabels::windowOpened()
{
}
BOOL BarcodesAndLabels::windowClosing()
{
return TRUE;
}
void BarcodesAndLabels::windowClosed()
{
}
void BarcodesAndLabels::actionPerformed(long sourceId,long eventId,const swString& eventName)
{
if(sourceId == m_okBtn.getID())
{
dispose(swOK);
}
else if(sourceId == m_cancelBtn.getID())
{
dispose(swCANCEL);
}
}
Here is what the component looks like:
If the user right-clicks on the control, a menu will be presented to allow the user to change the labels format, and/or print the labels as shown below:
Barcode control (swBarcodeCtrl
):
swBarcodeCtrl m_barcodeCtrl;
m_barcodeCtrl.setText(L"1234567890");
m_barcodeCtrl.setFormat(BARCODEFORMAT_QRCODE);
The following is a complete example that shows how to add the barcode control to a dialog box:
#pragma once
#include <swDialog.h>
#include <swBarcodeCtrl.h>
#include <swButton.h>
class BarcodesAndLabels: public swDialog
{
swBarcodeCtrl m_barcode;
swButton m_okBtn,m_cancelBtn;
public:
void windowOpening();
void windowOpened();
BOOL windowClosing();
void windowClosed();
void actionPerformed(long sourceId,long eventId,const swString& eventName);
};
#include "BarcodesAndLabels.h"
void BarcodesAndLabels::windowOpening()
{
setSize(700,600);
swPanel *contentPane = getContentPane();
if(contentPane!=NULL)
{
contentPane->setMargins(10,10,10,10);
contentPane->addRow(); contentPane->addRow(10);
contentPane->addRow(25);
contentPane->addColumn();
contentPane->addColumn(100); contentPane->addColumn(100);
contentPane->addChild(&m_barcode,0,0,3,1);
contentPane->addChild(&m_okBtn,1,2,1,1);
contentPane->addChild(&m_cancelBtn,2,2,1,1);
}
m_barcode.setText(L"1234567890");
m_barcode.setFormat(BARCODEFORMAT_QRCODE);
m_okBtn.setActionListener(this);
m_okBtn.setText(L"OK");
m_cancelBtn.setActionListener(this);
m_cancelBtn.setText(L"Cancel");
}
void BarcodesAndLabels::windowOpened()
{
}
BOOL BarcodesAndLabels::windowClosing()
{
return TRUE;
}
void BarcodesAndLabels::windowClosed()
{
}
void BarcodesAndLabels::actionPerformed(long sourceId,long eventId,const swString& eventName)
{
if(sourceId == m_okBtn.getID())
{
dispose(swOK);
}
else if(sourceId == m_cancelBtn.getID())
{
dispose(swCANCEL);
}
}
Here is what the component looks like:
Points of interest
This functionality can be very handy if someone needs to provide barcode and mailing label printing and preview functionality in their program. This functionality
is pretty difficult to implement from scratch, but fortunately, the SolidWidgets library already includes the functionality so you won't need to implement it on your own.
Conclusion
I hope this tutorial helps someone who needs to implement such functionality. Best of luck!
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.