• No results found

C H A P T E R

29

4

Reflection As an ActiveX Control

In version 7.0 of Reflection, the ability to use Reflection as an ActiveX control was introduced. Reflection can now be used within an application that supports ActiveX controls, such as a Visual Basic application. This enables an application to launch Reflection, to send commands to Reflection, and to respond to events that occur in the Reflection session.

This chapter provides a complete overview of using Reflection as an ActiveX control. This chapter details the tags, methods, and properties used to embed Reflection and invoke its features, and shows an example of HTML source code created to control Reflection in a web page.

What Is the Reflection ActiveX Control?

Reflection 8.0 includes a new file, R<n>axctrl.ocx, (<n> is 1, 2, or 4, depending on what product you installed, see the table on page 36). This .ocx file is the Reflection ActiveX control. Its purpose is to pass information between a web browser or a Visual Basic application and Reflection. This control calls and passes commands to Reflection from your application and can also return messages to the application indicating an event has occurred in the Reflection session. This control also lets you access almost all Reflection methods and properties.

Defining and Referencing Reflection As an ActiveX Control

To include Reflection in a web page requires HTML source code similar to the source used to include any other object in a web page. This HTML source code references the object and specifies parameters that should be used when the object is loaded.

As an example:

<OBJECT ID="R2winCtrl" width="550" height="370" CLASSID="CLSID: 15B168B2-AD3C-11d1-A8D8-00A0C9200E61">

<PARAM NAME="StartUpSettingsFile" VALUE="hostname.r2w"> <PARAM NAME="StartupMacro" VALUE="login">

<PARAM NAME="ControlID" VALUE="r2session"> <PARAM NAME=”InWebBrowser” VALUE=”True”> </OBJECT>

The Object tag is used to specify the ID of the ActiveX control, its placement in the web page, and the Class ID of the control. The Object ID (R2winCtrl) is used to reference the object elsewhere in the HTML source code. This Class ID is registered during instal- lation of Reflection.

Three different Class IDs are used, one for each of the three Reflection products: · Reflection for HP with NS/VT:

15B168AD-AD3C-11d1-A8D8-00A0C9200E61

· Reflection for UNIX and Digital:

15B168B2-AD3C-11d1-A8D8-00A0C9200E61

· Reflection for ReGIS Graphics:

15B168B7-AD3C-11d1-A8D8-00A0C9200E61

The parameters following the Object tag are unique to the Reflection ActiveX control. They can be used to specify desired actions when Reflection is started in a web page. Use of these parameters is optional, and each parameter has a different function:

Parameter Name Description

StartUpSettingsFile Specifies what settings file to load at startup: if no settings file is specified, or the file that is specified doesn’t exist, Reflection starts with default values

StartupMacro Specifies the macro in the settings file that should be run when Reflection starts

ControlID Specifies a unique session ID for Reflection: if you have more than one Reflection session running on a web page, specifying this parameter ensures that the position of each session is remem- bered when users return to this page in their browsers

InWebBrowser Specifies whether the control is being used within a browser. The value determines if Reflection will a dialog box on exit. Values are True or False.

Reflection As an ActiveX Control

31

Defining and Referencing Reflection As an ActiveX Control in an Application

Using Visual Basic, the Reflection ActiveX control is available as soon as Reflection is installed. To access the control, add the Reflection ActiveX control to your VB toolbox. Dragging the Reflection icon from the VB toolbox to your form drops the control right into the application. The properties of the control, such as the height and width, and the parameters, such as StartUpSettingsFile, are defined in the Properties window of the Visual Basic environment.

Controlling Reflection Within a Web Page or Application

The HTML example on page 29 shows an excerpt from a web page that contains Reflection. There are actually two ways to communicate to Reflection once the control has started the session: the distinction between the two forms of communication is important to note. The Reflection ActiveX control has its own interface, containing methods that let a user control Reflection through the ActiveX control. In contrast, a method exists for a user to bypass the Reflection ActiveX control and communicate directly with Reflection. The two methods are explained below.

The Reflection ActiveX contains the following methods:

· RunMacro: Runs a specific Reflection macro (contained in a settings file), for example:

R2winCtrl.RunMacro "DoTransfer", "Myfile.doc"

The DoTransfer parameter is the name of the macro to be executed. The Myfile.doc parameter is the macro data passed into the macro. In the example above, Myfile.doc is the file to be transferred.

· Command: Runs a specific Visual Basic command in Reflection, for example:

R2winCtrl.Command ".WRQSendFile,""Myfile.doc"","", rcBinary, rcDelete" In the above example, the .Command file is used to pass the Reflection method WRQSendFile to the Reflection session. In this case, Myfile.doc is transferred to the host as a binary file.

· SetFocus: Sets focus to the Reflection session, for example:

R2winCtrl.SetFocus

This method brings focus to Reflection’s terminal window from the web page or application.

· GetActiveSession: Returns the instance of the Reflection session object directly to the

calling application so that this application can communicate directly to the Reflection session. The way to use this method differs when using it from within a browser and using it in an application.

The following example is correct syntax when run inside a browser:

R2winCtrl.GetActiveSession.WRQSendFile "Myfile.doc","",rcBinary, rcDelete

The following example is correct syntax for a Visual Basic application: Dim Reflection2 As Reflection2.Application

Set Reflection2 = R2winCtrl.GetActiveSession

Reflection2.WRQSendFile "Myfile.doc","",rcBinary,rcDelete This code sets Reflection2 as the Reflection session object.

Receiving Information from Reflection Through Events

Perhaps as important as passing commands to Reflection, is the ability to respond to events that occur in a Reflection session. An application or web page can receive information from Reflection by using the event provided in the ActiveX control.

There are two separate actions required to use this event, one in the Reflection session itself, and one in the application or web page:

· In the Reflection session: Define an internal Reflection event, or mapping, which executes

the Visual Basic command, .RaiseControlEvent.

To define the internal Reflection event, use any of the mapping dialog boxes (Keyboard Mapping, Mouse Mapping, Event Setup, for example.), and map an action in

Reflection to the Visual Basic command .RaiseControlEvent. This command can specify two optional parameters, an integer and a string. These two values are passed back to your application or web page.

· In the application or web page: Handle the event in your application or web page using

Reflection As an ActiveX Control

33

As an example:

Map the Reflection Event, When a connection is made to .RaiseControlEvent 0, "connected". Now, in the web page, insert code to perform some action based on .RaiseControlEvent, such as:

<VBScript>

Sub R2winctrl_OnReflectionEvent(eventnumber, eventdata) If (eventnumber = 0) then

MsgBox "Connection Established", ,"Reflection" Else

if(eventnumber =1) then

MsgBox "Disconnected", ,"Reflection" End if

End if End Sub </VBScript>

In this example, when the Reflection session has established a connection, the .RaiseControlEvent is sent to your web page. Your web page then displays a message box with the text “Connection Established.”