689 691




Visual Basic 6 Black Book:Creating ActiveX Controls And Documents
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




Handling Constituent Control Events In An ActiveX Document
After you add controls to an ActiveX document, how do you handle the events those controls create? That’s the beauty of it all—you 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 haven’t 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 Document
To test an ActiveX document—and even debug it—while in the design process using your ActiveX document-supporting Web browser (such as the Microsoft Internet Explorer), just follow these steps:


1.  Select the ProjectName Properties item in the Project menu (where ProjectName is the name of your project).
2.  Click the Debugging tab in the Project Properties dialog box that opens.
3.  Make sure that the option button labeled Start Component is selected (the start component should be given as the name of your document, such as UserDocument1).
4.  To use your existing browser, make sure the box labeled Use Existing Browser is checked.
5.  Close the dialog box by clicking on OK.
6.  Start the document with the Start item in the Run menu.

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 document’s specification and tell the browser where to find the document’s EXE or DLL file).

Creating ActiveX Documents That Run Outside Visual Basic
The 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, I’ll 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 document—see “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 project’s name).
In addition, Visual Basic produces the specification file, with the extension .vbd, that describes the ActiveX document, and it’s 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 menu’s Open item), as shown in Figure 20.24, where we’ve opened the VBD file for the tic-tac-toe document we developed in the previous few topics.

Figure 20.24  Displaying a VBD file in the Microsoft Internet Explorer.
Distributed Computing: ActiveX Documents And Integrated Browsers
The Testing Department is calling. Now that the company’s grown so huge (thanks to the success of your programs), we need to start using the Internet for the company reps in the field. Can’t 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.
Let’s see an example. Here, we’ll add a Web browser to a program and use it to open the tic-tac-toe ActiveX document we’ve 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 document’s VBD file (which can be on the Internet) in the startup URL box; here, we’ll use the disk location of our VBD file, which is C:\vbbb\activextictactoedoc\activextictactoedoc.vbd. Then click the Finish button to create the program.

Figure 20.25  Setting Internet connectivity with the Application Wizard.
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 form’s title bar so the name of the displayed ActiveX document is not displayed, but we won’t 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.

Figure 20.26  Opening an ActiveX document in a program with a Web browser.
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.



Previous
Table of Contents
Next






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.



Wyszukiwarka

Podobne podstrony:
689 691
689 691
689 Uproszczenia dla jednostek nie mających obowiązku badania bilansu
Nuestro Circulo 691 TOPALOV 10 ANOS 14 de noviembre de 2015
index (689)
691 (2)
T REC G 691 200603 I!!PDF E
684 689
2 Przestrzenieid 691
687 689
687 689

więcej podobnych podstron