The purpose of this tutorial is to provide you with a quick and easy way to generate a Barcode program. Perform the following steps to create and run a program that reads barcodes.
1. |
Create a new directory in the Examples\CDLL directory called BarcodeTutor. |
2. |
Copy everything in the SimpleLoad directory into the BarcodeTutor directory. |
3. |
Compile the project as it is and run SimpleLoad.exe to familiarize yourself with the basic program. |
4. |
In the Imports.cpp file, add the following lines: |
#if defined(WIN64)
#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltbar_x.lib")
#else
#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltbar_u.lib")
#endif // #if defined(WIN64)
5. |
Add the following line in StdAfx.h in the BarcodeTutor directory: |
#include "..\..\..\include\ltbar.h"
6. |
Define the following global variables in Ezfunc.h in the BarcodeTutor directory: |
pBARCODEDATA pBarCodes;
Also, add the following defines:
#define IDM_READ_BARCODES 200
7. | Add the following statements in the WinMain function as follows: | |
a. | Add the following before calling InitInstance() statement |
if (L_BarCodeInit(BARCODES_1D) != SUCCESS)
return 0;
pBarCodes = NULL;
|
b. |
Add the following after the GetMessage() loop |
if (pBarCodes)
L_BarCodeFree(&pBarCodes);
L_BarCodeExit();
8. |
Edit EZFUNC.RC file in the BarcodeTutor directory and add the following lines: |
#include "EZFUNC.H"
MAIN_MENU MENU
BEGIN
MENUITEM "Read Barcodes" IDM_READ_BARCODES
END
9. |
In InitApplication, change the line: |
wcWindowClass.lpszMenuName = NULL;
To:
wcWindowClass.lpszMenuName = TEXT("MAIN_MENU");
10. |
In MainWndProc, change the line: |
Demos_CombinePath(szImagesDirectory, L_TEXT("Image1.cmp"), szFilename, _countof(szFilename));
To:
Demos_CombinePath(szImagesDirectory, L_TEXT("barcode1.tif"), szFilename, _countof(szFilename));
11. |
In InitInstance, change the menu parameter in CreateWindow from NULL to LoadMenu(hInstance, MAKEINTRESOURCE("MAIN_MENU")) |
12. |
In the MainWndProc procedure, add the following code to the switch statement: |
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_READ_BARCODES:
{
BARCODE1D Bar1d;
memset(&Bar1d, 0, sizeof(BARCODE1D));
Bar1d.uStructSize = sizeof(BARCODE1D);
Bar1d.bErrorCheck = TRUE;
Bar1d.nGranularity = 9;
Bar1d.nDirection = BARCODE_DIR_HORIZONTAL;
BARCODECOLOR BarColor;
memset(&BarColor, 0, sizeof(BARCODECOLOR));
BarColor.uStructSize = sizeof(BARCODECOLOR);
BarColor.dwColorBar = RGB(0, 0, 0);
BarColor.dwColorSpace = RGB(255, 255, 255);
// The Read method will search for all linear barcodes in the whole bitmap
L_INT nRet = L_BarCodeRead(&LeadBitmap,
NULL,
BARCODE_1D_READ_ANYTYPE,
BARCODE_SCANLINES_PER_PIXELS,
BARCODE_BLOCK_SEARCH,
0, &Bar1d, NULL, &BarColor,
&pBarCodes, sizeof(BARCODEDATA));
if (nRet == SUCCESS)
{
L_INT nCount = pBarCodes->nTotalCount;
L_CHAR szBuffer[MAX_PATH];
for (L_INT i = 0; i<ncount; i++)
{
memset(szbuffer, 0, max_path);
wsprintfa(szbuffer,
"Barcode # %d\nData %s\nLeft %d\nTop %d\nRight %d\nBottom %d\n",
i,
pbarcodes[i].pszbarcodedata,
pbarcodes[i].rcbarlocation.left,
pbarcodes[i].rcbarlocation.top,
pbarcodes[i].rcbarlocation.right,
pbarcodes[i].rcbarlocation.bottom);
messageboxa(hwnd, szbuffer, ("barcode data"), mb_ok);
}
}
else
messagebox(hwnd, text("failure during reading linear barcodes"), text("error!"), mb_ok);
}
break;
}
return 0;
13. |
On the Build menu, select Build SimpleLoad.exe. |
14. |
On the Build menu, select Execute SimpleLoad.exe. |
15. |
Save this project to use for testing other code samples. |