|
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
Using ActiveX Controls with Visual J++Were going to get our hands dirty by using one of the controls that Visual J++ supplies. Visual J++ came with 15 ActiveX controls including a Calendar control, a TreeView control, and a Sprite control. Lets start by creating a Visual J++ application named UseActiveX1. When the project is created, select the ActiveX Controls tab in the Toolbox window. The ActiveX controls that come with Visual J++ will appear as shown in Figure 20.1.
Select the Calendar control in the Toolbox window. Place the control on your Form window so that it occupies the entire Form window as shown in Figure 20.2.
You should notice in Figure 20.2 that the Properties window contains the properties for the Calendar control. Of course, if you select any other control or item and the Calendar control isnt selected, the Properties window will no longer contain the properties for the Calendar control. The properties that youll most often modify are the showDateSelector, showDays, showHorizontalGrid, showTitle, and showVerticalGrid properties. They all default to a value of true, but you can change the appearance of the control by changing any of them to false. The odd thing about this control is that when you try to change these properties, a button with an ellipsis appears. This button then brings up a dialog box in which you can edit these properties as shown in Figure 20.3.
Youll also be interested in the events for ActiveX controls. Select the control so that its properties appear in the Properties window. You can then click the Events button (the one with the lightening icon) and the controlis events will appear in the Properties window. To use the Calendar control, there are two approaches that you can take. You can use the Calendar controls methods to get the date information from somewhere in your program. The following example shows you how to get the day, month, and year from a Calendar control: int nDay = calendar1.getDay(); int nMonth = calendar1.getMonth(); int nYear = calendar1.getYear(); You can also add an event handler for a Calendar control. The following event handler is the one I use most often: private void calendar1_afterUpdate(Object source, Event e) { // Handle the calendar event. } Installing the ControlsWhat if your friend just gave you an ActiveX control that does exactly what your program needs? How are you going to use it in your program? Thats easy; all you have to do is create a COM wrapper for the control. First things first. Im going to be using two controls in this section. One was written in Visual Basic and the other in Visual C++. To use the Visual Basic control, youll need to have the Visual Basic runtime support installed. To get these two controls, you can go to my Web site at www.infinitevision.net, go to the book section, and find the Learn Visual J++ 6 in 21 Days page. Youll see at the bottom of the page a link that lets you download the controls for Chapter 20. After you download the controls for this chapter, unzip them to a directory on your hard drive.
With the two controls unzipped, youll have to register them. The easiest way to do this is from a command prompt. Run a command prompt and log on to the directory into which the controls have been placed. For Windows 95 and Windows 98 systems type the following lines from the command prompt to register the controls. c:\windows\system\regsvr32 RegistryControl.dll c:\windows\system\regsvr32 OhmsCalculator.ocx After you register each control, the regsvr32 program will display whether the registration was successful or whether an error was encountered as shown in Figure 20.4.
When you want to unregister a control, you can use the regsvr32 program. All you need to do is add the /u command line switch as follows: c:\windows\system\regsvr32 /s RegistryControl.dll For Windows NT systems type the following lines from the command prompt to register the controls. c:\winnt\system32\regsvr32 RegistryControl.dll c:\winπystem32\regsvr32 OhmsCalculator.ocx A summary of the steps to get and register the controls follows:
Now that the controls are on your hard drive and have been registered, you can create a COM wrapper for them and use them in your program. For this discussion, I created a new Visual J++ application named UseActiveX2. I suggest you do the same. Select Add COM Wrapper from the Project menu. A dialog box will appear in which all of the ActiveX controls that are registered on the system are listed. Find the OhmsCalculator control and check it as shown in Figure 20.5.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |