2025-04-27 07:49:33 -04:00

97 lines
3.3 KiB
HTML

<HTML>
<HEAD><TITLE>Content Rotator Sample ASP Object</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF" LINK="#000080" VLINK="#808080">
<a name="content-rotator"></a>
<h1>Content Rotator</h1>
The Content Rotator is a simple but useful ASP object built with
Microsoft's <a href="http://www.microsoft.com/visualc/prodinfo/">
ActiveX Template Library 1.1 (ATL)</a>.
<p>
The object was created with the the ATL COM AppWizard. It contains four
methods that were added by hand to the IDL file (ContRot.idl), the object's
header file (RotObj.h), and the object's C++ implementation file
(RotObj.cpp):
<ul>
<li> <code>HRESULT OnStartPage(IUnknown* pUnk)</code>
<li> <code>HRESULT OnEndPage()</code>
<li> <code>HRESULT ChooseContent(BSTR bstrDataFile, BSTR* pbstrRetVal)</code>
<li> <code>HRESULT GetAllContent(BSTR bstrDataFile)</code>
</ul>
<a name="on-start-end-page"></a>
<h2>OnStartPage and OnEndPage</h2>
<code>OnStartPage</code> and <code>OnEndPage</code> are two
optional methods that ASP calls on an object whenever a page is
opened or closed by the user's Web browser. The OnStartPage
method can use the <code>IScriptingContext</code> interface to
retrieve a pointer to an interface pointer of a built-in object
that enables a component to access that object's collections,
methods, and properties.
<h2>ChooseContent</h2>
<code>ChooseContent</code> reads a collection of weighted entries from
<code>bstrDataFile</code> and returns one entry in <code>pbstrRetVal</code>.
Each entry is a piece of HTML text. It can be used as:
<ul>
<li> a tip-of-the-day generator
<li> a random advertisement billboard
<li> a poor man's load-balancing scheme for selecting email names of Tech
Support people.
</ul>
<p>
A data file for the Content Rotator looks like this:
<pre>
%% // Tech Support people
&lt;a href="mailto:jsmith"&gt;John Smith&lt;/a&gt;, Tech Lead
%%
&lt;a href="mailto:bkidd"&gt;Billy (the) Kidd&lt;/a&gt;, Trouble Shooter
%% #3 // Jane is full-time, so make her the likeliest to be chosen
&lt;a href="mailto:jdoe"&gt;Jane Doe&lt;/a&gt;, Product Support
%% // Scare 'em away. Bwah ha ha!
Sorry. Tech Support&lt;br&gt;
is&lt;br&gt;
on&lt;br&gt;
&lt;b&gt;Strike!&lt;/b&gt;
</pre>
It contains a number of weighted entries. The entries are HTML text. Each
entry starts with one or more lines beginning with <code>%%</code>. If the
<code>%%</code> line doesn't have anything on it (as in the one for Billy
Kidd), then the entry's weight is one. If there's a number preceded by a
<code>#</code> (as in the Jane Doe example), then that's the weight.
Comments on the <code>%%</code> line start with <code>//</code>.
<p>
The probability of an entry's being chosen by the Content Rotator is its
weight divided by the sum of the weights of all the entries (usually
1/<i>n</i>).
<h2>GetAllContent</h2>
<code>GetAllContent</code> reads a collection of weighted entries from
<code>bstrDataFile</code> and writes all the entries back to the user's
browser, each one separated by a horizontal rule (an &lt;HR&gt; tag), so
that it can be proofread.
<h2>Demos</h2>
Click here to run a demonstration of the <a href="Fortunes.asp">
<code>ChooseContent</code></a> method.
<p>
Click here to run a demonstration of the <a href="cr-proof.asp">
<code>GetAllContent</code></a> method.
</BODY>
</HTML>