⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch16.htm

📁 用VC开发activeX控件的电子书,很不错的
💻 HTM
📖 第 1 页 / 共 5 页
字号:
and Netscape Navigator, you are better off using JavaScript. You can use a combination
of both, if needed.</P>
<P>Scripting languages are a subset of the languages they mimic; they do not include
all of the functionality available in the language. In general, scripting languages
have no way to access the system or data directly, which prevents the creation of
viruses. Scripting languages can, however, use other technologies to access data,
such as the Microsoft dbWeb and the Netscape LiveWire Pro. Visit the Netscape Web
site to view tutorials and language references for JavaScript, and the Microsoft
site for information on VBScript.</P>
<P>Scripting languages are interpretive, not compiled, so users need a scripting
engine to run scripts. Navigator does not include an engine for VBScript; therefore,
Navigator cannot be used with VBScript, as mentioned before. Both scripting engines
are included with Microsoft Internet Explorer. Both engines can be licensed from
their respective companies for free for use in applications. Be careful not to include
any sensitive data or code in the scripts. Because the scripts are not compiled,
all browsers have the capability to view the HTML document source, including the
scripting.</P>
<P>To include a script in a HTML document, use the <TT>&lt;SCRIPT&gt;</TT> tag. The
<TT>&lt;SCRIPT&gt;</TT> tag consists of the <TT>LANGUAGE</TT>, <TT>SRC</TT>, and
<TT>TYPE</TT> attributes. The <TT>LANGUAGE</TT> attribute states whether the script
is a VBScript or JavaScript script, <TT>SRC</TT> specifies the external file that
contains the scripts not directly in the HTML, and <TT>TYPE</TT> is the file type
for the external file. Listing 16.1 shows an example of VBScript and JavaScript.
The easiest way to add a script that is contained within the <TT>&lt;Script&gt;</TT>
tags is with the ActiveX Control Pad. In JavaScript only, you can also use the <TT>&lt;A&gt;</TT>
tag with a custom URL type, allowing a script to be executed when the user clicks
a hyperlink (see Listing 16.2).
<H3><A NAME="Heading6"></A>Listing 16.1 <SPACER TYPE="HORIZONTAL" SIZE="10">JSVBSSAMP.HTM--Example
of VBScript and JavaScript Using the &lt;SCRIPT&gt; Tag</H3>
<P><FONT COLOR="#0066FF"><TT>&lt;FORM NAME=&quot;SampleForm&quot;&gt;<BR>
&lt;INPUT TYPE=&quot;button&quot; NAME=&quot;VBSButton&quot; VALUE=&quot;VBScript&quot;
<BR>
onClick=&quot;VBSClick&quot; LANGUAGE=&quot;VBScript&quot;&gt;<BR>
&lt;INPUT TYPE=&quot;button&quot; NAME=&quot;JSButton&quot; VALUE=&quot;JavaScript&quot;
<BR>
onClick=&quot;JSClick()&quot; LANGUAGE=&quot;JavaScript&quot;&gt;<BR>
&lt;/FORM&gt;<BR>
&lt;!--VBScript example--&gt;<BR>
&lt;SCRIPT LANGUAGE=&quot;VBSCRIPT&quot;&gt;<BR>
sub VBSClick<BR>
document.SampleForm.VBSButton.value=&quot;Clicked&quot;<BR>
alert &quot;You clicked the VBScript button&quot;<BR>
document.SampleForm.VBSButton.value=&quot;VBScript&quot;<BR>
end sub <BR>
&lt;/SCRIPT&gt; <BR>
&lt;!--JavaScript example--&gt;<BR>
&lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;<BR>
function JSClick()<BR>
{<BR>
document.SampleForm.JSButton.value=&quot;Clicked&quot;<BR>
alert(&quot;You clicked the JavaScript button.&quot;)<BR>
document.SampleForm.JSButton.value=&quot;JavaScript&quot;<BR>
} <BR>
&lt;/SCRIPT&gt;</TT></FONT></P>
<H3><A NAME="Heading7"></A>Listing 16.2 <SPACER TYPE="HORIZONTAL" SIZE="10">AREFSAMP.HTM--Example
of JavaScript Using the &lt;A&gt; Tag</H3>
<P><FONT COLOR="#0066FF"><TT>&lt;A HREF=&quot;javascript:alert(`This is a message')&quot;&gt;Click
here to view the message &lt;/A&gt;</TT></FONT></P>
<H3><A NAME="Heading8"></A>Internet Component Download</H3>
<P>An important piece of the ActiveX Internet technology is the capability to safely
download and install ActiveX controls and the needed support files on the client
machine. Microsoft Internet Explorer automatically downloads and installs ActiveX
controls used in HTML documents through a process called <I>Internet Component Download.
</I>A control is downloaded only if the control is not installed on the users' machines
or if the version used in the HTML is newer than the control on the users' machines.
For now, the control remains on the users' machines until they remove it.</P>
<P>Microsoft has plans to provide a mechanism, in future releases of Internet Explorer,
to delete unused controls from a user's machine.</P>
<P>Before an ActiveX control is installed, Internet Explorer checks for a digital
signature. As mentioned earlier in this chapter, Internet Explorer has three safety
levels: high, medium, and low. High will not install an unsigned control, medium
asks users if they want to download an unsigned control, and low downloads a control
signed or unsigned. Digital signatures were covered earlier in this chapter. Once
the control is downloaded and installed, an attempt is made to register the control
and its components.</P>
<P>For a control in an HTML page to automatically download, you need to use the <TT>CODEBASE</TT>
attribute of the <TT>&lt;OBJECT&gt;</TT> tag. An example of this is shown in the
HTML code listed in Listing 16.3.
<H3><A NAME="Heading9"></A>Listing 16.3 <SPACER TYPE="HORIZONTAL" SIZE="10">SAMPLEIE.HTM--Using
an ActiveX Control in HTML Code</H3>
<P><FONT COLOR="#0066FF"><TT>&lt;HTML&gt;<BR>
&lt;HEAD&gt;<BR>
&lt;TITLE&gt;Sample Page&lt;/TITLE&gt;<BR>
&lt;/HEAD&gt;<BR>
&lt;BODY&gt; <BR>
&lt;OBJECT <BR>
ID=&quot;MFCControlWin1&quot; <BR>
WIDTH=100 <BR>
HEIGHT=51<BR>
CLASSID=&quot;CLSID:A1198546-2E75-11D0-BD82-000000000000&quot;<BR>
CODEBASE=&quot;http://www.somesite.com/somedirectory/ <BR>
MFCControl.ocx#Version=1,0,0,1&quot;&gt;<BR>
&lt;PARAM NAME=&quot;Alignment&quot; VALUE=&quot;1&quot;&gt;<BR>
&lt;PARAM NAME=&quot;CaptionProp&quot; VALUE=&quot;Sample&quot;&gt;<BR>
&lt;/OBJECT&gt; <BR>
&lt;/BODY&gt; <BR>
&lt;/HTML&gt;</TT></FONT></P>
<P>The <TT>CODEBASE</TT> attribute tells Microsoft Internet Explorer what to download
and install. The <TT>CODEBASE</TT> attribute contains a reference to where the control
and its supporting files can be found for downloading. If the control needs supporting
files, the <TT>CODEBASE</TT> attribute points to a cabinet (CAB) file or an install
(INF) file. These files, like an ActiveX control, can contain a digital signature.</P>
<P>A <I>CAB file </I>is a file that contains a compressed version of the control
and any other files the control needs to install and run. It is downloaded and expanded,
and the control's components are installed. To create a CAB file, use the Diamond
utility provided with the Microsoft ActiveX SDK.</P>
<P>An <I>INF file </I>specifies the files that need to be downloaded and their URLs.
Each file is downloaded and then installed. The INF file can provide platform independence
by specifying different URLs for files that need to be downloaded for different platforms.</P>
<P>The <TT>CODEBASE</TT> attribute should contain a version number to allow Microsoft
Internet Explorer to check whether the version of the file on the Web server is newer
than the same file installed on the user's machine. To include a version number,
use the <TT>Version</TT> URL fragment as shown in Listing 16.3. The numbers after
the <TT>=</TT> represent the current version of the control, which can be found by
looking at the properties of the control. If a version number is not used, Microsoft
Internet Explorer will assume that the version of the file on the user's machine
is recent enough.</P>
<P>For more information on the Internet Component Download, see the Internet Component
Download section of the Microsoft ActiveX SDK documentation.
<H3><A NAME="Heading10"></A>Electronic Commerce</H3>
<P>Electronic commerce could be defined as doing business by using a computer. For
your purposes, it is more specifically defined as doing business over the Internet.
It could be shopping via one of the Internet malls, buying and selling personal computers
via a reseller's Web site, online banking, or just about anything. Some of the many
advantages of doing business on the Internet are that companies are able to reach
people 24 hours a day, seven days a week; it's easier to reach global customers;
the number of Internet users is growing rapidly; information reaches people faster
through the Internet than through conventional methods; and new products can be released
more quickly.</P>
<P>One of the big disadvantages has been security. Server security has been around
for a while, but a standard technology for the secure transfer of sensitive data
was missing until recently. The Secure Channel communication technology, which provides
privacy, integrity, and authentication for the transfer of data from client to server
and server to server, helps to solve this problem. As mentioned earlier in this chapter,
SSL handles the authentication of the server, encryption of the data sent and received,
and integrity of the data being sent and received. PCT provides protection against
eavesdropping on a network or altering a network packet.</P>
<P>Before this technology was developed, credit card information and other sensitive
information could not be entered online. If people wanted to buy something they saw
on a merchant's Web site, they had to call the merchant to place an order. However,
the current technology makes ordering possible from the Web site; shopping and ordering
are done in one place. Examples of this are Dell Computer (<A HREF="http://www.dell.com"><B>http://www.dell.com</B></A>)
and Gateway2000 (<A HREF="http://www.gateway2000.com"><B>http://www.gateway2000.com</B></A>).
Both Web sites allow users to configure their own system, do what-if price analysis,
and place the order including payment information.</P>
<P>Another protocol, which is in the final stages of development, will further secure
electronic transactions. This protocol, Secure Electronic Transactions (SET), is
designed to handle secure credit card payments over the Internet using digital certificates
and cryptography.</P>
<P>The Netscape Merchant System and the Microsoft Merchant Server are specialized
systems for developing Web merchandising sites. These systems provide many built-in
features to help companies create a complete shopping Web site. The features include,
but are not limited to, billing, transaction processing, product updating, product
searching, storefront creation, handling of secured payments, order processing, and
database access. These systems are marketed as a total merchandising Web server solution.</P>
<P>The use of the Internet for commercial and recreational purposes expands every
day. The need for reliable security is unprecedented. Fortunately, a lot of people
and companies are working hard to make the Internet a reality for all types of use.</P>
<P>The next sections examine some of the advanced features of ActiveX.
<H2><A NAME="Heading11"></A>Advanced COM</H2>
<P>In this section, we dig into the details of the Component Object Model (COM).
In the first two subsections, we deal with COM fundamentals. First we examine how
C++ vtables are used to implement COM interfaces. Second we show how an ActiveX Object
can aggregate another ActiveX Object to implement part of its functionality, and
we discuss ATL tools for aggregation and tear-off interfaces. Finally we look at
enumerators.
<H3><A NAME="Heading12"></A>Using C++ vtables to Describe Interfaces</H3>
<P>Roughly, a <I>COM interface </I>is a structure that contains a pointer to a structure
containing pointers to functions. Rather than read that over, have a look at the
C definition of <TT>IUnknown</TT> in Listing 16.4.
<H3><A NAME="Heading13"></A>Listing 16.4<SPACER TYPE="HORIZONTAL" SIZE="10"> MSDEV\INCLUDE\UNKNWN.H--The
Definition of the IUnknown Interface in C Is a Structure that Contains a Pointer
to a Structure that Contains Pointers to Functions</H3>
<P><FONT COLOR="#0066FF"><TT>typedef struct IUnknownVtbl<BR>
{<BR>
BEGIN_INTERFACE<BR>
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )( <BR>
IUnknown __RPC_FAR * This,<BR>
/* [in] */ REFIID riid,<BR>
/* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject);<BR>
ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )( <BR>
IUnknown __RPC_FAR * This);<BR>
ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )( <BR>
IUnknown __RPC_FAR * This);<BR>
END_INTERFACE<BR>
} IUnknownVtbl; <BR>
interface IUnknown<BR>
{<BR>
CONST_VTBL struct IUnknownVtbl __RPC_FAR *lpVtbl; <BR>
};</TT></FONT></P>
<P><TT>IUnknownVtbl</TT> is the structure that contains pointers to functions. It's
identical to the table of virtual functions, or vtable, that C++ establishes for
a class's virtual functions. <TT>IUnknown</TT> is a structure that contains a pointer
to an <TT>IUnknownVtbl</TT> structure. So to simplify the definition, an <I>interface</I>
is a structure that contains a pointer to a vtable. Because COM defines an interface
this way, the definition of an interface in C++ is simpler than in C. Look at the
C++ definition of <TT>IUnknown</TT> in Listing 16.5
<H3><A NAME="Heading14"></A>Listing 16.5 <SPACER TYPE="HORIZONTAL" SIZE="10">MSDEV\INCLUDE\UNKNWN.H--The
Definition of an Interface in C++ Makes Use of C++ vtables</H3>
<P><FONT COLOR="#0066FF"><TT>interface IUnknown<BR>
{<BR>
public:<BR>
BEGIN_INTERFACE<BR>
virtual HRESULT STDMETHODCALLTYPE QueryInterface( <BR>
/* [in] */ REFIID riid,<BR>
/* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject) = 0; <BR>
virtual ULONG STDMETHODCALLTYPE AddRef( void) = 0; <BR>
virtual ULONG STDMETHODCALLTYPE Release( void) = 0; <BR>
END_INTERFACE <BR>
};</TT></FONT></P>
<P>In C++, the interface is simply a structure (a class, really) that has virtual
functions, and the vtable is implicit in the language. With that in mind, now look
at various ways an ActiveX Object can implement multiple interfaces. <B><I><BR>
<BR>
CNumber</I>: A Simple Sample </B><SPACER TYPE="HORIZONTAL" SIZE="10">The first sample
is a COM Object that implements a simple custom interface. The custom interface is
<TT>INumber</TT>, shown in Listing 16.6. <TT>INumber</TT> defines a method to get
the value of the number and a method to set the value of the number. <TT>CNumber</TT>
is a COM Object that implements the <TT>INumber</TT> interface. The <TT>CNumber</TT>
class is shown in Listing 16.7.
<H3><A NAME="Heading15"></A>Listing 16.6 <SPACER TYPE="HORIZONTAL" SIZE="10">INUMBER.H--The
INumber Interface</H3>
<P><FONT COLOR="#0066FF"><TT>interface INumber : public IUnknown<BR>
{<BR>
public:<BR>
// ILrsInetUnlock methods<BR>
virtual HRESULT __stdcall GetNumber(<BR>
/* [out] */ double* pValue) = 0;<BR>
virtual HRESULT __stdcall SetNumber(<BR>
/* [in] */ double value) = 0; <BR>
};</TT></FONT></P>
<H3><A NAME="Heading16"></A>Listing 16.7<SPACER TYPE="HORIZONTAL" SIZE="10"> UMBER.H--The
CNumber Class</H3>
<P><FONT COLOR="#0066FF"><TT>class CNumber : INumber<BR>
{<BR>
public:<BR>
// IUnknown methods<BR>
HRESULT __stdcall QueryInterface(REFIID riid,<BR>
LPVOID* lpInterface);<BR>
ULONG __stdcall AddRef();<BR>
ULONG __stdcall Release(); <BR>
// ILrsInetUnlock methods<BR>
HRESULT __stdcall GetNumber(double* pValue);<BR>
HRESULT __stdcall SetNumber(double value); <BR>
// Constructors and destructor<BR>
CNumber();<BR>
//CNumber(LPUNKNOWN pUnkOuter);<BR>
~CNumber(); <BR>
private:<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -