Writing Barcodes

Take the following steps to add code to the existing project that will let you to write barcodes:

  1. Start with the program you created in Reading Barcodes.

  2. Click 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
    Button3 IDC_WRITE_BARCODE Write Barcode
  6. From the View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_BARCODETUTOR_DIALOG".

  7. Double click on "Write Barcode" button, and add the following code:

    BARCODE1D Bar1d;    
    memset(&Bar1d, 0, sizeof(BARCODE1D));    
    Bar1d.uStructSize = sizeof(BARCODE1D);    
    Bar1d.bErrorCheck = TRUE;    
    Bar1d.bOutShowText = TRUE;    
    BARCODEDATA BarData;    
    memset(&BarData, 0, sizeof(BARCODEDATA));    
    BarData.uStructSize = sizeof(BARCODEDATA);    
    BarData.nUnits = BARCODE_SCANLINES_PER_PIXELS;    
    SetRect(&BarData.rcBarLocation, 100, 100, 350, 200);    
    BarData.pszBarCodeData = "012345678901";   
    BarData.nSizeofBarCodeData = (L_INT)strlen(BarData.pszBarCodeData);    
    BarData.ulType = BARCODE_1D_EAN_13;    
    BARCODECOLOR BarColor;    
    memset(&BarColor, 0, sizeof(BARCODECOLOR));    
    BarColor.uStructSize = sizeof(BARCODECOLOR);    
    BarColor.dwColorBar = RGB(0, 0, 0);    
    BarColor.dwColorSpace = RGB(255, 255, 255);    
    m_Barcode.SetBitmap(&m_Bitmap);    
    L_INT nRet = m_Barcode.Write(&BarData, 0, &BarColor, &Bar1d, NULL, NULL, NULL, NULL);    
    if (nRet == SUCCESS)    
       AfxMessageBox(TEXT("Barcode written successfully"));   
    else   
       AfxMessageBox(TEXT("Failure during writing linear barcodes")); 

  8. Compile and test the program.

Help Version 20.0.2018.9.25
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Barcode C++ Class Library Help