Register ActiveX Events in Event Structures in LabVIEW

Updated Feb 16, 2024

Environment

Software

  • LabVIEW

This article will guide you through the process of registering an Active X event so it can be used to trigger an event case structure in LabVIEW. The process assumes general knowledge of Active X, Active X events, and event-driven programming if these concepts are new to you, visit the following documentation. The procedure will integrate one of the old LabVIEW Active X examples that uses the Web Browser Active X control. It will receive a Web Page URL as input from a control, and then return through an event and a Callback VI the corresponding title of the Web Page. The same Callback VI will be used to also generate a second customized event that will later be used by the event structure to turn on a led control and show how the programmatic event is registered. 

The program also integrates another Active X method that would let you Navigate to the specific URL, even though it is not part of the specific subject of this article, it was part of the original example and was kept to expand on the functionality of Active X programming.

Use the following diagram as a base to complete the procedure:
image.png
1. Use the Create User Event Function to create the Custom Event,  this and other event VIs are located in the  Dialog & User Interface>>Events Pallete. Notice how the input for this event is a cluster, the data type and label of the elements define the data type and name of the user event. LabVIEW uses owned labels to identify data the user event carries, you should name each element of the input with a descriptive owned label. If you do not add a label, the user event will not appear in the Event Data Node of an Event structure when added.
2. Place a Register For Events Node and connect the event created in step 1, this node will create an event registration refnum for the custom event that will be used later in the event structure.
3. Place an Active X container in the front panel, this and other Active X components are located in the .NET & Active X Pallete. Once you add the control, right-click on it and select Insert Active X Object, select the required object and then click on OK, for this example we will select the Microsoft Web Browser Object. 
 image.png
4. Place Register Event Callback node and connect the Active X control created in the last step to the Event Source Terminal. Click on the dropdown menu and select the Event, for this example select the Title Change Event. Pass a cluster of bot the custom event refnum created in the step 1 and a reference for a string (Web Page Title) to the User Parameter terminal, and use the bundle function to form a cluster of the last 2 mentioned components. Both the reference and the event refnum will be used inside the Calllback VI that will be created in the next step.
5. To create the Callback VI, right-click in VI Ref and select Create Callback VI 
image.png
This option will automatically create a Callback VI, from there you will be able to access the User Parameters. Double-click on the created VI to open it. and create the following VI, after completing the diagram save the VI:
image.png
a. Use a Unbundle By Name function to access both the event refnum cluster and the Web Page Title reference. 
b. Use another Unbundle By Name function to access the Text from the Event Data cluster, this is the data returned by the Title Change Event selected in step 4. The text will contain the name of the web page.
c. Use a Property node with the Web Page Title reference as the input, select the Value property in write mode and pass the text as the input. This property node will write the value to the Web Page Title indicator we have in the main front panel.
d. Use a Generate User Event function to create an event that will trigger the Event structure in the main VI. 
6. Create a while loop with an event structure inside. To register programmatic events such as the custom event we created in the last steps, right click on the structure and select Show Dynamic Event Terminals
image.png 
Once the structure is created create the following 3 events with the respective block diagram,
  • <Custom Event>: User event:
This event will demonstrate the custom event we created in step 1 and generated in step 5 is triggering the event structure. For this example, you can use a Led to demonstrate the execution, in another application you can adjust this event according to your requirements.
 
image.png
image.png
  • "Stop": Value Change
Use this event to stop the loop.
image.png
image.png
  • "Web Page URL": Value Change
This is the secondary Active X event mentioned in the first section of the article. It uses the Navigate2 method to Navigate to the specific URL. Use the Web Browser container created in step 3 as the input. 
image.png
image.png
 
7. Use the Unregister For Events and Destroy User Events functions to finish up the process. 
 
 

The following is the result of the program, the WebBrowser container will show the browser, the Web Page title will reference the Page name retrieved from the Title Change Event and the Custom Event executed? boolean control will confirm the custom event you created is correctly executed. 
image.png