Chapter 9. Developing Applications with Morovia Barcode ActiveX Control

This chapter explains how to integrate Morovia Barcode ActiveX control with Visual C++, Visual Basic and Windows scripting applications. The Morovia Barcode ActiveX product comes with a full collection of samples for Visual C++, Visual Basic and more.

9.1. License considerations

Generally there are two different approaches to use a Barcode ActiveX control in your application. You can create the control by inserting it into a dialog/form; or you can create the object at background. Those two scenarios have different license implications. Most programming environments understand the license protocols well. When you insert the control to a dialog or a form, the programming environment retrieves the run-time license from the control and embed it into the dialog/form resource. When the application runs on another computer, the barcode object is then created with the embedded license key. This whole process is transparent to the developer and end user.

Your application can also create the barcode object at background. Unfortunately you have to pass the license key manually in this scenario if you need your application to run on a computer without design time license installed. If you are programming in C++, your application should call IClassFactory2::CreateInstance and pass your LicenseToas the license key. Note that it is much difficult to use this approach when you work in some environments, such as classic Visual Basic. When this is the case, you can get around it by inserting the control into a dialog/form and making it hidden. When you need to use the control, just retrieve the interface pointer from the hidden control. In this way you let the programming environment handles the licensing issue for you and you concentrate on the feature development.

In scripting environment, such as ASP and PHP, the computer must have the design-time license available in order to create the contorl. In those scenarios, the computers running your script must get their single user/network server licenses separately.

9.2. Using Morovia ActiveX Controls with MSVC++

To use Morovia Barcode ActiveX with Visual C++, you need to make a project that uses MFC with ActiveX support. The easiest way to do this is to use the MFC AppWizard (exe).

Make sure that support for ActiveX controls is enabled (it should be enabled by default). Then you will be able to add ActiveX controls to the dialog and make member variables for them using ClassWizard (see below for more details).

This example assumes you are creating the ActiveX Control in a dialog box.

Right-click on the dialog box and select Insert ActiveX Control from the menu.

Figure 9.1. Inserting Control Into a MFC Dialog

Inserting Control Into a MFC Dialog

From the list that appears, choose Morovia Barcode ActiveX to include. It displays an area of barcode image. Change the symbology to the one you are working with, and other properties.

9.2.1. Adding Member Variable in Class Wizard

The ActiveX Control will appear in the Member Variables tab in the Class Wizard. When you add a variable for the control, MSVC creates a Class wrapper for the control.

9.3. Adding ActiveX Controls in Visual Basic

To add an ActiveX Control in Visual Basic first add it to the Control Toolbar.

  1. Right click on the Control Toolbar and select Components... from the drop-down box.

  2. Choose the ActiveX Controls from the list. (e.g. Morovia Barcode ActiveX). Click OK.

  3. Icons for the ActiveX Controls will now appear in the Control Toolbar. The Morovia Barcode ActiveX control is shown in this toolbar.

  4. Double-click on an icon to add a control to the form. As each icon is added it will be given its own name (e.g. MoroviaBarcodeActiveX1).

  5. Use the names of the controls to call ActiveX functions. All of the available methods for the ActiveX function appear in the pop-up box as the control is entered. The ActiveX functions should be preceded by the Call function when accessing methods that do not require the return of a value. When the method is preceded by an "=" i.e, when returning a variable value, Call is not required.

9.4. Windows Scripting

9.4.1. Prerequisite

Before you experiment the samples in this article, you need to have the VBScript run time installed on your computer. The VBScript run time engine comes with Microsoft Internet Explorer 4.0 or above.

The scripting environment also requires you to have the design-time license of the Barcode control. This can be assured by running the installer provided by Morovia.

9.4.2. Details

A great feature of Morovia Barcode ActiveX is Windows Scripting integration. The interface is carefully designed and implemented to be compatible with scripting languages, such as VBScript and Jscript. This allows you to batch generate barcode images with several lines of code:

Dim oStr
Set OStr = WScript.CreateObject("Morovia.BarcodeActiveX")
Ostr.AutoSize = true
ostr.Font.Name = "Arial"
ostr.Symbology = 10
ostr.Message = "978020161594|53995"
oStr.ExportImage "ean-13-sample.jpg", 1
ostr.Symbology = 12
ostr.Message = "0-87779-709-9|90000"
ostr.ExportImage "bookland-Sample.jpg", 1

The code above generates two barcode image files, one for an EAN-13 and another for Bookland.

If you are using Barcode ActiveX lite version, you need to change the ProgID from Morovia.BarcodeActiveX to Morovia.BarcodeLite.

9.5. Using Barcode ActiveX at background

9.5.1. Visual C++

Morovia Barcode ActiveX work with Visual C++ 5.0, 6.0 and Visual Studio .Net. We recommend that C++ programmers use Microsoft Visual C++ #import directive to import the desired Morovia Barcode control as an OLE server. This will automatically expose the control's methods and properties in your project.

9.5.2. Visual Basic

The code snippet below demonstrates how to create the control at the background, and use the Barcode ActiveX to create a barcode and send it to the printer:

Dim BC
Set BC = CreateObject("Morovia.BarcodeActiveX")
Printer.PaintPicture BC.Picture, 2048, 1024
Set BC = Nothing