|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Handling Constituent Control Events In An ActiveX DocumentAfter you add controls to an ActiveX document, how do you handle the events those controls create? Thats the beauty of it allyou handle such events just as you would in a standard Visual Basic EXE program, so designing an ActiveX document is really just like designing a standard form in Visual Basic. If you havent already done so, take a look at the tic-tac-toe game we developed in the previous topic. There, we set up a control array of nine buttons and handled the button clicks just as you would in a standard Visual Basic form:
Private Sub Command_Click(Index As Integer)
If blnXFlag Then
Command(Index).Caption = "x"
Else
Command(Index).Caption = "o"
End If
blnXFlag = Not blnXFlag
End Sub
Microsoft has worked hard to make sure that creating ActiveX documents is as easy as creating standard Visual Basic EXE programs in the hopes that ActiveX documents will become popular, and the programmer is the winner. Testing An ActiveX DocumentTo test an ActiveX documentand even debug itwhile in the design process using your ActiveX document-supporting Web browser (such as the Microsoft Internet Explorer), just follow these steps:
When you follow these steps, Visual Basic creates a VBD file for your document and opens that file in your Web browser (VBD files hold the ActiveX documents specification and tell the browser where to find the documents EXE or DLL file). Creating ActiveX Documents That Run Outside Visual BasicThe Testing Department is calling again. Your new ActiveX document is a winner, but how come you can only launch it from Visual Basic? Hmm, you say, Ill look into it. ActiveX documents need either an EXE or a DLL file and a VBD file. (You select either EXE or DLL when you create the documentsee ActiveX Document DLLs Vs. EXEs, earlier in this chapter.) How do you create these files? When you create an ActiveX document, you save it with the extension .dob. Visual Basic uses that DOB file to create the EXE or DLL file that holds the actual code for the ActiveX document. To create the EXE or DLL file, just select the Make ProjectName.exe item in the File menu (where ProjectName is your projects name). In addition, Visual Basic produces the specification file, with the extension .vbd, that describes the ActiveX document, and its that file that you actually open in the host application, such as the Microsoft Internet Explorer. To open the ActiveX document in the Internet Explorer, you just open the VBD file directly (use the File menus Open item), as shown in Figure 20.24, where weve opened the VBD file for the tic-tac-toe document we developed in the previous few topics.
Distributed Computing: ActiveX Documents And Integrated BrowsersThe Testing Department is calling. Now that the companys grown so huge (thanks to the success of your programs), we need to start using the Internet for the company reps in the field. Cant we download updated programs in a transparent way over the Internet? You think about ActiveX documents and say, no problem. If you integrate a Web browser into a program, you can have that browser download ActiveX documents in a seamless way that makes those documents look like part of the program itself. In this way, users can download ActiveX documents filled with current data into a program in a way that seems transparent to them. Lets see an example. Here, well add a Web browser to a program and use it to open the tic-tac-toe ActiveX document weve developed in the previous few topics. To create a program with a built-in Web browser, use the Visual Basic Application Wizard. When the Application Wizard asks you about Internet connectivity, as shown in Figure 20.25, click the option button labeled Yes, and enter the URL of your documents VBD file (which can be on the Internet) in the startup URL box; here, well use the disk location of our VBD file, which is C:\vbbb\activextictactoedoc\activextictactoedoc.vbd. Then click the Finish button to create the program.
At design time, we can customize the program even more by changing the caption of the menu item that opens the game from Web browser to Tic Tac Toe, and editing the browser form, frmBrowser, by removing the combo box that shows the URL and all the buttons. We can also stretch the Web browser control (brwWebBrowser) so it covers the whole frmBrowser form. Customizing the browser form this way prevents it from appearing as a Web browser at all. Instead, it will look like a part of your program; the fact that it comes from the Internet is entirely transparent to the user. (You can also remove the forms title bar so the name of the displayed ActiveX document is not displayed, but we wont go that far here.) Running this program and selecting the Tic Tac Toe menu item opens that ActiveX document in the program, as shown in Figure 20.26. The ActiveX document looks just like any other part of the program, which is the idea behind distributed computing.
Making ActiveX Document Properties Persistent (PropertyBag Object)Just as with ActiveX controls, you can make the data in ActiveX documents persistent, which means the data is stored when you close the document and restored in the display when you open the document. How does this work? To make the data in an ActiveX document persistent, you use the PropertyChanged method as you do with ActiveX controls, and use the ReadProperty and WriteProperty methods.
|
|
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. |