Available in LEADTOOLS Barcode Modules.
|
Finding Duplicate Barcodes
Take the following steps to add code to the existing project that will let you to find duplicate barcodes:
1. |
Start with the program you created in Reading Barcodes. |
||
2. |
Click on the "Solution Explorer" tab. |
||
3. |
Double-click the "BarcodeTutor" folder to open it. |
||
4. |
Double-click the "Resource Files" folder to open it. Then double click "BarcodeTutor.rc" file to open it, then double click "Dialog", and then double click "IDD_BARCODETUTOR_DIALOG" |
||
5. |
Now, drag and drop 1 button, and change its properties as follows: |
||
|
|
ID |
Caption |
|
Button4 |
IDC_FIND_DUPLICATE |
Find Duplicate |
6. |
From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_BARCODETUTOR_DIALOG" |
||
7. |
Double click on "Find Duplicate" button, and add the following code: |
L_INT nDupIndex=0;
L_TCHAR szBuffer[MAX_PATH];
memset(szBuffer, 0, MAX_PATH);
pBARCODEDATA pBarData = NULL;
if (m_Barcode.IsDuplicated(0))
{
nDupIndex = m_Barcode.GetFirstDuplicated(0);
if (nDupIndex >= 0)
{
pBarData = m_Barcode.GetBarCodeDataItem(nDupIndex);
// Print the first duplicated barcode data
wsprintf(szBuffer, TEXT("Data is %hs\nUnits %d\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n"),
pBarData->pszBarCodeData,
pBarData->nUnits,
pBarData->rcBarLocation.left,
pBarData->rcBarLocation.top,
abs(pBarData->rcBarLocation.right - pBarData->rcBarLocation.left),
abs(pBarData->rcBarLocation.bottom - pBarData->rcBarLocation.top));
AfxMessageBox(szBuffer);
// find the next (second) duplicated barcode data
nDupIndex = m_Barcode.GetNextDuplicated(nDupIndex);
if (nDupIndex >= 0)
{
pBarData = m_Barcode.GetBarCodeDataItem(nDupIndex);
wsprintf(szBuffer, TEXT("Data is %hs\nUnits %d\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n"),
pBarData->pszBarCodeData,
pBarData->nUnits,
pBarData->rcBarLocation.left,
pBarData->rcBarLocation.top,
abs(pBarData->rcBarLocation.right - pBarData->rcBarLocation.left),
abs(pBarData->rcBarLocation.bottom - pBarData->rcBarLocation.top));
AfxMessageBox(szBuffer);
}
}
if (nDupIndex < 0)
{
wsprintf(szBuffer, TEXT("An error occurred \nError Code = %d\n"), nDupIndex);
AfxMessageBox(szBuffer);
}
}
else
{
wsprintf(szBuffer, TEXT("This Barcode is not duplicated ..."));
AfxMessageBox(szBuffer);
}
8. |
Compile and test the program. |