Take the following steps to add code to the existing project that will let you to find duplicate barcodes:
Start with the program you created in Reading Barcodes.
Click the "Solution Explorer" tab.
Double-click the "BarcodeTutor" folder to open it.
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".
Now, drag and drop 1 button, and change its properties as follows:|
| Name | ID | Caption |
|---|---|---|
| Button4 | IDC_FIND_DUPLICATE | Find Duplicate |
From the View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_BARCODETUTOR_DIALOG".
Double click "the 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 datawsprintf(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 datanDupIndex = 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);}
Compile and test the program.