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.

Define the following global IDs in Ezfunc.h in the BarcodeTutor directory:

 

#define IDM_FIND_DUPLICATE       202
 

 

3.

Edit EZFUNC.RC file in the BarcodeTutor directory and add the following lines:

 

MAIN_MENU   MENU

BEGIN

   ...

   ...
   MENUITEM "Find Duplicate"  IDM_FIND_DUPLICATE

END

 

4.

In the MainWndProc procedure, add the following code to the switch statement for WM_COMMAND:

      case IDM_FIND_DUPLICATE:
         {
            L_INT nDupIndex=0;

            L_TCHAR szBuffer[MAX_PATH];

            memset(szBuffer, 0, MAX_PATH);

 

            if (L_BarCodeIsDuplicated(&(pBarCodes[0])))

            {

               nDupIndex = L_BarCodeGetDuplicated(&(pBarCodes[0]));

               if (nDupIndex >= 0)

               {

                  // Print the first duplicated barcode data

                  wsprintf(szBuffer, TEXT("Data is %hs\nUnits %d\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n"),

                           pBarCodes[nDupIndex].pszBarCodeData,

                           pBarCodes[nDupIndex].nUnits,

                           pBarCodes[nDupIndex].rcBarLocation.left,

                           pBarCodes[nDupIndex].rcBarLocation.top,

                           abs(pBarCodes[nDupIndex].rcBarLocation.right - pBarCodes[nDupIndex].rcBarLocation.left),

                           abs(pBarCodes[nDupIndex].rcBarLocation.bottom - pBarCodes[nDupIndex].rcBarLocation.top));

 

                  MessageBox(hWnd, szBuffer, TEXT("BarCode Info."), MB_OK);

 

                  // find the next (second) duplicated barcode data

                  nDupIndex = L_BarCodeGetNextDuplicated(pBarCodes, nDupIndex);

                  if (nDupIndex >= 0)

                  {

                     wsprintf(szBuffer, TEXT("Data is %hs\nUnits %d\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n"),

                              pBarCodes[nDupIndex].pszBarCodeData,

                              pBarCodes[nDupIndex].nUnits,

                              pBarCodes[nDupIndex].rcBarLocation.left,

                              pBarCodes[nDupIndex].rcBarLocation.top,

                              abs(pBarCodes[nDupIndex].rcBarLocation.right - pBarCodes[nDupIndex].rcBarLocation.left),

                              abs(pBarCodes[nDupIndex].rcBarLocation.bottom - pBarCodes[nDupIndex].rcBarLocation.top));

 

                     MessageBox(hWnd, szBuffer, TEXT("BarCode Info."), MB_OK);

                  }

               }

 

               if (nDupIndex < 0)

               {

                  wsprintf(szBuffer, TEXT("An error occurred \nError Code = %d\n"), nDupIndex);

                  MessageBox(hWnd, szBuffer, TEXT("Notice!"), MB_OK);

               }

            }

            else

            {

               wsprintf(szBuffer, TEXT("This Barcode is not duplicated ..."));

               MessageBox(hWnd, szBuffer, TEXT("Notice!"), MB_OK);

            }
         }
         break;

 

5.

Build SimpleLoad.exe.

6.

Run SimpleLoad.exe.