Take the following steps to add code to the existing project that will let you to write 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:
| Button | ID | Caption |
|---|---|---|
| Button3 | IDC_WRITE_BARCODE | Write Barcode |
From the View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_BARCODETUTOR_DIALOG".
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"));elseAfxMessageBox(TEXT("Failure during writing linear barcodes"));
Compile and test the program.