Element |
Tag Syntax |
HTC |
|
ATTACH |
|
PROPERTY |
|
METHOD |
|
EVENT |
|
Figure 3 hilite.htc
<PUBLIC:HTC URN="www.skonnard.com:hilitev1">
<PUBLIC:ATTACH EVENT="onload" FOR="window" HANDLER="initialize" />
<PUBLIC:ATTACH EVENT="onmouseover" HANDLER="hilite" />
<PUBLIC:ATTACH EVENT="onmouseout" HANDLER="normal" />
<PUBLIC:PROPERTY NAME="hiliteColor" />
<PUBLIC:METHOD NAME="ModifyColor" />
<PUBLIC:EVENT NAME="onColorChanged" ID="eColorChanged" />
<SCRIPT LANGUAGE="JScript">
var normalColor, normalSpacing;
function hilite()
{
// save original values
normalColor = style.color;
normalSpacing= style.letterSpacing;
style.color = hiliteColor;
style.letterSpacing = 2;
}
function normal()
{
// reset to original values
style.color = normalColor;
style.letterSpacing = normalSpacing;
}
function initialize()
{
// initialize the property
if (hiliteColor == null)
hiliteColor = "red";
}
function ModifyColor(newColor)
{
// modify the hiliteColor
hiliteColor = newColor;
oEvent = createEventObject();
eColorChanged.fire(oEvent);
}
</SCRIPT>
</HTC>
Figure 4 HTC Behavior Test
<html>
<head>
<title>HTC Behavior Test</title>
<style>
p { behavior:url(hilite.htc) }
</style>
</head>
<body>
<h1>HTC Behavior Test</h1>
<p HILITECOLOR="red" onclick="ModifyColor('blue')" onColorChanged="alert('color changed');">
Hilite Me!
</p>
<p HILITECOLOR="green" onclick="ModifyColor('red')" onColorChanged="alert('color changed');">
Hilite Me!
</p>
<p HILITECOLOR="blue" onclick="ModifyColor('green')" onColorChanged="alert('color changed');">
Hilite Me!
</p>
</body>
</html>
Figure 5 Syntax Differences in WSC and HTC
|
WSC Syntax (beta 1) |
HTC Syntax (beta 2) |
Identifying the behavior |
|
|
Receiving notifications |
|
|
Exposing and firing custom events |
|
|
Exposing properties and methods |
|
|
Figure 6 C++ Interfaces for Binary HTCs
// C++ Interfaces for Binary HTCs
interface IElementBehavior : IUnknown {
HRESULT _stdcall Init([in] IElementBehaviorSite* pBehaviorSite);
HRESULT _stdcall Notify(
[in] long lEvent,
[in, out] VARIANT* pvar);
HRESULT _stdcall Detach();
};
interface IElementBehaviorFactory : IUnknown {
HRESULT _stdcall FindBehavior(
[in] BSTR bstrBehavior,
[in] BSTR bstrBehaviorUrl,
[in] IUnknown* pUnkSite,
[out] IElementBehavior** ppBehavior);
};