Click here to Skip to main content
15,881,687 members
Articles / Programming Languages / C++

SolidWidgets Barcodes and Labels Library

Rate me:
Please Sign up or sign in to vote.
3.91/5 (6 votes)
22 Jul 2012CPOL1 min read 24.1K   1.2K   26   5
The SolidWidgets library includes functionality to create, preview, and print barcodes and mailing labels.

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):

C++
// Declare an instance of swMailingLabels:
swMailingLabels m_mailingLabels;

// Add address and barcode labels
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);
//
// This component allows the user to right-click and change
// the mailing labels format. It automatically manages that so you do not have to
// provide that functionality yourself.
//

The following is a complete example that shows how to add the mailing labels component to a dialog box:

C++
// Header
#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);
};

// CPP file
#include "BarcodesAndLabels.h"

void BarcodesAndLabels::windowOpening()
{
    setSize(700,600);

    swPanel *contentPane = getContentPane();
    if(contentPane!=NULL)
    {
        contentPane->setMargins(10,10,10,10);

        contentPane->addRow(); // Mailing Labels Control
        contentPane->addRow(10);
        contentPane->addRow(25); // Buttons

        contentPane->addColumn();
        contentPane->addColumn(100); // OK Button
        contentPane->addColumn(100); // Cancel Button

        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:

Login

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:

Login

Barcode control (swBarcodeCtrl):

C++
// Declare an instance of swBarcodeCtrl:
swBarcodeCtrl m_barcodeCtrl;
// Set the barcode text
m_barcodeCtrl.setText(L"1234567890");
// Set the barcode type
m_barcodeCtrl.setFormat(BARCODEFORMAT_QRCODE);
// You can set the barcode format to any of the following: (These are all defined in swBarcodeCtrl.h)
/*
    BARCODEFORMAT_DATAMATRIX	1
    BARCODEFORMAT_QRCODE		2
    BARCODEFORMAT_128A			3
    BARCODEFORMAT_128B			4
    BARCODEFORMAT_128C			5
    BARCODEFORMAT_39			6
    BARCODEFORMAT_93			7
    BARCODEFORMAT_EAN8			8
    BARCODEFORMAT_EAN13			9
    BARCODEFORMAT_UPCA			10
    BARCODEFORMAT_UPCE			11
    BARCODEFORMAT_CODABAR		12
    BARCODEFORMAT_I25			13
    BARCODEFORMAT_MSI			14
    BARCODEFORMAT_PLESSEY_UK	15
*/

The following is a complete example that shows how to add the barcode control to a dialog box:

C++
// Header
#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);
};

// CPP file
#include "BarcodesAndLabels.h"

void BarcodesAndLabels::windowOpening()
{
    setSize(700,600);

    swPanel *contentPane = getContentPane();
    if(contentPane!=NULL)
    {
        contentPane->setMargins(10,10,10,10);

        contentPane->addRow(); // Barcode Control
        contentPane->addRow(10);
        contentPane->addRow(25); // Buttons

        contentPane->addColumn();
        contentPane->addColumn(100); // OK Button
        contentPane->addColumn(100); // Cancel Button

        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:

Login

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!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionIs SolidWidgets commercial library? Pin
Ігор Добродій30-Apr-16 12:26
Ігор Добродій30-Apr-16 12:26 
QuestionAdd Solid Widgets Library to .net Pin
ManojSridhar914-Dec-14 0:39
ManojSridhar914-Dec-14 0:39 
QuestionCode128 Pin
Taulie31-Aug-13 1:24
Taulie31-Aug-13 1:24 
Is switch between subset A,B or C in Code128 supported or can i print only one subset of Code128 at one time?
QuestionMissing code Pin
sisira22-Jul-12 4:31
sisira22-Jul-12 4:31 
AnswerRe: Missing code Pin
Jake Franta22-Jul-12 7:03
Jake Franta22-Jul-12 7:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.