684 689




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




ActiveX Document DLLs Vs. EXEs
You can create both ActiveX document EXEs and DLLs. Here’s the difference: if an ActiveX document is written as an executable file (EXE file), it is an out-of-process server and runs in its own process; if it has been implemented as a dynamic link library (DLL file), it is an in-process server and runs in the same process as the client application.
Although ActiveX documents are usually built as EXE projects, the benefit of DLLs is that applications that use in-process servers usually run faster than those that use out-of-process servers because the application doesn’t have to cross process boundaries to use an object’s properties, methods, and events. In addition, the performance of an in-process component, or DLL file, surpasses that of the same component compiled as an EXE. Also, multiple programs accessing the same EXE can overwrite global data, but that doesn’t happen if they each have their own in-process server.
Adding Controls To An ActiveX Document (A Tic-Tac-Toe Example)
The Testing Department is on the phone. The ActiveX document you’ve created is very nice, but why can’t you do anything with it? Well, you say, I was just about to add controls to it and create a Web browser game.

Using ActiveX documents, you can display entire forms in Web browsers. To see this at work, we’ll create a mini tic-tac-toe game. This game will let users click buttons to display alternate x’s and o’s (although it won’t include the logic to actually play tic-tac-toe). Working with multiple controls in this way will demonstrate how to display entire programs as Web pages.
Create a new ActiveX document (EXE or DLL), and add nine command buttons to it arranged in a 3×3 grid in classic tic-tac-toe fashion. Give each button the same name, Command, clear each button’s caption (that is, select the text in the caption and press the backspace key), and when Visual Basic asks if you want to create a control array, click Yes, because a control array will make the code shorter and easier to handle.
To alternate x’s and o’s as the user clicks buttons, we’ll need a Boolean flag, which we’ll call blnXFlag. If this flag is true, the next caption to set will be “x”; otherwise, “o”. Add the declaration of blnXFlag to the (General) section:


Dim blnXFlag As Boolean


We also initalize blnXFlag to True when the document first loads by adding this code to the Initialize event handler:


Private Sub UserDocument_Initialize()
blnXFlag = True
End Sub


Now when the user clicks a button, we alternate between setting the clicked buttons’ captions to “x” and “o” this way:



Private Sub Command_Click(Index As Integer)
If blnXFlag Then
Command(Index).Caption = "x"
Else
Command(Index).Caption = "o"
End If
...
End Sub


At the end of the code, we toggle the state of blnXFlag for the next time the user clicks a button:


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


Let’s see our new ActiveX document game at work. Select the Project1 Properties item in the Project menu, and click the Debugging tab in the Project Properties dialog box that opens. Make sure that the option button labeled Start Component is selected (the start component should be given as UserDocument1), and the box labeled Use Existing Browser is checked. Then close the dialog box by clicking on OK, and run the game with the Start item in the Run menu.
The result appears in Figure 20.23. As you can see, our entire game appears in the Microsoft Internet Explorer. The user can alternate button captions just by clicking the buttons. Our ActiveX document example is a success.

Figure 20.23  Our tic-tac-toe ActiveX document.
We’ll save the document as activextictactoe.dob (ActiveX documents have the extension .dob when saved in Visual Basic, just as form files have the extension .frm), and the project as activextictactoe.vbp. The default name for the document is UserDocument1, as you can see in the Visual Basic Properties window; if you want to use a different name for the document, set it in the Properties window. We’ll change the document name to activextictactoedoc. When we create the VBD specification file for this document, then, that file will be activextictactoedoc.vbd, and that’s the file to open in your Web browser

The code for this example, activextictactoedoc.dob version 1 (version 2 will support persistent data), appears in Listing 20.4.
Listing 20.4 activextictactoedoc.dob version 1


VERSION 6.00
Begin VB.UserDocument activextictactoedoc
AutoRedraw = -1 'True
ClientHeight = 2865
ClientLeft = 0
ClientTop = 0
ClientWidth = 4800
HScrollSmallChange= 225
ScaleHeight = 2865
ScaleWidth = 4800
VScrollSmallChange= 225
Begin VB.CommandButton Command
Height = 495
Index = 8
Left = 3360
TabIndex = 8
Top = 1920
Width = 1215
End
Begin VB.CommandButton Command
Height = 495
Index = 7
Left = 3360
TabIndex = 7
Top = 1080
Width = 1215
End
Begin VB.CommandButton Command
Height = 495
Index = 6
Left = 3360
TabIndex = 6
Top = 360
Width = 1215
End
Begin VB.CommandButton Command
Height = 495
Index = 5
Left = 1800
TabIndex = 5
Top = 1920
Width = 1215
End
Begin VB.CommandButton Command
Height = 495
Index = 4
Left = 1800
TabIndex = 4
Top = 1080
Width = 1215
End
Begin VB.CommandButton Command
Height = 495
Index = 3
Left = 1800
TabIndex = 3
Top = 360
Width = 1215
End
Begin VB.CommandButton Command
Height = 495
Index = 2
Left = 240
TabIndex = 2
Top = 1920
Width = 1215
End
Begin VB.CommandButton Command
Height = 495
Index = 1
Left = 240
TabIndex = 1
Top = 1080
Width = 1215
End
Begin VB.CommandButton Command
Height = 495
Index = 0
Left = 240
TabIndex = 0
Top = 360
Width = 1215
End
End
Attribute VB_Name = "activextictactoedoc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Dim blnXFlag As Boolean

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

Private Sub UserDocument_Initialize()
blnXFlag = True
End Sub






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:
684 Podwyższenie kapitału zakładowego w spółce z o o
681 684
689 Uproszczenia dla jednostek nie mających obowiązku badania bilansu
6 rozB 676 684
Nuestro Circulo 684 CTO ARGENTINO FEMENINO
index (689)
684 687
www mediweb pl sex wyswietl vad php id=684

więcej podobnych podstron