Figure 2   Stores Class from HTC Syntax

Element
Tag Syntax
HTC
 <PUBLIC:HTC
 URN = sURN>
ATTACH
 <PUBLIC:ATTACH
 EVENT = sEvent
 FOR = "document" | "element" | "window"
 HANDLER = sEventHandler
 URN = sURN/>
PROPERTY
 <PUBLIC:PROPERTY
 NAME = sName
 ID = sPropertyID
 INTERNALNAME = sInternalName
 GET = sGetFunction
 PUT = sPutFunction
 PERSIST = bPersist/>
METHOD
 <PUBLIC:METHOD
 NAME = sName
 INTERNALNAME = sInternalName/>
EVENT
 <PUBLIC:EVENT
 NAME = sName
 ID = sEventID/>


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
 <scriptlet
 id=idBehavior>	
 •••
 <PUBLIC:HTC 
 URN="www.microsoft.com">
 •••
Receiving notifications
 </scriptlet>
 attachNotification
 (onNotify);
 function onNotify
 (sNotification) {...}
 </PUBLIC:HTC> 
 <PUBLIC:ATTACH
 EVENT=oncontentchange
 HANDLER=oncontentchangeHandler /> 
 function oncontentchangeHandler 
 () {...}
Exposing and firing custom events
 <implements
 type="Behavior"
 default>
 <event name=onExecute/>
 </implements>
 <script>
 oEvent =
 createEventObject();
 oEvent.result = 
 sResult;
 fireEvent 
 ("onExecute",oEvent); 
 </script> 
 <PUBLIC:EVENT ID=exec
 NAME=onExecute />
 	
 <SCRIPT>
 oEvent = createEventObject();
 oEvent.result = sResult;
 exec.fire (oEvent);
 </SCRIPT>
Exposing properties and methods
 <implements
 type="Behavior"
 default>
 <property name=delay/>
 <method 
 name=startFlying />
 </implements>
 <PUBLIC:PROPERTY NAME=delay />
 <PUBLIC:METHOD NAME="startFlying" />


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);
 };