The features described in this topic are obsolete
and should not be used in new IDL code.
Creating an Interface and Handling Events
The goal of this first example is very simple: to create a user interface in Microsoft Visual Basic and have IDL respond to events and display an image. The following figure shows what the finished project looks like when it runs. The Visual Basic source code used to create the example is shown in the following figure:
As the figure shows, our first example program consists of two buttons ("Plot Data" and "Exit"), a graphics area, and a text box. All of these elements reside on top of what is called a form in Visual Basic parlance. (A form in Visual Basic is similar to a top level base in IDL.) Clicking the Plot Data button causes IDL to produce the surface plot shown. Clicking Exit causes IDL and the Visual Basic program to free memory and exit.
Drawing the Interface
Begin building the first example by creating a new Visual Basic project, adding the IDL ActiveX control, and drawing the interface components.
Launch Microsoft Visual Basic and create a new project.
- Add the IDL ActiveX component to the project. Visual Basic displays a list of all available components when you select the Components from the Project menu.
- Begin drawing the interface. The "Plot" and "Exit" buttons were created with the CommandButton widget, the text box was created with the TextBox widget, and the graphics display area was created with IDLDrawWidget.
Select the "IDLDrawX3 ActiveX Control module" check box and close the Components window. Visual Basic will display the IDLDrawWidget's icon in the toolbar.
Specifying the IDL Path and Graphics Level
Having added IDLDrawWidget to the Visual Basic project, we now have access to IDLDrawWidget's properties and methods. Use the IdlPath and GraphicsLevel properties to specify the directory path of the IDL ActiveX control and to choose between IDL's direct and object graphics capabilities. Refer to IDLDrawWidget Control Reference for a complete list of the properties and methods to IDLDrawWidget.
- Use Visual Basic's Properties window to select the IDLDrawWidget. All of the IDLDrawWidget's properties can be set using the Properties window. Many properties can also be set within the source code. These distinctions are noted in IDLDrawWidget Control Reference.
- Locate the IdlPath property and enter the directory path to your IDL installation. If you installed IDL in its default location, this path will be:
- Locate the GraphicsLevel property and set it equal to 1. This selects IDL's direct graphics. A setting of 2 selects IDL's object graphics.
Initializing IDL
With the interface drawn and the properties of the IDLDrawWidget set, now write some Visual Basic code to give the application behavior. By double-clicking on the form which contains all of the interface components, Visual Basic will automatically generate the following subroutine.
Visual Basic's Form_Load routine executes automatically when a program starts running. This procedure can be used to initialize IDL, create the IDLDrawWidget, and direct output from IDL to a text box. The code to accomplish these tasks will be placed between the two statements listed above.
IDL needs to be initialized before Visual Basic can interact with the IDLDrawWidget. This is done with the InitIDL method. InitIDL takes the hWnd of the form containing the IDLDrawWidget as an argument and returns 1 or less than 1, depending on whether or not IDL initialized successfully. Assuming that the default names given to the form and the IDLDrawWidget were not changed, IDL can be initialized with the following statement.
A conditional statement is included to display an error message and exit the program if IDL failed to initialize.
Creating the Draw Widget
When a box is drawn with the "IDLDrawWidget" icon in the toolbar, an OCX frame is created. This is a container for the IDLDrawWidget. This container is analogous to an IDL widget base. The graphics window that will be used by IDL still must be created. This is accomplished with the CreateDrawWidget method, as shown in the following statement:
Directing IDL Output to a Text Box
The example program displays any output returned by IDL in a text box created in Visual Basic. This is accomplished with the SetOutputWnd method of the IDLDrawWidget. The SetOutputWnd method takes the hWnd of the text box that will contain the IDL output as an argument. The text box in the example program is named IDL_Output_Box, hence the following statement.
Note
Although this is the last statement within the Form_Load() subroutine, it could be placed before the call to InitIDL to get standard IDL version information printed.
Responding to Events and Issuing IDL Commands
The easiest way to integrate IDL with Visual Basic is to let Visual Basic manage the events and pass instructions to IDL. Recall that our example program contains two buttons: "Plot Data" and "Exit". When you double-click on "Plot Data", Visual Basic automatically creates the following subroutine:
Visual Basic will execute any statements within this subroutine when the user clicks "Plot Data". Instructions are passed to IDL using the ExecuteStr method to the IDLDrawWidget. The ExecuteStr method takes a string as an argument. This string is passed to IDL for execution as if it were entered at the IDL command line.
The five statements which follow instruct IDL to produce the surface plot shown in the figure above.
IDLDrawWidget1.ExecuteStr ("Z = SHIFT(DIST(40), 20, 20)")
IDLDrawWidget1.ExecuteStr ("Z = EXP(-(Z/10)^2)")
IDLDrawWidget1.ExecuteStr ("SURFACE, Z")
IDLDrawWidget1.ExecuteStr ("PRINT, SIZE(Z)")
Cleaning Up and Exiting
This project exits when the user clicks "Exit". Exiting is a two step process. IDL is given a chance to clean up and exit by issuing the DoExit method. The Visual Basic program then exits with an End statement.


