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
There are a few reasons why you may want to create your ActiveX document as an in-process component (DLL file). The performance of an in-process component surpasses that of the same component compiled as an EXE. In addition, multiple programs accessing the same EXE can overwrite global data; that doesnt happen if they each have their own in-process server.
Which ActiveX Component Do I Want To Build?
With all the different types of ActiveX components to choose from, how do you decide which type of component you want to create? Take a look at this list:
To build an invisible component that provides routines in code that you can call, build a code component (ActiveX EXE or an ActiveX DLL).
To build a component that can run in the same process with your application, build an ActiveX DLL.
To build a component that can serve multiple applications and can run on a remote computer, build an ActiveX EXE.
To build a visible component that can be dropped into an application at design time, build an ActiveX control.
To build a visible component that can take over an application window at runtime, build an ActiveX document.
Thats it for the overview of ActiveX controls and documents for the momentits time to turn to the Immediate Solutions.
Immediate Solutions
Creating An ActiveX Control
The Testing Department is calling again. Wouldnt it be great if you built a new ActiveX control that displayed a digital clock? That control could be reused in many other programs. Hmm, you think, how do you create an ActiveX control?
Select the New Project menu item in the Visual Basic File menu to open the New Project dialog box, as shown in Figure 20.1.
Figure 20.1 The New Project dialog box.
Select the ActiveX Control item in the New Project dialog box and click on OK. This creates a new, empty ActiveX control, as shown in Figure 20.2.
Figure 20.2 A new ActiveX control.
Believe it or not, youve created your first ActiveX control, UserControl1. You can even run the control with the Run menus Start item, which would display the control by launching the Microsoft Internet Explorer if you have it installed in your computer; however, there would be nothing to see because the control is empty.
The default name of the control is Project1, but we can change that to, say, FirstControl. To do that, select the Project1 Properties item in the Project menu, and type FirstControl into the Project Name box in the Project Properties dialog box, then click on OK. Also, save the project as firstcontrol.vbp. Instead of a FRM file, you save ActiveX controls in CTL files. Select the Save UserControl1 item in the file menu to save the control as firstcontrol.ctl. Heres what appears in that file on disk:
VERSION 6.00
Begin VB.UserControl UserControl1
ClientHeight = 3600
ClientLeft = 0
ClientTop = 0
ClientWidth = 4800
ScaleHeight = 3600
ScaleWidth = 4800
End
Attribute VB_Name = "UserControl1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Now that weve seen how to create a new ActiveX control, its time to make it do something. Well see how that works in the next topic.
Designing An ActiveX Control From Scratch
The testing department is on the phone. Your new ActiveX control looks fine, but why doesnt it do anything? Should it? you ask. Yes, they say.
You can design the appearance of your ActiveX control entirely from scratch, creating an entirely new control, never seen before. In that case, youre responsible for creating the controls appearance from scratch. Later, you can add events to your control, as well as methods and properties, as well see later in this chapter.
To design the appearance of your entirely new control, you can use the Visual Basic graphics methods that the UserControl object supports, such as Circle, Line, PSet, Print, Cls, and Point. You can also display an image in the UserControl object by setting its Picture property.
Lets see an example. Here, well just draw two lines to crisscross an ActiveX control and draw a black box in the middle. Create a new ActiveX control now, and double-click it at design time to open the code window to the UserControl_Initialize function:
Private Sub UserControl_Initialize()
End Sub
This function is just like the Form Load procedure that were familiar with. Set the controls AutoRedraw property to True so we can draw graphics from UserControl_Initialize, and then draw the lines to crisscross the control, using the Line method and ScaleWidth and ScaleHeight just as you would in a Visual Basic form:
Private Sub UserControl_Initialize()
Line (0, 0)-(ScaleWidth, ScaleHeight)
Line (0, ScaleHeight)-(ScaleWidth, 0)
...
End Sub
Next, we draw a filled-in black box in the center of the control this way:
Private Sub UserControl_Initialize()
Line (0, 0)-(ScaleWidth, ScaleHeight)
Line (0, ScaleHeight)-(ScaleWidth, 0)
Line (ScaleWidth / 4, ScaleHeight / 4)-(3 * ScaleWidth / 4, _
3 * ScaleHeight / 4), , BF
End Sub
Lets test this new ActiveX control now in the Microsoft Internet Explorer (assuming you have that browser installed). To do that, just select the Run menus Start item now. Doing so opens the Project Properties dialog box, shown in Figure 20.3.
Figure 20.3 The Project Properties window.
Leave UserControl1 in the Start Component box, and make sure the Use Existing Browser box is clicked, then click on OK. This registers our control with Windows, creates a temporary HTML page with the control embedded in it, and starts the Internet Explorer, as you see in Figure 20.4.
Figure 20.4 Our first ActiveX control.
You can see our new ActiveX control in Figure 20.4. Now weve created our first ActiveX control and designed its appearance from scratch. If we wanted to, we could add events, properties, and methods to this control (well see how to do so later in this chapter).
Heres the temporary HTML page that Visual Basic creates to display our ActiveX control; note that our control is registered with Windows and has its own ID, so this page can use the HTML <OBJECT> tag to embed one of our controls in the page:
<HTML>
<BODY>
<OBJECT classid="clsid:B2A69D3B-D38C-11D1-8881-E45E08C10000">
</OBJECT>
</BODY>
</HTML>
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:
2009 03 BP KGP Niebieska karta sprawozdanie za 2008rid&6572007 09 Szkoła konstruktorówid 657II CSK 657 10 1649 652SP?657652 Ewidencja przeceny towarów w księgach rachunkowych657 Uproszczona rachunkowość małych firm657 (2)więcej podobnych podstron