<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 - Entries tagged with Halloween</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Tags/halloween/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9 - Entries tagged with Halloween</title>
      <link>http://channel9.msdn.com/Tags/halloween</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Tags/halloween</link>
    <language>en</language>
    <pubDate>Sat, 18 May 2013 16:30:20 GMT</pubDate>
    <lastBuildDate>Sat, 18 May 2013 16:30:20 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>15</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Test of Terror: A Channel 9 Halloween Bedtime Story</title>
      <description><![CDATA[<p>Halloween has arrived yet again and the time for scary stories and fright fests has begun. Let Microsoft haunt your dreams and please enjoy the latest addition to our Halloween Series...which may or may NOT be fictional. Happy haunting- have a spooky day!</p><p>Here's some of our past terrifying short films...</p><p><a href="http://channel9.msdn.com/Blogs/LauraFoy/Bug-Killer--A-Channel-9-Halloween-special">Bug Killer</a></p><p><a href="http://channel9.msdn.com/posts/The-Killer-App-A-Channel-9-Halloween-Special">The Killer App</a></p><p><a href="http://channel9.msdn.com/posts/Kinect-to-Kill-A-Channe-9-Halloween-Special">Kinect to Kill</a></p><p>&nbsp;</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:6a38ed7423154f929f3da0f901043eb1">]]></description>
      <comments>http://channel9.msdn.com/Blogs/LauraFoy/Test-of-Terror-A-Channel-9-Halloween-Bedtime-Story</comments>
      <itunes:summary>Halloween has arrived yet again and the time for scary stories and fright fests has begun. Let Microsoft haunt your dreams and please enjoy the latest addition to our Halloween Series...which may or may NOT be fictional. Happy haunting- have a spooky day! Here&#39;s some of our past terrifying short films... Bug Killer The Killer App Kinect to Kill &amp;nbsp; </itunes:summary>
      <itunes:duration>394</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/LauraFoy/Test-of-Terror-A-Channel-9-Halloween-Bedtime-Story</link>
      <pubDate>Wed, 31 Oct 2012 02:43:03 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/LauraFoy/Test-of-Terror-A-Channel-9-Halloween-Bedtime-Story</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012.mp3" expression="full" duration="394" fileSize="6317613" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012.mp4" expression="full" duration="394" fileSize="37311418" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012.webm" expression="full" duration="394" fileSize="16560922" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012.wma" expression="full" duration="394" fileSize="3207295" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012.wmv" expression="full" duration="394" fileSize="48568745" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012_high.mp4" expression="full" duration="394" fileSize="81170612" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012_mid.mp4" expression="full" duration="394" fileSize="56895412" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012_Source.wmv" expression="full" duration="394" fileSize="388669386" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012.ism/manifest" expression="full" duration="394" fileSize="8446" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/1bce/7d4821a9-d66e-4fe9-847b-5d6d83da1bce/Halloween2012.wmv" length="48568745" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Laura Foy</dc:creator>
      <itunes:author>Laura Foy</itunes:author>
      <slash:comments>18</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/LauraFoy/Test-of-Terror-A-Channel-9-Halloween-Bedtime-Story/RSS</wfw:commentRss>
      <category>Halloween</category>
    </item>
  <item>
      <title>Kinect to Kill: A Channel 9 Halloween Special</title>
      <description><![CDATA[<p>It's that time of year again...when the ghost and the goblins come knocking at your door. This year we invite you to watch a story about friendships, love, horror and of course- a crazy serial killer! Enjoy!</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:cb58578dba6c4ba581679f8b002f5c29">]]></description>
      <comments>http://channel9.msdn.com/posts/Kinect-to-Kill-A-Channe-9-Halloween-Special</comments>
      <itunes:summary>It&#39;s that time of year again...when the ghost and the goblins come knocking at your door. This year we invite you to watch a story about friendships, love, horror and of course- a crazy serial killer! Enjoy! </itunes:summary>
      <itunes:duration>491</itunes:duration>
      <link>http://channel9.msdn.com/posts/Kinect-to-Kill-A-Channe-9-Halloween-Special</link>
      <pubDate>Sat, 29 Oct 2011 18:30:51 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/posts/Kinect-to-Kill-A-Channe-9-Halloween-Special</guid>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_2MB_ch9.wmv" expression="full" duration="491" fileSize="476368040" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_ch9.mp3" expression="full" duration="491" fileSize="3935822" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_ch9.webm" expression="full" duration="491" fileSize="41763968" type="video/webm" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_ch9.wma" expression="full" duration="491" fileSize="3982275" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_ch9.wmv" expression="full" duration="491" fileSize="106696379" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_high_ch9.mp4" expression="full" duration="491" fileSize="129625236" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_low_ch9.mp4" expression="full" duration="491" fileSize="48579885" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_med_ch9.mp4" expression="full" duration="491" fileSize="97646763" type="video/mp4" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011.ism/manifest" expression="full" duration="491" fileSize="8446" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ak.channel9.msdn.com/ch9/5c29/cb58578d-ba6c-4ba5-8167-9f8b002f5c29/halloween2011_ch9.wmv" length="106696379" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Laura Foy</dc:creator>
      <itunes:author>Laura Foy</itunes:author>
      <slash:comments>34</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/posts/Kinect-to-Kill-A-Channe-9-Halloween-Special/rss</wfw:commentRss>
      <category>Halloween</category>
    </item>
  <item>
      <title>The Killer App: A Channel 9 Halloween Special</title>
      <description><![CDATA[ <p>Windows Phone 7 is almost here and developers are working hard to get the #1 app in the marketplace. Journalists and reporters are scouring the internet to find the next big thing- the Windows Phone 7&nbsp;Killer App. But that phrase takes on a whole new meaning around Halloween...be careful what you download! Happy Halloween!</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:db4adc1177d94b0f82749e1d013ae749">]]></description>
      <comments>http://channel9.msdn.com/posts/The-Killer-App-A-Channel-9-Halloween-Special</comments>
      <itunes:summary> Windows Phone 7 is almost here and developers are working hard to get the #1 app in the marketplace. Journalists and reporters are scouring the internet to find the next big thing- the Windows Phone 7&amp;nbsp;Killer App. But that phrase takes on a whole new meaning around Halloween...be careful what you download! Happy Halloween! </itunes:summary>
      <itunes:duration>425</itunes:duration>
      <link>http://channel9.msdn.com/posts/The-Killer-App-A-Channel-9-Halloween-Special</link>
      <pubDate>Fri, 29 Oct 2010 04:02:48 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/posts/The-Killer-App-A-Channel-9-Halloween-Special</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_2MB_ch9.wmv" expression="full" duration="425" fileSize="322070806" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_ch9.mp3" expression="full" duration="425" fileSize="3408174" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_ch9.mp4" expression="full" duration="425" fileSize="47079596" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_ch9.wma" expression="full" duration="425" fileSize="3456573" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_ch9.wmv" expression="full" duration="425" fileSize="93543981" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/e749/db4adc11-77d9-4b0f-8274-9e1d013ae749/KillerApp_ch9.wmv" length="93543981" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Laura Foy</dc:creator>
      <itunes:author>Laura Foy</itunes:author>
      <slash:comments>33</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/posts/The-Killer-App-A-Channel-9-Halloween-Special/rss</wfw:commentRss>
      <category>Halloween</category>
      <category>Windows Phone 7</category>
      <category>WP7</category>
    </item>
  <item>
      <title>Ping 80: Office 365, Ozzie blogs, Oprah loves Kinect, Re-Tweeting Fail</title>
      <description><![CDATA[ <p>It's the best time of the year! Time for ghosts, goblins and hot stories from the land of Microsoft.On this episode of Ping, Laura &amp; Paul bring you all the news...with as straight faces as possible,</p><p><a href="http://cnettv.cnet.com/microsoft-explains-office-365/9742-1_53-50094746.html">Office 365 is here!</a></p><p><a href="http://www.ozzie.net">Ozzie Blogs! Rockin!</a></p><p><a href="http://www.techflash.com/seattle/2010/10/oprah-gives-away-xbox-360s-kinect-audi.html?ana=from_rss&amp;utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A&#43;TechFlash_ToddBishop&#43;%28TechFlash&#43;-&#43;Todd&#43;Bishop%27s&#43;Microsoft&#43;Blog%29">Oprah knows best</a></p><p><a href="http://gizmodo.com/5668013/one-politicians-incredibly-unfortunate-tweet">The dangers of re-tweeting</a></p><p>&nbsp;</p><p>Happy Halloween!</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:e4c9725b693544ed9a079e1a016bf1dd">]]></description>
      <comments>http://channel9.msdn.com/Shows/PingShow/Ping-80-Office-365-Ozzie-blogs-Oprah-loves-Kinect-Re-Tweeting-Fail</comments>
      <itunes:summary> It&#39;s the best time of the year! Time for ghosts, goblins and hot stories from the land of Microsoft.On this episode of Ping, Laura &amp;amp; Paul bring you all the news...with as straight faces as possible, Office 365 is here! Ozzie Blogs! Rockin! Oprah knows best The dangers of re-tweeting &amp;nbsp; Happy Halloween! </itunes:summary>
      <itunes:duration>751</itunes:duration>
      <link>http://channel9.msdn.com/Shows/PingShow/Ping-80-Office-365-Ozzie-blogs-Oprah-loves-Kinect-Re-Tweeting-Fail</link>
      <pubDate>Tue, 26 Oct 2010 00:59:58 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Shows/PingShow/Ping-80-Office-365-Ozzie-blogs-Oprah-loves-Kinect-Re-Tweeting-Fail</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_2MB_ch9.wmv" expression="full" duration="751" fileSize="234553975" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_ch9.mp3" expression="full" duration="751" fileSize="6016585" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_ch9.mp4" expression="full" duration="751" fileSize="82681845" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_ch9.wma" expression="full" duration="751" fileSize="6088077" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_ch9.wmv" expression="full" duration="751" fileSize="165881937" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/f1dd/e4c9725b-6935-44ed-9a07-9e1a016bf1dd/Ping80_ch9.wmv" length="165881937" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Laura Foy</dc:creator>
      <itunes:author>Laura Foy</itunes:author>
      <slash:comments>10</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Shows/PingShow/Ping-80-Office-365-Ozzie-blogs-Oprah-loves-Kinect-Re-Tweeting-Fail/RSS</wfw:commentRss>
      <category>Halloween</category>
      <category>Kinect</category>
      <category>PingShow</category>
      <category>Ray Ozzie</category>
      <category>Office 365</category>
    </item>
  <item>
      <title>Share Your Windows 7 Desktop With the Ghouls and Ghosts of Eerie Autumn</title>
      <description><![CDATA[ <p>October is the spookiest month of the year, fact. As the warmth of the <em>season of mists and mellow fruitfulness</em>s is grasped by the ice-cold fingers of winter, the days become shorter, the nights longer and the earth spins slowly into the “dark half” of the year.</p><p>That’s according to the Celts, who celebrated the festival of Samhain on October 31<sup>st</sup> to mark the end of the “lighter half” of the year and start of the “darker half”. According to <a href="http://en.wikipedia.org/wiki/Halloween">Wikipedia</a>, the ancient Celts believed that the border between this world and the&nbsp;<a title="Otherworld" href="http://en.wikipedia.org/wiki/Otherworld">Otherworld</a>&nbsp;became thin on Samhain, allowing spirits (both harmless and harmful) to pass through. The family's ancestors were honoured and invited home while harmful spirits were warded off. It is believed that the need to ward off harmful spirits led to the wearing of&nbsp;<a title="Costumes" href="http://en.wikipedia.org/wiki/Costumes">costumes</a>&nbsp;and&nbsp;<a title="Masks" href="http://en.wikipedia.org/wiki/Masks">masks</a>. Their purpose was to disguise oneself as a harmful spirit and thus avoid harm. </p><p>Nowadays, in many countries, Halloween is celebrated at the end of October, and if you and the family are preparing the apples for bobbing, pumpkins for carving, and costumes for wearing, or if you simply want to bring the spookiness of October to your desktop, then make sure you check out the Windows 7 Eerie Autumn theme.</p><p>Shiver at the sights of 15 creepy wallpapers, scream in terror at spooky sounds which greet every email and USB connection, but beware! &nbsp;Gargoyles, gourds, and ghostly creatures haunt <a href="http://windows.microsoft.com/en-US/windows/downloads/eerie-autumn">this eerily elegant Windows 7 theme</a>.</p><p>Now where did I leave that cape?</p><p>&nbsp;</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:1cdea4bf30664325a4af9e1700c30dff">]]></description>
      <comments>http://channel9.msdn.com/Blogs/coolstuff/Share-Your-Windows-7-Desktop-With-the-Ghouls-and-Ghosts-of-Eerie-Autumn</comments>
      <itunes:summary> October is the spookiest month of the year, fact. As the warmth of the season of mists and mellow fruitfulnesss is grasped by the ice-cold fingers of winter, the days become shorter, the nights longer and the earth spins slowly into the “dark half” of the year. That’s according to the Celts, who celebrated the festival of Samhain on October 31st to mark the end of the “lighter half” of the year and start of the “darker half”. According to Wikipedia, the ancient Celts believed that the border between this world and the&amp;nbsp;Otherworld&amp;nbsp;became thin on Samhain, allowing spirits (both harmless and harmful) to pass through. The family&#39;s ancestors were honoured and invited home while harmful spirits were warded off. It is believed that the need to ward off harmful spirits led to the wearing of&amp;nbsp;costumes&amp;nbsp;and&amp;nbsp;masks. Their purpose was to disguise oneself as a harmful spirit and thus avoid harm.  Nowadays, in many countries, Halloween is celebrated at the end of October, and if you and the family are preparing the apples for bobbing, pumpkins for carving, and costumes for wearing, or if you simply want to bring the spookiness of October to your desktop, then make sure you check out the Windows 7 Eerie Autumn theme. Shiver at the sights of 15 creepy wallpapers, scream in terror at spooky sounds which greet every email and USB connection, but beware! &amp;nbsp;Gargoyles, gourds, and ghostly creatures haunt this eerily elegant Windows 7 theme. Now where did I leave that cape? &amp;nbsp; </itunes:summary>
      <link>http://channel9.msdn.com/Blogs/coolstuff/Share-Your-Windows-7-Desktop-With-the-Ghouls-and-Ghosts-of-Eerie-Autumn</link>
      <pubDate>Fri, 22 Oct 2010 11:53:47 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/coolstuff/Share-Your-Windows-7-Desktop-With-the-Ghouls-and-Ghosts-of-Eerie-Autumn</guid>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/60e128cf-d50b-479b-885a-15a3d452f6d9.jpg" height="66" width="100"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/15c5751c-90be-487f-b568-b8bf035f7ac5.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/b30bc3d1-9ced-4421-a9e0-0599445648df.jpg" height="240" width="320"></media:thumbnail>      
      <dc:creator>Terry Walsh</dc:creator>
      <itunes:author>Terry Walsh</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/coolstuff/Share-Your-Windows-7-Desktop-With-the-Ghouls-and-Ghosts-of-Eerie-Autumn/RSS</wfw:commentRss>
      <category>Halloween</category>
      <category>theme</category>
      <category>Themes</category>
      <category>Windows 7</category>
      <category>Windows7</category>
    </item>
  <item>
      <title>Halloween Gremlins</title>
      <description><![CDATA[
<p>This article describes a quick and easy application to play Halloween tricks on the PC.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9915768/clip_image001_2.jpg"><img title="clip_image001" border="0" alt="clip_image001" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9915768/clip_image001_thumb.jpg" width="282" height="135"></a></p>
<h3>Introduction</h3>
<p>This article describes “Gremlin”, a quick and easy application that lets you play Halloween tricks. When your victim's computer is idle, Gremlin moves windows around on the screen, changes the focus window, moves your mouse, scrolls windows, and types nonsensical
 stuff. When there is background noise – like someone talking – it will shake the screen, even as your victim is typing away.</p>
<h3>Deployment</h3>
<p><b>Run it right away</b>. You can download, copy theGremlin.exe executable and NAudio.dll to the victim's computer (say in c:\ directory), and then double click on the executable to run it.</p>
<p><b>Run it later.</b> The other option is to copy the executable and dll files (or a shortcut to it) to the Startup folder on the victim's machine and watch the fun begin when they start up their machine in the morning!</p>
<p>If the computer you're using runs on Windows XP the path is: </p>
<blockquote>
<p>C:\Documents and Settings\All Users\Start Menu\Programs\Startup</p>
</blockquote>
<p>With Vista and Windows 7 the path looks like: </p>
<blockquote>
<p>C:\Users\<i>USERNAME</i>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup</p>
</blockquote>
<p>Just remember to change <i>USERNAME</i> to the name of the user on your machine.</p>
<p></p>
<h4>Commandline</h4>
<p>Gremlin is compiled as a windows application, so it won't popup a terminal window if you double click on it, etc. But you can run it from the command line with flags:</p>
<blockquote>
<p><b>-aggressive</b> will make the gremlin's actions more obvious</p>
<p><b>-help</b> will display the command line options</p>
<p><b>-name</b> <i>NAME</i> is useful for testing. Gremlin will only use windows with this specific title or from this specific application. (Remember to drop the &quot;.exe&quot; from the application filename)</p>
</blockquote>
<p>To stop the program, press CTRL&#43;F2.</p>
<h3>And now … the dodgy bits</h3>
<p>The overall structure of the program is broken down into three kinds of functionality – actions, triggers and some interstitial glue:</p>
<p>Actions</p>
<ul>
<li>The screen-shaker is a window that makes the monitor look like it is shaking. Sort of like a loose cable on the back of the monitor.
</li><li>A random event might kick the windows around—either friction will slow them down, or...
</li><li>Gremlin will type nonsensical messages from the keyboard. These messages are then sent from a virtual keyboard, or they:
</li><li>Move the mouse around, or </li><li>Press the mouse buttons, or </li><li>Randomly switch the focus to another window </li></ul>
<p>Triggers</p>
<ul>
<li>An audio module listens for sounds that trigger the module that shakes your screen.
</li><li>Otherwise, the software uses a p/invoke to <strong>GetLastInputInfo()</strong> and waits for the user to be idle for a minute or two. When it detects that the user is inactive, it randomly selects and carries out actions.
</li></ul>
<p>Other</p>
<ul>
<li>A hidden window receives key press events. I tend to reuse this module a lot, as a way to
<i>stop</i> experimental programs that may have made my machine unusable. </li></ul>
<p>For fun, I'll describe a couple of these modules below.</p>
<p></p>
<h4>Screen shaker</h4>
<p>My favorite bit is the screen shaker. It grabs a picture of the screens, creates a window that spreads across them, and then moves that image back and forth a few pixels every 30ms or so, with a little bit of random rotation. (Faster computers, of course,
 get a better effect).</p>
<p>The screen shaker is special in four ways:</p>
<ul>
<li>It is a top-level window – no other windows are allowed to go over it. </li><li>This top-level window never becomes the focus window (the window that gets the keyboard events).
</li><li>Mouse button events (e.g. clicks and double-clicks) are passed through to the windows and desktop underneath. This gives the illusion that this is the &quot;real&quot; desktop shaking, by allowing a person to click on a button or text that passes the click thru to
 the <i>real</i> button or text. </li><li>It shakes each of the monitor's screens independently </li></ul>
<p>Some background: to create a window that looks like the shaking screen, I used two classes. The first is ScrShake (in ScreenShake.cs), which derives from the second class UnfocusableForm.&nbsp; I'll describe ScrShake first.</p>
<p>The screen shaking process requires five instance variables:</p>
<ul>
<li><i>animTimer</i> is a System.Windows.Forms.Timer used to force painting of a new frame on the screen.
</li><li><i>bx</i>, and <i>by </i>are how far the screen has shaken up or down, left or right.
</li><li><i>angle </i>is how much the screen has twisted during shaking. </li><li><i>screenBitmap</i> is an array of bitmaps, one for each of the monitors. </li></ul>
<p>This creates a window without a border or other trappings, then makes it the topmost window and sets a flag in the method variable ExStyle to ignore mouse clicks. More on this flag in a little while.</p>
<p></p>
<p><b>C# <br>
</b></p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> ScrShake : UnfocusableForm
{
   <span class="kwrd">public</span> ScrShake(<span class="kwrd">double</span> ShakeCoef, <span class="kwrd">double</span> AngleCoef) : <span class="kwrd">base</span>(<span class="kwrd">true</span>)
   {
      <span class="kwrd">this</span>.SuspendLayout();
      … other setup code …
      <span class="rem">// This is needed since we're over the whole display, and we don't</span>
      <span class="rem">// want the other areas to be blurry</span>
      TransparencyKey =  BackColor = ForeColor = System.Drawing.Color.Fuchsia;
      DoubleBuffered = <span class="kwrd">true</span>;
      TopMost = <span class="kwrd">true</span>;
      FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

      ClientSize = <span class="kwrd">new</span> System.Drawing.Size(300, 300);
      Name = <span class="str">&quot;topimage&quot;</span>;
      ResumeLayout(<span class="kwrd">false</span>);

      <span class="rem">// This is need to pass mouse clicks thru to lower layers</span>
      ExStyle |= (<span class="kwrd">int</span>) WS . EX_TRANSPARENT;

      … More code that will be described later…
   }
}</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b><br>
</b></p>
<p>When the timer has done a given number of animations, it will call the Stop() method. This will stop the animation, clean it up, and hide the window:</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">void</span> Stop()
{
   animTimer . Stop();
   Hide();
   screenBitmap = <span class="kwrd">null</span>;
}</pre>
<p>When the main loops that start the animated screen shaking process, it calls the Screens() method. This grabs an image of the screens, determines the shape of each monitor, and starts the animation for 10 frames.</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">internal</span> <span class="kwrd">void</span> Screens()
{
   <span class="kwrd">if</span> (Visible)
   {
      Stop();
      <span class="kwrd">return</span> ;
   }
   <span class="rem">// Grab the screens</span>
   screenBitmap = Program.GrabScreens();
   CountDown = 10;

   animTimer.Start();
   angle = 0.0f;
   … code to display the window and get shape of monitors (see below)…
}</pre>
<p><b><br>
</b></p>
<p>The screen capture portion is in ScreenCapture.cs. The method GrabScreens() creates an individual bitmap for each monitor and returns them as an array.</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">internal</span> <span class="kwrd">void</span> Screens()
{
   <span class="kwrd">if</span> (Visible)
   {
      Stop();
      <span class="kwrd">return</span> ;
   }
   <span class="rem">// Grab the screens</span>
   screenBitmap = Program.GrabScreens();
   CountDown = 10;

   animTimer.Start();
   angle = 0.0f;
   … code to display the window and get shape of monitors (see below)…
}</pre>
<p><b><br>
</b></p>
<p>The code below determines the bounds of each screen and builds up a size of all of the screens put together. The window will be set to be this size.
</p>
<p><b>C# </b></p>
<pre class="csharpcode">Screen[] AllScreens = Screen.AllScreens;

<span class="rem">// full width/height of all monitors combined</span>
Rectangle fullSize = AllScreens[0].Bounds;

<span class="rem">// find a rectangle that will encompass all monitors on the system</span>
<span class="rem">// (assuming the primary monitor is on the left/top!)</span>
<span class="kwrd">for</span> (<span class="kwrd">int</span> i = 1; i &lt; AllScreens.Length &amp;&amp; i &lt; screenBitmap.Length; i&#43;&#43;)
{
    Rectangle Bounds = AllScreens[i].Bounds;

    <span class="kwrd">if</span> (Bounds.Left &lt; fullSize.Left)
        fullSize.X = Bounds.X;

    <span class="kwrd">if</span> (Bounds.Right &gt; fullSize.Right)
        fullSize.Width = Bounds.Right - fullSize.X;

    <span class="kwrd">if</span> (Bounds.Top &lt; fullSize.Top)
        fullSize.Y = Bounds.Y;

    <span class="kwrd">if</span> (Bounds.Bottom &gt; fullSize.Bottom)
        fullSize.Height = Bounds.Bottom - fullSize.Y;
}</pre>
<p>The code to show the window, fill the whole screen, and move it to the top looks like:</p>
<p><b>C# </b></p>
<pre class="csharpcode">Show();
WindowState = FormWindowState.Normal;
<span class="rem">// cover all monitors with one gigantic window</span>
Location = <span class="kwrd">new</span> Point(fullSize.Left, fullSize.Top);
Size = <span class="kwrd">new</span> Size(fullSize.Width, fullSize.Height);

<span class="rem">// bring it to the top</span>
BringToFront();</pre>
<p>The constructor also created a timer that drives the screen shaking effect. The timer has a delegate that randomly selects the angle of rotation and the offset of the image, and triggers a repaint of the window. (The amount of shaking is controlled by two
 external variables called <i>AngleCoef</i> and <i>ShakeCoef</i>).</p>
<p><b>C# </b></p>
<pre class="csharpcode">animTimer = <span class="kwrd">new</span> System.Windows.Forms.Timer();
animTimer.Tick &#43;= <span class="kwrd">delegate</span>(<span class="kwrd">object</span> A, EventArgs E)
{
    <span class="kwrd">if</span> (--CountDown &lt; 1)
        Stop();

    angle &#43;= (<span class="kwrd">float</span>)((Program.Rnd.NextDouble() - 0.5) * AngleCoef);
    bx = (<span class="kwrd">float</span>)((Program.Rnd.NextDouble() - 0.5) * ShakeCoef);
    by = (<span class="kwrd">float</span>)((Program.Rnd.NextDouble() - 0.5) * ShakeCoef);
    Invalidate();
};

<span class="rem">// Sets the timer interval to 30 milliseconds.</span>
animTimer.Interval = 30;</pre>
<p>Although each monitor shifts up &amp; down, left &amp; right by the same amount, and rotates by the same angle, they are painted independently. This gives the illusion that each monitor has a shaky image. Paint the window is using the following code.
</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnPaint(PaintEventArgs e)
{
    <span class="kwrd">base</span>.OnPaint(e);
    Graphics g = e.Graphics;
    g.CompositingQuality = CompositingQuality.HighQuality;

    <span class="rem">// for each monitor, draw the effect</span>
    Screen[] AllScreens = Screen.AllScreens;
    <span class="kwrd">for</span>(<span class="kwrd">int</span> i = 0; i &lt; screenBitmap.Length; i&#43;&#43;)
    {
        <span class="kwrd">if</span> (<span class="kwrd">null</span> == screenBitmap[i])&nbsp;&nbsp; <span class="kwrd">continue</span>;
        g.SmoothingMode = SmoothingMode.HighQuality;

        <span class="rem">// grab the size of the current monitor</span>
        Rectangle region = AllScreens[i].Bounds;

        <span class="kwrd">double</span> ImWidth = screenBitmap[i].Width  * <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Graphics.DpiX / screenBitmap[i].HorizontalResolution;
        <span class="kwrd">double</span> ImHeight= screenBitmap[i].Height * <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Graphics.DpiY / screenBitmap[i].VerticalResolution;
        Matrix m = <span class="kwrd">new</span> Matrix();
        m.Translate( (<span class="kwrd">float</span>)(- ImWidth  /2), 
                  (<span class="kwrd">float</span>)(- ImHeight /2), MatrixOrder.Append);

        <span class="rem">// rotate the bitmap about the center</span>
        m.RotateAt(angle, <span class="kwrd">new</span> Point(0,0), MatrixOrder.Append);

        <span class="rem">// center the image no matter what its size is</span>
        m.Translate( region.Width /2 - bx, 
                  region.Height/2 - by, MatrixOrder.Append);

        <span class="rem">// assign our transformation matrix</span>
        g.Transform = m;

        <span class="rem">// draw it</span>
        g.DrawImage(screenBitmap[i], region.Left, region.Top);
    }</pre>
<h4>The Form that does nothing!</h4>
<p>The ScrShaker class uses a help class called UnfocusableForm (in UnfocusableForm.cs) to create a window that never becomes the focus window – it never receives key presses, etc.</p>
<p>This window has no trappings – no border, no resize gripper, no icon, no minimize / maximize buttons, no title bar.</p>
<p></p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> UnfocusableForm : Form
{
   <span class="kwrd">public</span> UnfocusableForm(<span class="kwrd">bool</span> X) : <span class="kwrd">base</span>()
   {
      <span class="kwrd">if</span> (X)
        {
           ControlBox = <span class="kwrd">false</span>;
           FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
           ShowInTaskbar = <span class="kwrd">false</span>;
           ShowIcon = <span class="kwrd">false</span>;
           MinimizeBox = <span class="kwrd">false</span>;
           SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
           StartPosition = System.Windows.Forms.FormStartPosition.Manual;
        }
   }</pre>
<p>Then it overrides the ShowWithoutActivation method so that the window will <i>
not</i> become the active when it is shown.</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">bool</span> ShowWithoutActivation
{ get {  <span class="kwrd">return</span> <span class="kwrd">true</span>; } }</pre>
<p>The UnfocusableForm class also overrides the CreateParams() method to set extra styles when creating the window. I haven't found a way to set these styles flexibly. Instead, the UnfocusableForm uses a method variable called ExStyle that allows derived classes
 to specify what flags they desire. In this case, The ScrShake class used the method variable to set a flag that ignore mouse clicks:</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> CreateParams CreateParams
{
  get
  {
     CreateParams cp=<span class="kwrd">base</span>.CreateParams;
     cp . ExStyle |= ExStyle;
     <span class="kwrd">return</span> cp;
  }
}</pre>
<p><b><br>
</b>Finally, it captures a couple of events that ask a window if it would like to become the active window. (These usually happen when the user clicks on an inactive window):</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">internal</span> <span class="kwrd">const</span> <span class="kwrd">int</span> MA_NOACTIVATE = 0x0003;
<span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> WndProc(<span class="kwrd">ref</span> Message m)
{
  <span class="kwrd">if</span> (m.Msg == (<span class="kwrd">int</span>) WM.MOUSEACTIVATE)
  {
     m.Result = (IntPtr) MA_NOACTIVATE;
     <span class="kwrd">return</span>;
  }
  <span class="kwrd">if</span> (m.Msg == (<span class="kwrd">int</span>) WM.FOCUS)
  {
     m.Result = (IntPtr)1;
     <span class="kwrd">return</span>;
  }
  <span class="kwrd">base</span>.WndProc(<span class="kwrd">ref</span> m);
}</pre>
<h4>Sending Mouse Events</h4>
<p>Sending Mouse Events is simple, but not trivial. The wiki at Pinvoke.net provides the signature to the procedures and structures we need to pass to it. (Note: these structures are a bit different, based on
<a href="http://blogs.msdn.com/oldnewthing/archive/2009/08/13/9867383.aspx">a blog posting by Raymond Chen</a>)</p>
<p><b>C# </b></p>
<pre class="csharpcode">[DllImport(<span class="str">&quot;user32.dll&quot;</span>, EntryPoint = <span class="str">&quot;SendInput&quot;</span>, SetLastError = <span class="kwrd">true</span>)]
<span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">uint</span> SendInput(<span class="kwrd">uint</span> nInputs, INPUT[] Inputs, <span class="kwrd">int</span> cbSize);
[DllImport(<span class="str">&quot;user32.dll&quot;</span>, EntryPoint = <span class="str">&quot;GetMessageExtraInfo&quot;</span>, SetLastError = <span class="kwrd">true</span>)]
<span class="kwrd">static</span> <span class="kwrd">extern</span> IntPtr GetMessageExtraInfo();

[StructLayout(LayoutKind.Sequential)]
<span class="kwrd">struct</span> INPUT
{
   <span class="kwrd">internal</span> INPUTTYPE   type;
   <span class="kwrd">internal</span> INPUT_UNION i;
}

 <span class="rem">// This generates the anonymous union</span>
[StructLayout(LayoutKind.Explicit)]
<span class="kwrd">struct</span> INPUT_UNION
{
   [FieldOffset(0)]
   <span class="kwrd">public</span> MOUSEINPUT mi;
   [FieldOffset(0)]
   <span class="kwrd">public</span> KEYBDINPUT ki;
   [FieldOffset(0)]
   <span class="kwrd">public</span> HARDWAREINPUT hi;
};

[StructLayout(LayoutKind.Sequential)]
<span class="kwrd">struct</span> MOUSEINPUT
{
   <span class="kwrd">public</span> <span class="kwrd">int</span>    dx;
   <span class="kwrd">public</span> <span class="kwrd">int</span>    dy;
   <span class="kwrd">public</span> <span class="kwrd">int</span>    mouseData;
   <span class="kwrd">public</span> MOUSEEVENTF dwFlags;
   <span class="kwrd">public</span> <span class="kwrd">int</span>    time;
   <span class="kwrd">public</span> IntPtr dwExtraInfo;
}

[Flags]
<span class="kwrd">enum</span> MOUSEEVENTF : <span class="kwrd">int</span>
{
   MOVE       = 0x01,
   LEFTDOWN   = 0x02,
   LEFTUP     = 0x04,
   RIGHTDOWN  = 0x08,
   RIGHTUP    = 0x10,
   MIDDLEDOWN = 0x20,
   MIDDLEUP   = 0x40,
   ABSOLUTE   = 0x8000
}</pre>
<p><b><br>
</b></p>
<p>Each of these pieces go together in a specific way. To do a mouse movement, a mouse event structure needs to be created. This involves setting dwFlags to the kind of mouse event (a relative movement in this case), dx and dy to the number of pixels moved.
 It is also important to set dwExtraInfo to whatever GetMessageExtraInfo() is set to.</p>
<p><b>C# </b></p>
<pre class="csharpcode">MOUSEINPUT MEvent = <span class="kwrd">new</span> MOUSEINPUT();
MEvent.dwFlags = MOUSEEVENTF.MOVE;
MEvent.dx = Rnd . Next(-8, 8) ;
MEvent.dy = Rnd . Next(-8, 8);
MEvent.dwExtraInfo = GetMessageExtraInfo();
Send(MEvent);</pre>
<p>Sending the event takes a few more steps that are all wrapped in a helper methdo called Send(). Send these
<i>human interface device</i> events via the SendInput() procedure (earlier). The procedure takes an array of events, for different kinds of devices. We have to create the array, set the event type, copy the event data, and then make the call:</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">bool</span> Send(MOUSEINPUT Event)
{
  INPUT[] Events = <span class="kwrd">new</span> INPUT[1];
  Events[0] . type = INPUTTYPE . MOUSE;
  Events[0] . i.mi = MEvent;
  <span class="kwrd">return</span> SendInput((<span class="kwrd">uint</span>)Events.Length, Events, Marshal.SizeOf(Events[0])) &gt; 0; 
}</pre>
<p><b><br>
</b></p>
<p>From here, sending a mouse button click is pretty straight forward. A mouse click is really a mouse button press event, followed by a mouse button release event. To make things interesting the mouse button is choosen at random. The “ugly” part is that each
 of the mouse buttons is assigned a bit, so a binary shift is used to convert a button number to its bit. And the button release is yet another bit, so the second message shifts the flags, to move the bit from the “button pressed” state to the “button released
 state”.</p>
<p><b>C# </b></p>
<pre class="csharpcode">MOUSEINPUT MEvent = <span class="kwrd">new</span> MOUSEINPUT();
MEvent.dwFlags = (MOUSEEVENTF) (1 &lt;&lt; (2*Rnd.Next(0, 3)&#43;1)) ;
MEvent.dwExtraInfo = GetMessageExtraInfo ();
Send(MEvent);

MEvent.dwFlags = (MOUSEEVENTF)((<span class="kwrd">int</span>) MEvent.dwFlags &lt;&lt; 1);
MEvent.dwExtraInfo = GetMessageExtraInfo ();
Send(MEvent);</pre>
<p><b><br>
</b></p>
<h4>Generating deranged text</h4>
<p>The gremlin can also type deranged sentences that will appear in editors, if the user left one open. The SendWait() method in the SendKeys class does the typing itself:</p>
<p><b>C#</b>&nbsp;</p>
<pre class="csharpcode">SendKeys . SendWait(GenerateSentence());
SendKeys . SendWait(<span class="str">&quot;{ENTER}&quot;</span>);</pre>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9915768/clip_image001_5B6_5D.jpg"><img title="clip_image001[6]" border="0" alt="clip_image001[6]" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9915768/clip_image001_5B6_5D_thumb.jpg" width="282" height="135"></a></p>
<p>Generating the sentences is not difficult; I used a simplistic Markov generator. This generator starts by randomly selecting a word that can start a sentence. The
<i>Starts</i> variable is array which holds just these words. Then, in the Transition method, this word is used to find the
<i>next</i> word that can be included in the sentence. It does this by using a dictionary, called
<i>NonStart</i>, which given the word as a key, will return a list of all the words that can come after it. This process then repeats, appending the words onto the end of a string. It stops if it finds a word that can end a sentence.</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">static</span> Dictionary&lt;<span class="kwrd">string</span>,<span class="kwrd">string</span>[]&gt; NonStart ;
<span class="kwrd">static</span> <span class="kwrd">string</span>[] Starts;
<span class="kwrd">static</span> Dictionary&lt;<span class="kwrd">string</span>,<span class="kwrd">string</span>&gt; Terminal ;

<span class="kwrd">static</span> <span class="kwrd">string</span> GenerateSentence()
{
  StringBuilder SB = <span class="kwrd">new</span> StringBuilder();
  <span class="kwrd">string</span> Word = Starts[ Rnd.Next(0, Starts.Length) ];

  Transition(SB, Word);
  <span class="kwrd">return</span> SB.ToString();
}

<span class="kwrd">static</span> <span class="kwrd">void</span> Transition(StringBuilder SB, <span class="kwrd">string</span> Word)
{
  <span class="kwrd">while</span> (<span class="kwrd">true</span>)
  {
     SB.Append(Word);
     SB.Append(<span class="str">' '</span>);

     <span class="rem">// Look up word after this</span>
     <span class="kwrd">string</span>[] Nexts;
     <span class="kwrd">if</span> (!NonStart.TryGetValue(Word, <span class="kwrd">out</span> Nexts))
       <span class="kwrd">break</span>;
     <span class="kwrd">int</span> Idx = Rnd.Next(Terminal . ContainsKey(Word) ? -1 :0, Nexts.Length);
     <span class="kwrd">if</span> (Idx &lt; 0)
       <span class="kwrd">break</span>;
     Word = Nexts[Idx];
  }
}</pre>
<p><b><br>
</b></p>
<p>Building these two dictionaries and array is a pretty simple process. The BuildSuffixTree() method takes a string and splits it up into sentences. Then it splits each sentence into (lower case) words. The first word of the sentence goes onto the end of the
<i>Starts</i> array. Otherwise, the previous word is used to look up a list in a dictionary, and the current word is appended on to the list. This dictionary will become the
<i>NonStarts</i> dictionary. The last word of the sentence is also placed into the
<i>Terminal</i> dictionary, to indicate that this might be the end of a sentence.</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">static</span> <span class="kwrd">void</span> BuildSuffixTree()
{
  <span class="rem">// First, build up a list of words that start sentence, and transitions</span>
  List&lt;<span class="kwrd">string</span>&gt; Starts1 = <span class="kwrd">new</span> List&lt;<span class="kwrd">string</span>&gt;();
  Dictionary&lt;<span class="kwrd">string</span>,List&lt;<span class="kwrd">string</span>&gt;&gt; Trans = <span class="kwrd">new</span> Dictionary&lt;<span class="kwrd">string</span>,List&lt;<span class="kwrd">string</span>&gt;&gt;();
  <span class="kwrd">foreach</span>(<span class="kwrd">string</span> S1 <span class="kwrd">in</span> S.Split(<span class="kwrd">new</span> <span class="kwrd">char</span>[]{<span class="str">'.'</span>,<span class="str">'?'</span>,<span class="str">'!'</span>}))
  {
     <span class="kwrd">string</span> Prev=<span class="kwrd">null</span>;
     <span class="kwrd">foreach</span>(<span class="kwrd">string</span> S2 <span class="kwrd">in</span> S1.Split(<span class="kwrd">new</span> <span class="kwrd">char</span>[]{<span class="str">' '</span>,<span class="str">'\n'</span>,<span class="str">'\r'</span>,<span class="str">'\t'</span>,<span class="str">','</span>,<span class="str">';'</span>}))
     {
        <span class="kwrd">if</span> (S2 . Length &lt; 1)
          <span class="kwrd">continue</span>;
        <span class="kwrd">if</span> (<span class="kwrd">null</span> == Prev)
          {
             Starts1.Add(<span class="kwrd">string</span>.Intern(S2.ToLower()));
             Prev = <span class="kwrd">string</span>.Intern(S2.ToLower());
             <span class="kwrd">continue</span>;
          }
        List&lt;<span class="kwrd">string</span>&gt; Nextsa;
        <span class="kwrd">if</span> (! Trans.TryGetValue(Prev, <span class="kwrd">out</span> Nextsa))
          Trans[Prev] = Nextsa = <span class="kwrd">new</span> List&lt;<span class="kwrd">string</span>&gt;();
        Prev = <span class="kwrd">string</span>.Intern(S2.ToLower());
        Nextsa.Add(Prev);
     }
     <span class="kwrd">if</span> (<span class="kwrd">null</span> != Prev)
       Terminal[Prev] = Prev;
 }

 <span class="rem">// Next, flatten the list of words that start a sentence</span>
 Starts = Starts1.ToArray();

 <span class="rem">// Flatten the transition table</span>
 <span class="kwrd">foreach</span> (<span class="kwrd">string</span> S3 <span class="kwrd">in</span> Trans.Keys)
  NonStart[S3] = Trans [S3].ToArray();
}</pre>
<p><b><br>
</b></p>
<h3>The things that trigger action</h3>
<h4>The audio trigger</h4>
<p>The audio module (in file AudioTrigger.cs) listens in on all of the microphones. It uses NAudio, with a basic setup and delegate structure swiped from Mark Heath's article “.NET Audio Recording”. The first difference is that it registers
<i>all</i> audio input devices:</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">static</span> WaveIn[] StartMics()
{
  <span class="kwrd">int</span> NumDevices = WaveIn.DeviceCount;
  WaveIn[] AudIns = <span class="kwrd">new</span> WaveIn[NumDevices];
  <span class="kwrd">for</span> (<span class="kwrd">int</span> waveInDevice = 0; waveInDevice &lt; NumDevices ; waveInDevice&#43;&#43;)
  {
     AudIns[waveInDevice] = <span class="kwrd">new</span> WaveIn();
     AudIns[waveInDevice].DeviceNumber = waveInDevice;
     AudIns[waveInDevice].DataAvailable &#43;= waveIn_DataAvailable;
     AudIns[waveInDevice].WaveFormat = <span class="kwrd">new</span> WaveFormat(8000, 1);
     AudIns[waveInDevice].StartRecording();
  }
  <span class="kwrd">return</span> AudIns;
}</pre>
<p>The real magic in the trigger is a modified version of the waveIn_DataAvailable delegate. Instead of saving the audio, it checks for any sound activity. It starts by checking to see if any of the sound amplitudes are greater than a pre-defined, very high
 threshold. Then the samples are squared and summed up, and the result is compared with a threshold. If it exceeds the threshold, the trigger is set. These two are good at catching the kind of sound made when a person is talking, futzing on the desk, or typing.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9915768/clip_image002_2.jpg"><img title="clip_image002" border="0" alt="clip_image002" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9915768/clip_image002_thumb.jpg" width="372" height="210"></a></p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">static</span> <span class="kwrd">double</span> AudioThresh  = 0.8;
<span class="kwrd">static</span> <span class="kwrd">double</span> AudioThresh2 = 0.09;

<span class="kwrd">static</span> <span class="kwrd">void</span> waveIn_DataAvailable(<span class="kwrd">object</span> sender, WaveInEventArgs e)
{
  <span class="kwrd">bool</span> Tr = <span class="kwrd">false</span>;
  <span class="kwrd">double</span> Sum2  = 0;
  <span class="kwrd">int</span> Count = e.BytesRecorded / 2;
  <span class="kwrd">for</span> (<span class="kwrd">int</span> index = 0; index &lt; e.BytesRecorded; index &#43;= 2)
  {
     <span class="kwrd">double</span> Tmp = (<span class="kwrd">short</span>)((e.Buffer[index &#43; 1] &lt;&lt; 8) | e.Buffer[index &#43; 0]);
     Tmp /= 32768.0;
     Sum2 &#43;= Tmp*Tmp;
     <span class="kwrd">if</span> (Tmp &gt; AudioThresh)
       Tr = <span class="kwrd">true</span>;
  }
  Sum2 /= Count;

  <span class="rem">// If the Mean-Square is greater than a threshold, set a flag to indicate that noise has happened</span>
  <span class="kwrd">if</span> (Tr || Sum2 &gt; AudioThresh2)
    Interlocked.Exchange(<span class="kwrd">ref</span> AudioTrigger, 1);
}</pre>
<p><b><br>
</b></p>
<p>This sets a flag – AudioTrigger – which will be seen (and reset) in the main loop, with a bit of code that looks like:</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">while</span> (0 == Shutdown)
{
    <span class="rem">// Do some lovely events</span>
    Application . DoEvents();
    Thread . Sleep (20);

    <span class="rem">//… do some other stuff ..</span>

    <span class="rem">// Check for a kick from the sound system</span>
    <span class="kwrd">if</span> (0 != AudioTrigger)
    {
        Interlocked . Exchange(<span class="kwrd">ref</span> AudioTrigger, 0);
        …
        ScreenShaker . Screens();
        <span class="kwrd">continue</span>;
    }
    <span class="rem">//… more checks for the user idle trigger…</span>
}<b><br></b></pre>
<h4>Waiting for the user to be idle</h4>
<p>The check to see if the user is not doing anything, the main loop uses a helper method called LastInputTime(), which returns the number of milliseconds the user did any input activity. The loop ensures that the user has been idle for long enough, and then
 calls the method that selects random gremlin actions:</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">uint</span> LastTime = Win32.LastInputTime();
<span class="kwrd">if</span> ((<span class="kwrd">uint</span>) Environment.TickCount &lt; IdleTimeTrigger &#43; LastTime)
    <span class="kwrd">continue</span>;</pre>
<p>The LastInputTime() helper method uses a p/invoke call to the GetLastInputInfo() API call. The wiki at Pinvoke.net provides the signature to the procedure, and a suitable structure that we need to pass to it:</p>
<p><b>C# </b></p>
<pre class="csharpcode">[DllImport(<span class="str">&quot;User32.dll&quot;</span>)]
<span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">bool</span> GetLastInputInfo(<span class="kwrd">ref</span> LASTINPUTINFO LastInfo);

[StructLayout(LayoutKind.Sequential)]
<span class="kwrd">struct</span> LASTINPUTINFO
{
  <span class="kwrd">public</span> <span class="kwrd">uint</span> cbSize;

  <span class="rem">/// &lt;summary&gt;</span>
  <span class="rem">/// Number of system tickes</span>
  <span class="rem">/// &lt;/summary&gt;</span>
  <span class="kwrd">public</span> <span class="kwrd">uint</span> dwTime;
}</pre>
<p>Then, these two structures are wrapped up into the LastInputTime() helper procedure, which does the dirty work of allocating and initializing a structure.
</p>
<p><b>C# </b></p>
<pre class="csharpcode"><span class="kwrd">internal</span> <span class="kwrd">static</span> <span class="kwrd">uint</span> LastInputTime()
{
  LASTINPUTINFO lastInput=<span class="kwrd">new</span> LASTINPUTINFO();
  lastInput.cbSize = (<span class="kwrd">uint</span>)Marshal.SizeOf(lastInput);
  GetLastInputInfo(<span class="kwrd">ref</span> lastInput);
  <span class="kwrd">return</span> lastInput . dwTime;
}<b><br></b></pre>
<h3>Conclusion</h3>
<p>The tricks gremlin plays are intended to be somewhat subtle. There is an aggressive option to make it react more, and move windows around more visibly.
</p>
<p>If you want to try this out, the download link for the <a href="http://gremlin.codeplex.com/Release/ProjectReleases.aspx">
executable</a> and <a href="http://gremlin.codeplex.com/SourceControl/ListDownloadableCommits.aspx">
source code</a> are at the top of the article!</p>
<h4>Resources and References</h4>
<p>This article is a blatant grab bag of experimental and reused code from earlier experiments and other demo programs. Below are some of the projects I lifted code examples from:</p>
<ul>
<li><a href="http://pinvoke.net/">Pinvoke.net</a> – a wiki-style site with many useful bits of example code related to calling the Windows API from within .NET.
</li><li><a href="http://blogs.msdn.com/coding4fun/archive/2009/10/08/9905168.aspx">“.NET Audio Recorder”</a> by Mark Heath, from which I stole code to make the audio trigger.
</li><li><a href="http://blogs.msdn.com/coding4fun/archive/2007/10/29/5773776.aspx">“Possessed PC Pranks for Halloween”</a> by Brian Peek, from which I stole the basic code for sending keystrokes.
</li><li><a href="http://blogs.msdn.com/coding4fun/archive/2007/03/29/1991785.aspx">“April Fools' Day Application”</a> by Brian Peek, from which I stole code to grab the screen and rotate it.
</li></ul>
<h3>About The Author</h3>
<p>Randall Maas writes firmware for medical devices, and consults in embedded software. Before that he did a lot of other things… like everyone else in the software industry. You can contact him at
<a href="mailto:randym@acm.org">randym@acm.org</a>.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:144c71c45bb4497091de9e7600caf138">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Halloween-Gremlins</comments>
      <itunes:summary>
This article describes a quick and easy application to play Halloween tricks on the PC. 
 
Introduction
This article describes “Gremlin”, a quick and easy application that lets you play Halloween tricks. When your victim&#39;s computer is idle, Gremlin moves windows around on the screen, changes the focus window, moves your mouse, scrolls windows, and types nonsensical
 stuff. When there is background noise – like someone talking – it will shake the screen, even as your victim is typing away. 
Deployment
Run it right away. You can download, copy theGremlin.exe executable and NAudio.dll to the victim&#39;s computer (say in c:\ directory), and then double click on the executable to run it. 
Run it later. The other option is to copy the executable and dll files (or a shortcut to it) to the Startup folder on the victim&#39;s machine and watch the fun begin when they start up their machine in the morning! 
If the computer you&#39;re using runs on Windows XP the path is:  

C:\Documents and Settings\All Users\Start Menu\Programs\Startup 

With Vista and Windows 7 the path looks like:  

C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 

Just remember to change USERNAME to the name of the user on your machine. 
 
Commandline
Gremlin is compiled as a windows application, so it won&#39;t popup a terminal window if you double click on it, etc. But you can run it from the command line with flags: 

-aggressive will make the gremlin&#39;s actions more obvious 
-help will display the command line options 
-name NAME is useful for testing. Gremlin will only use windows with this specific title or from this specific application. (Remember to drop the &amp;quot;.exe&amp;quot; from the application filename) 

To stop the program, press CTRL&amp;#43;F2. 
And now … the dodgy bits
The overall structure of the program is broken down into three kinds of functionality – actions, triggers and some interstitial glue: 
Actions 

The screen-shaker is a window that makes the monitor look like it i</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Halloween-Gremlins</link>
      <pubDate>Sat, 31 Oct 2009 22:37:42 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Halloween-Gremlins</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/9915768_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/9915768_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Randall Maas</dc:creator>
      <itunes:author>Randall Maas</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Halloween-Gremlins/RSS</wfw:commentRss>
      <category>Audio</category>
      <category>Halloween</category>
      <category>Pranks</category>
      <category>Holiday</category>
    </item>
  <item>
      <title>Bug Killer – A Channel 9 Halloween special</title>
      <description><![CDATA[
<p><strong>WARNING</strong>: This video contains blood, gore and one extremely frightening software developer.</p>
<p>&nbsp;</p>
<p>Have you spent countless nights up late writing code? &nbsp;Have your eyes burned after staring at a monitor for 18 hours? Have you ever wanted to hack up a co-worker or two? &nbsp;Sure, we all have! Here’s the story of&nbsp;what happened to&nbsp;one developer on a dark and
 foggy night when the pressure&nbsp;was just too much…<br /><br /><a shape="rect" href="http://ecn.channel9.msdn.com/o9/c4f/projects/halloween/c9halloween.zip " shape="rect">Get the &quot;Behind the Scenes&quot; Theme here</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:162a8e2679ec4df1afdb9deb0017f225">]]></description>
      <comments>http://channel9.msdn.com/Blogs/LauraFoy/Bug-Killer--A-Channel-9-Halloween-special</comments>
      <itunes:summary>
WARNING: This video contains blood, gore and one extremely frightening software developer. 
&amp;nbsp; 
Have you spent countless nights up late writing code? &amp;nbsp;Have your eyes burned after staring at a monitor for 18 hours? Have you ever wanted to hack up a co-worker or two? &amp;nbsp;Sure, we all have! Here’s the story of&amp;nbsp;what happened to&amp;nbsp;one developer on a dark and
 foggy night when the pressure&amp;nbsp;was just too much…Get the &amp;quot;Behind the Scenes&amp;quot; Theme here 
</itunes:summary>
      <itunes:duration>331</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/LauraFoy/Bug-Killer--A-Channel-9-Halloween-special</link>
      <pubDate>Fri, 30 Oct 2009 05:34:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/LauraFoy/Bug-Killer--A-Channel-9-Halloween-special</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/502554_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/502554_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_2MB_ch9.wmv" expression="full" duration="331" fileSize="270626056" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_ch9.mp3" expression="full" duration="331" fileSize="2652279" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_ch9.mp4" expression="full" duration="331" fileSize="62573431" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_ch9.wma" expression="full" duration="331" fileSize="2687549" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_ch9.wmv" expression="full" duration="331" fileSize="71802167" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_Zune_ch9.wmv" expression="full" duration="331" fileSize="69627314" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/0/2/1/3/5/4/HallFin_ch9.wmv" length="71802167" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Laura Foy</dc:creator>
      <itunes:author>Laura Foy</itunes:author>
      <slash:comments>54</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/LauraFoy/Bug-Killer--A-Channel-9-Halloween-special/RSS</wfw:commentRss>
      <category>bug killer</category>
      <category>Halloween</category>
      <category>Visual Studio</category>
    </item>
  <item>
      <title>Halloween...be afraid...be very, very afraid.</title>
      <description><![CDATA[What are your Halloween traditions? See if they can compare to the SCARY people we found... <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:d4a549551e124096be859e0f01018119">]]></description>
      <comments>http://channel9.msdn.com/Blogs/LauraFoy/Halloweenbe-afraidbe-very-very-afraid</comments>
      <itunes:summary>What are your Halloween traditions? See if they can compare to the SCARY people we found...</itunes:summary>
      <itunes:duration>374</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/LauraFoy/Halloweenbe-afraidbe-very-very-afraid</link>
      <pubDate>Fri, 31 Oct 2008 23:12:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/LauraFoy/Halloweenbe-afraidbe-very-very-afraid</guid>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_large_on10.jpg" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_small_on10.jpg" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_2MB_on10.wmv" expression="full" duration="374" fileSize="117248189" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_on10.mp3" expression="full" duration="374" fileSize="2993551" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_on10.mp4" expression="full" duration="374" fileSize="21023686" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_on10.wma" expression="full" duration="374" fileSize="3039189" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_on10.wmv" expression="full" duration="374" fileSize="23644407" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_Zune_on10.wmv" expression="full" duration="374" fileSize="29639843" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/on10/9/1/9/3/2/halloween08_s_on10.wmv" expression="full" duration="374" fileSize="202" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/on10/9/1/9/3/2/halloween08_on10.wmv" length="23644407" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Laura Foy</dc:creator>
      <itunes:author>Laura Foy</itunes:author>
      <slash:comments>3</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/LauraFoy/Halloweenbe-afraidbe-very-very-afraid/RSS</wfw:commentRss>
      <category>Halloween</category>
    </item>
  <item>
      <title>Possessed PC Pranks for Halloween</title>
      <description><![CDATA[<span id="c4fmetadata">
<table cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td width="50"><img height="47" alt="Pumpkin" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/Pumkin.gif" width="50" border="0">
</td>
<td><span class="entry_description">In this application, Brian Peek demonstrates how to create two spooky Halloween applications to trick your friends and colleagues.</span></td>
</tr>
<tr>
<td colspan="2">
<div class="entry_author"><a href="http://www.brianpeek.com/" target="_blank">Brian Peek</a></div>
<div class="entry_company"><a href="http://www.aspsoft.com/">ASPSOFT, Inc.</a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
Less than 1 hour</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Basic or Visual C# Express Editions</a>,
<a href="http://msdn2.microsoft.com/en-us/directx/Aa937789.aspx" target="_blank">
DirectX SDK (for application #1)</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input">None</span></div>
<div class="entry_details"><b>Download: </b><a href="http://channel9.msdn.com/ShowPost.aspx?PostID=351868" target="_blank">Download</a>
</div>
</td>
</tr>
</tbody>
</table>
<p></span>&nbsp;</p>
<h3>Introduction</h3>
<p>Last year I wrote two articles on how to annoy your friends and family by <a href="http://blogs.msdn.com/coding4fun/archive/2006/10/30/905508.aspx" target="_blank">
dripping blood down their computer screen</a>, or by <a href="http://blogs.msdn.com/coding4fun/archive/2006/10/30/905480.aspx" target="_blank">
squirting them with (hopefully) fake blood from (even more hopefully) a fake skull</a>.&nbsp; Halloween is just around the corner, so here are two more applications which you can use to further bother the people around you.</p>
<p>&nbsp;</p>
<h3>Application #1 - Cursed Video</h3>
<p>If you have ever seen the horror film <a href="http://www.imdb.com/title/tt0298130/" target="_blank">
The Ring</a>, then you can likely guess the basic premise of this application.&nbsp; For those that haven't, the film is about a video tape which, when watched, will cause the viewer to die within a week of viewing it.&nbsp; So, what better way to annoy and terrify your
 friends than by playing the &quot;cursed video&quot; at a time you schedule without their knowing?</p>
<p>This application will use a library from Managed DirectX to play the video.&nbsp; If you haven't already, grab the full
<a href="http://msdn2.microsoft.com/en-us/directx/Aa937789.aspx" target="_blank">
DirectX SDK</a> and install.&nbsp; Note that we will be creating a dependency on DirectX, so the victim's PC will need to have DirectX 9.0c installed.&nbsp; Almost every XP desktop has it installed at this point, but be sure to test the app on the target PC.&nbsp; Additionally,
 I have had mixed success drawing a semi-transparent video with every method I've tried (DX, WPF, etc.).&nbsp; It is very dependent on video drivers, so the intended effect may not be perfect on all PCs.&nbsp; Again, be sure to test.</p>
<p>Next, create a new C#/VB Windows Application project and set references to the Microsoft.DirectX and Microsoft.DirectX.AudioVideoPlayback assemblies as shown:</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/image.png"><img height="160" alt="image" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/image_thumb.png" width="332" border="0"></a>
</p>
<p>Next, we need to make some modifications to the form.&nbsp; The video will be played at 50% transparency against the victim's desktop, which gives a very creepy effect.&nbsp; The form should also be hidden from view until the video is ready to be played at the selected
 time.&nbsp; To do this, set the following properties on the form:</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="200"><strong>Property</strong></td>
<td valign="top" width="200"><strong>Value</strong></td>
</tr>
<tr>
<td valign="top" width="200">BackColor</td>
<td valign="top" width="200">Fuchsia</td>
</tr>
<tr>
<td valign="top" width="200">FormBorderStyle</td>
<td valign="top" width="200">None</td>
</tr>
<tr>
<td valign="top" width="200">WindowState</td>
<td valign="top" width="200">Minimized</td>
</tr>
<tr>
<td valign="top" width="200">Opacity</td>
<td valign="top" width="200">50%</td>
</tr>
<tr>
<td valign="top" width="200">ShowInTaskbar</td>
<td valign="top" width="200">False</td>
</tr>
<tr>
<td valign="top" width="200">TopMost</td>
<td valign="top" width="200">True</td>
</tr>
<tr>
<td valign="top" width="200">TransparencyKey</td>
<td valign="top" width="200">Fuchsia</td>
</tr>
</tbody>
</table>
<p>Next, we need to provide a surface onto which the video can be drawn.&nbsp; Drop a <strong>
PictureBox</strong> control onto the form and set its properties as follows:</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="200"><strong>Property</strong></td>
<td valign="top" width="200"><strong>Value</strong></td>
</tr>
<tr>
<td valign="top" width="200">BackColor</td>
<td valign="top" width="200">Fuchsia</td>
</tr>
<tr>
<td valign="top" width="200">Dock</td>
<td valign="top" width="200">Fill</td>
</tr>
</tbody>
</table>
<p>Now we need a method which will play the video.&nbsp; Bring in the <strong>Microsoft.DirectX.AudioVideoPlayback</strong> namespace with the using/Imports keyword and then add the following method to the form:</p>
<p><strong>C#</strong></p>
<span id="c4fmetadata">
<div>
<pre><span>using</span> Microsoft.DirectX.AudioVideoPlayback;

...

Video _video;

<span>public</span> <span>void</span> StartShow()
{
    <span>// create a new video from a filename</span>
    <span>this</span>._video = Video.FromFile(<span>&quot;ring.wmv&quot;</span>);

    <span>// set the drawable surface to the picturebox</span>
    <span>this</span>._video.Owner = pictureBox1;

    <span>// setup an event handler so we can pop up a msgbox when the video is over</span>
    <span>this</span>._video.Ending &#43;= <span>new</span> EventHandler(video_Ending);

    <span>// play it!</span>
    <span>this</span>._video.Play();
}

<span>void</span> video_Ending(<span>object</span> sender, EventArgs e)
{
    <span>// called when the video ends</span>
    MessageBox.Show(<span>&quot;Happy Halloween!&quot;</span>);
    <span>this</span>.Close();
}</pre>
</div>
</span>
<p><strong>VB</strong></p>
<div>
<pre><span>Imports</span> Microsoft.DirectX.AudioVideoPlayback

...

<span>Private</span> _video <span>As</span> Video

<span>Public</span> <span>Sub</span> StartShow()
    <span>' create a new video from a filename</span>
    <span>Me</span>._video = Video.FromFile(<span>&quot;ring.wmv&quot;</span>)

    <span>' set the drawable surface to the picturebox</span>
    <span>Me</span>._video.Owner = pictureBox1

    <span>' setup an event handler so we can pop up a msgbox when the video is over</span>
    <span>AddHandler</span> _video.Ending, <span>AddressOf</span> video_Ending

    <span>' play it!</span>
    <span>Me</span>._video.Play()
<span>End</span> <span>Sub</span>

<span>Private</span> <span>Sub</span> video_Ending(<span>ByVal</span> sender <span>As</span> <span>Object</span>, <span>ByVal</span> e <span>As</span> EventArgs)
    <span>' called when the video ends</span>
    MessageBox.Show(<span>&quot;Happy Halloween!&quot;</span>)
    <span>Me</span>.Close()
<span>End</span> Sub</pre>
</div>
<p>This simply creates a new <strong>Video</strong> object by loading a specific filename (ring.wmv), then assigns the video's
<strong>Owner</strong> property to the <strong>PictureBox</strong>, which is where the video will be drawn.&nbsp; Next, an event is setup so we are notified when the clip has ended, and finally, the video is played with the
<strong>Play</strong> method.</p>
<p>The <strong>video_Ending</strong> event handler displays a message box and closes down the application.</p>
<p><strong>x86/x64</strong></p>
<p>The Managed DirectX assemblies are compiled to run in x86 mode only.&nbsp; If you are compiling the application on an x64 OS, you will have to ensure that the main application is built as an x86 target.&nbsp; To do so, choose
<strong>Configuration Manager</strong> from the build menu.&nbsp; In the dialog that appears, choose
<strong>&lt;New...&gt;</strong> from the <strong>Active solution platform</strong> drop down:</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/new.png"><img height="310" alt="new" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/new_thumb.png" width="494" border="0"></a>
</p>
<p>Finally, choose <strong>x86</strong> from the <strong>Type or select the new platform</strong> drop down:</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/x86.png"><img height="229" alt="x86" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/x86_thumb.png" width="353" border="0"></a>
</p>
<p>Get back to the project and rebuild and you will have an x86-native application which will run successfully on both x86 and x64 platforms.</p>
<h5></h5>
<h5>Config/Test/Scheduler</h5>
<p>The code which handles the configuration, scheduling and testing will be the same for both of these applications, so please jump to that section by clicking
<a href="#scheduler">here</a>.</p>
<p>&nbsp;</p>
<h3>Application #2 - The Shining</h3>
<p>If you have seen <a href="http://www.imdb.com/title/tt0081505/" target="_blank">
The Shining</a>, you can probably guess where this one is heading, too.&nbsp; The basic plot is that an author and his family retreat to an isolated hotel for the winter, and some paranormal activity causes the father to go a bit insane, among other things.&nbsp; In
 the film, as the author goes crazy, he starts typing &quot;All work and no play makes Jack a dull boy&quot; over and over again on the typewriter.&nbsp; So, this application will mimic that by, at the appointed time, popping up an instance of Notepad and having the computer
 type the phrase over and over again on its own.</p>
<p>Once again, create a new VB/C# Windows Application project.&nbsp; As with the previous project, we want the main form to be hidden, but this time, it should be hidden at all times.&nbsp; So, set the form properties as follows:</p>
<table cellspacing="0" cellpadding="2" width="402" border="1">
<tbody>
<tr>
<td valign="top" width="200"><strong>Property</strong></td>
<td valign="top" width="200"><strong>Value</strong></td>
</tr>
<tr>
<td valign="top" width="200">FormBorderStyle</td>
<td valign="top" width="200">None</td>
</tr>
<tr>
<td valign="top" width="200">WindowState</td>
<td valign="top" width="200">Minimized</td>
</tr>
<tr>
<td valign="top" width="200">ShowInTaskbar</td>
<td valign="top" width="200">False</td>
</tr>
<tr>
<td valign="top" width="200">Size</td>
<td valign="top" width="200">10, 10</td>
</tr>
</tbody>
</table>
<p>Next, drag a timer onto the form named <strong>tmrType</strong> and create an event handler for the
<strong>Tick</strong> event which we will fill in later.</p>
<p>Create a method named <strong>StartShow</strong> as follows:</p>
<p><strong>C#</strong></p>
<div>
<pre><span>using</span> System.Diagnostics;
...

<span>private</span> Process _process;

<span>public</span> <span>void</span> StartShow()
{
    _process = Process.Start(<span>&quot;notepad.exe&quot;</span>);
    tmrType.Start();
}</pre>
</div>
<p><strong>VB</strong></p>
<div>
<pre><span>Imports</span> System.Diagnostics

...

<span>' the Notepad process</span>
<span>Private</span> _process <span>As</span> Process

<span>Public</span> <span>Sub</span> StartShow()
    _process = Process.Start(<span>&quot;notepad.exe&quot;</span>)
    tmrType.Start()
<span>End</span> Sub</pre>
</div>
<p>This code starts an instance of Notepad and then starts the <strong>tmrType</strong> ticking.&nbsp; That tick event will send the appropriate letter to the Notepad window from the phrase:</p>
<p><strong>C#</strong></p>
<div>
<pre><span>using</span> System.Runtime.InteropServices;

...

[DllImport(<span>&quot;user32&quot;</span>)]
<span>public</span> <span>static</span> <span>extern</span> <span>int</span> SetForegroundWindow(IntPtr hwnd);

<span>// counter variables</span>
<span>private</span> <span>int</span> i, j;

<span>// the message to type out</span>
<span>private</span> <span>const</span> <span>string</span> msg = <span>&quot;All work and no play makes Jack a dull boy.&quot;</span>;

...

<span>private</span> <span>void</span> tmrType_Tick(<span>object</span> sender, EventArgs e)
{
    <span>// make sure the Notepad window is at the front</span>
    SetForegroundWindow(_process.MainWindowHandle);

    <span>// send the next letter to the window</span>
    <span>if</span>(i &lt; msg.Length)
        SendKeys.Send(msg[i&#43;&#43;].ToString());
    <span>else</span>
    {
        <span>// send a carriage return if we're at the end of the line</span>
        SendKeys.Send(<span>&quot;{ENTER}&quot;</span>);

        <span>// write the line 5 times</span>
        <span>if</span>(&#43;&#43;j &lt; 5)
            i = 0;
        <span>else</span>
        {
            <span>// when done, stop the timer, display the msgbox and close it up</span>
            tmrType.Stop();
            MessageBox.Show(<span>&quot;Happy Halloween!&quot;</span>);
            <span>this</span>.Close();
        }
    }
}</pre>
</div>
<p><strong>VB</strong></p>
<div>
<pre><span>Imports</span> System.Runtime.InteropServices

...

&lt;DllImport(<span>&quot;user32&quot;</span>)&gt; _
<span>Public</span> <span>Shared</span> <span>Function</span> SetForegroundWindow(<span>ByVal</span> hwnd <span>As</span> IntPtr) <span>As</span> <span>Integer</span>
<span>End</span> <span>Function</span>

<span>' counter variables</span>
<span>Private</span> i, j <span>As</span> <span>Integer</span>

<span>' the message to type out</span>
<span>Private</span> <span>Const</span> msg <span>As</span> <span>String</span> = <span>&quot;All work and no play makes Jack a dull boy.&quot;</span>

<span>Private</span> <span>Sub</span> tmrType_Tick(<span>ByVal</span> sender <span>As</span> <span>Object</span>, <span>ByVal</span> e <span>As</span> EventArgs) <span>Handles</span> tmrType.Tick
    <span>' make sure the Notepad window is at the front</span>
    SetForegroundWindow(_process.MainWindowHandle)

    <span>' send the next letter to the window</span>
    <span>If</span> i &lt; msg.Length <span>Then</span>
        SendKeys.Send(msg.Chars(i).ToString())
        i &#43;= 1
    <span>Else</span>
        <span>' send a carriage return if we're at the end of the line</span>
        SendKeys.Send(<span>&quot;{ENTER}&quot;</span>)

        <span>' write the line 5 times</span>
        j = j &#43; 1
        <span>If</span> j &lt; 5 <span>Then</span>
            i = 0
        <span>Else</span>
            <span>' when done, stop the timer, display the msgbox and close it up</span>
            tmrType.<span>Stop</span>()
            MessageBox.Show(<span>&quot;Happy Halloween!&quot;</span>)
            <span>Me</span>.Close()
        <span>End</span> <span>If</span>
    <span>End</span> <span>If</span>
<span>End</span> Sub</pre>
</div>
<p>At the start of the tick, a call is made to the Win32 API function <strong>SetForegroundWindow</strong>, passing in the window handle (<strong>_process.MainWindowHandle</strong>) of the Notepad process.&nbsp; This ensures that the Notepad window is focused before
 we send the next letter to the window using the <strong>SendKeys</strong> method.&nbsp; When the end of the phrase is reached, a carriage return is sent using
<strong>SendKeys</strong> and the string <strong>{ENTER}</strong>.&nbsp; This repeats 5 times at which point the timer is stopped, the message box is displayed, and the application closes.</p>
<p>&nbsp;</p>
<h3></h3>
<h3><a name="scheduler">The Scheduler</a></h3>
<p>The final piece is to setup a time at which the effect will display on the victim's PC.&nbsp; Create a simple dialog box with a
<strong>DateTimePicker</strong> control that allows the choosing of the appropriate date/time to run:</p>
<p><img height="136" alt="image" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/image_3.png" width="234" border="0">
</p>
<p>Next, create a new application setting named <strong>Time</strong> as shown:</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/image_4.png"><img height="114" alt="image" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773776/image_thumb_3.png" width="494" border="0"></a>
</p>
<p>Next, setup the events on the <strong>Configuration</strong> form as follows:</p>
<p><strong>C#</strong></p>
<div>
<pre><span>private</span> <span>void</span> ConfigForm_Load(<span>object</span> sender, EventArgs e)
{
    <span>// if no time has been specified, show today's date, otherwise, show the date previously selected</span>
    <span>if</span>(Properties.Settings.Default.Time == DateTime.MinValue)
        dateTimePicker1.Value = DateTime.Now.Date;
    <span>else</span>
        dateTimePicker1.Value = Properties.Settings.Default.Time;
}

<span>private</span> <span>void</span> btnSave_Click(<span>object</span> sender, EventArgs e)
{
    <span>// save the currently selected date/time to the Settings collection</span>
    Properties.Settings.Default.Time = dateTimePicker1.Value;

    Properties.Settings.Default.Save();

    <span>// tell the user what's up</span>
    MessageBox.Show(<span>&quot;Date and time saved.  When you click OK, the application will continue running and the show will start upon the specified date and time.  If you wish to reset the date/time, restart the application with the '-config' switch.&quot;</span>, <span>&quot;Configuration updated&quot;</span>, MessageBoxButtons.OK, MessageBoxIcon.Information);

    <span>// close it up</span>
    <span>this</span>.DialogResult = DialogResult.OK;
    <span>this</span>.Close();
}

<span>private</span> <span>void</span> btnCancel_Click(<span>object</span> sender, EventArgs e)
{
    <span>// close it up</span>
    <span>this</span>.DialogResult = DialogResult.Cancel;
    <span>this</span>.Close();
}
</pre>
</div>
<p><strong>VB</strong></p>
<div>
<pre><span>Private</span> <span>Sub</span> ConfigForm_Load(<span>ByVal</span> sender <span>As</span> <span>Object</span>, <span>ByVal</span> e <span>As</span> EventArgs) <span>Handles</span> <span>MyBase</span>.Load
    <span>' if no time has been specified, show today's date, otherwise, show the date previously selected</span>
    <span>If</span> My.Settings.<span>Default</span>.Time = DateTime.MinValue <span>Then</span>
        dateTimePicker1.Value = DateTime.Now.<span>Date</span>
    <span>Else</span>
        dateTimePicker1.Value = My.Settings.<span>Default</span>.Time
    <span>End</span> <span>If</span>
<span>End</span> <span>Sub</span>

<span>Private</span> <span>Sub</span> btnSave_Click(<span>ByVal</span> sender <span>As</span> <span>Object</span>, <span>ByVal</span> e <span>As</span> EventArgs) <span>Handles</span> btnSave.Click
    <span>' save the currently selected date/time to the Settings collection</span>
    My.Settings.<span>Default</span>.Time = dateTimePicker1.Value

    My.Settings.<span>Default</span>.Save()

    <span>' tell the user what's up</span>
    MessageBox.Show(<span>&quot;Date and time saved.  When you click OK, the application will continue running and the show will start upon the specified date and time.  If you wish to reset the date/time, restart the application with the '-config' switch.&quot;</span>, <span>&quot;Configuration updated&quot;</span>, MessageBoxButtons.OK, MessageBoxIcon.Information)

    <span>' close it up</span>
    <span>Me</span>.DialogResult = System.Windows.Forms.DialogResult.OK
    <span>Me</span>.Close()
<span>End</span> <span>Sub</span>

<span>Private</span> <span>Sub</span> btnCancel_Click(<span>ByVal</span> sender <span>As</span> <span>Object</span>, <span>ByVal</span> e <span>As</span> EventArgs) <span>Handles</span> btnCancel.Click
    <span>' close it up</span>
    <span>Me</span>.DialogResult = System.Windows.Forms.DialogResult.Cancel
    <span>Me</span>.Close()
<span>End</span> Sub</pre>
</div>
<p>The code loads the current value at start (if it exists), saves it when the <strong>
Save</strong> button is clicked, and does nothing when <strong>Cancel</strong> is clicked.</p>
<p>Back on the main form of either application, drag and drop a timer control named
<strong>tmrScheduler</strong> to the main design surface.&nbsp; Set the properties as follows:</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="200"><strong>Property</strong></td>
<td valign="top" width="200"><strong>Value</strong></td>
</tr>
<tr>
<td valign="top" width="200">Enabled</td>
<td valign="top" width="200">True</td>
</tr>
<tr>
<td valign="top" width="200">Interval</td>
<td valign="top" width="200">60000</td>
</tr>
</tbody>
</table>
<p>This will start the timer immediately and call the <strong>Tick</strong> event once every minute.&nbsp; That event will check to see whether the requested time has passed and, if so, starts the show:</p>
<p><strong>C# - Cursed Video</strong></p>
<div>
<pre><span>private</span> <span>void</span> tmrScheduler_Tick(<span>object</span> sender, EventArgs e)
{
    <span>// if the current time is greater than the time set by the user</span>
    <span>if</span>(DateTime.Now &gt;= Properties.Settings.Default.Time)
    {
        <span>// bring up the window</span>
        <span>this</span>.WindowState = FormWindowState.Maximized;

        <span>// disable this timer</span>
        tmrScheduler.Enabled = <span>false</span>;

        <span>// bring it to the top</span>
        <span>this</span>.BringToFront();

        <span>// play the movie</span>
        StartShow();
    }
}</pre>
</div>
<p><strong>VB - Cursed Video</strong></p>
<div>
<pre><span>Private</span> <span>Sub</span> tmrScheduler_Tick(<span>ByVal</span> sender <span>As</span> <span>Object</span>, <span>ByVal</span> e <span>As</span> EventArgs) <span>Handles</span> tmrScheduler.Tick
    <span>' if the current time is greater than the time set by the user</span>
    <span>If</span> DateTime.Now &gt;= My.Settings.<span>Default</span>.Time <span>Then</span>
        <span>' bring up the window</span>
        <span>Me</span>.WindowState = FormWindowState.Maximized

        <span>' disable this timer</span>
        tmrScheduler.Enabled = <span>False</span>

        <span>' bring it to the top</span>
        <span>Me</span>.BringToFront()

        <span>' play the movie</span>
        StartShow()
    <span>End</span> <span>If</span>
<span>End</span> Sub</pre>
</div>
<p><strong>C# - The Shining</strong></p>
<div>
<pre><span>private</span> <span>void</span> tmrScheduler_Tick(<span>object</span> sender, EventArgs e)
{
    <span>// if the current time is greater than the time set by the user</span>
    <span>if</span>(DateTime.Now &gt;= Properties.Settings.Default.Time)
    {
        <span>// disable this timer</span>
        tmrScheduler.Enabled = <span>false</span>;

        <span>// start typing</span>
        StartShow();
    }
}</pre>
</div>
<p><strong>VB - The Shining</strong></p>
<div>
<pre><span>Private</span> <span>Sub</span> tmrScheduler_Tick(<span>ByVal</span> sender <span>As</span> <span>Object</span>, <span>ByVal</span> e <span>As</span> EventArgs) <span>Handles</span> tmrScheduler.Tick
    <span>' if the current time is greater than the time set by the user</span>
    <span>If</span> DateTime.Now &gt;= My.Settings.<span>Default</span>.Time <span>Then</span>
        <span>' disable this timer</span>
        tmrScheduler.Enabled = <span>False</span>

        <span>' start typing</span>
        StartShow()
    <span>End</span> <span>If</span>
<span>End</span> Sub</pre>
</div>
<h3>Configuration/Testing</h3>
<p>To make it easy to reset the launch time, and to test the effect without scheduling it, two command line parameters can be added to
<strong>Program.cs/vb</strong> to re-run the configuration or test.&nbsp; Add the following code prior to the call to
<strong>Application.Run:</strong></p>
<p><strong>C#</strong></p>
<div>
<pre><span>// test the effect</span>
<span>if</span>(Environment.CommandLine.IndexOf(<span>&quot;test&quot;</span>) &gt; -1)
{
    Form1 f = <span>new</span> Form1();
    f.StartShow();
    f.ShowDialog();
    <span>return</span>;
}

<span>// if we haven't set the time, or the user requested the config dialog, display it</span>
<span>if</span>(Properties.Settings.Default.Time == DateTime.MinValue || Environment.CommandLine.IndexOf(<span>&quot;config&quot;</span>) &gt; -1)
{
    <span>if</span>(<span>new</span> ConfigForm().ShowDialog() == DialogResult.Cancel)
        <span>return</span>;
}</pre>
</div>
<p><strong>VB</strong></p>
<strong></strong>
<div>
<pre><span>' test the effect</span>
<span>If</span> Environment.CommandLine.IndexOf(<span>&quot;test&quot;</span>) &gt; -1 <span>Then</span>
    <span>Dim</span> f <span>As</span> Form1 = <span>New</span> Form1()
    f.StartShow()
    f.ShowDialog()
    <span>Return</span>
<span>End</span> <span>If</span>

<span>' if we haven't set the time, or the user requested the config dialog, display it</span>
<span>If</span> My.Settings.<span>Default</span>.Time = DateTime.MinValue <span>OrElse</span> Environment.CommandLine.IndexOf(<span>&quot;config&quot;</span>) &gt; -1 <span>Then</span>
    <span>If</span> <span>New</span> ConfigForm().ShowDialog() = DialogResult.Cancel <span>Then</span>
        <span>Return</span>
    <span>End</span> <span>If</span>
<span>End</span> If</pre>
</div>
<p>If <strong>-test</strong> is passed on the command line, the form is created and the show is started.&nbsp; If
<strong>-config</strong> is passed on the command line, the Configuration dialog is displayed and the application continues as it would the first time it ran.</p>
<h3><strong></strong></h3>
<h3>Deployment</h3>
<p><strong>Cursed Video</strong></p>
<p>Copy the exe, <strong>Microsoft.DirectX</strong> and <strong>Microsoft.DirectX.AudioVideoPlayback</strong> to a folder on the user's PC along with a video clip named
<strong>ring.wmv</strong>.&nbsp; Of course, you can replace that video clip with any clip of your choosing, though if you wish to use a different filename, you will have to change the code and recompile.</p>
<p><strong>The Shining</strong></p>
<p>Copy the exe to a folder on the user's PC.</p>
<p>&nbsp;</p>
<p>For either, create a shortcut to it in the Startup program group, or set it up to run via the registry using the following key for the logged in user:
</p>
<ul>
<li>HKCU\Software\Microsoft\Windows\CurrentVersion\Run</li></ul>
<p>Simply create a new string key with any Name, and a Data value of the path to the executable.
</p>
<p>Next, start the application once on their PC to setup the date and time for the show to begin. Once that is done, the application will remain running in the background. If the PC is restarted, and the application is setup to run at startup as described above,
 it will start silently and remain running, waiting for the date and time specified.
</p>
<h3>Summary</h3>
<p>Two Halloween applications for the price of one.&nbsp; Not that you paid for either.&nbsp; Be sure to have fun with them this Halloween and disturb anyone you can.&nbsp; Enjoy!</p>
<h3>Thanks</h3>
<p>Thanks to Giovanni Montrone for testing out these applications during development.</p>
<h3>Bio</h3>
<p>Brian is a Microsoft C# MVP and a recognized .NET expert with over 6 years experience developing .NET solutions, and over 9 years of professional experience architecting and developing solutions using Microsoft technologies and platforms, although he has
 been &quot;coding for fun&quot; for as long as he can remember.&nbsp; Outside the world of .NET and business applications, Brian enjoys developing both hardware and software projects in the areas of gaming, robotics, and whatever else strikes his fancy for the next ten minutes.
 He rarely passes up an opportunity to dive into a C/C&#43;&#43; or assembly language project.&nbsp; You can reach Brian via his blog at
<a href="http://www.brianpeek.com/">http://www.brianpeek.com/</a>.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:d6ad859429a74dd7b4a39e7600d1b812">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Possessed-PC-Pranks-for-Halloween</comments>
      <itunes:summary>





In this application, Brian Peek demonstrates how to create two spooky Halloween applications to trick your friends and colleagues.



Brian Peek
ASPSOFT, Inc.

Difficulty: Easy
Time Required: 
Less than 1 hour
Cost: Free
Software: Visual Basic or Visual C# Express Editions,

DirectX SDK (for application #1)
Hardware: None
Download: Download





&amp;nbsp; 
Introduction
Last year I wrote two articles on how to annoy your friends and family by 
dripping blood down their computer screen, or by 
squirting them with (hopefully) fake blood from (even more hopefully) a fake skull.&amp;nbsp; Halloween is just around the corner, so here are two more applications which you can use to further bother the people around you. 
&amp;nbsp; 
Application #1 - Cursed Video
If you have ever seen the horror film 
The Ring, then you can likely guess the basic premise of this application.&amp;nbsp; For those that haven&#39;t, the film is about a video tape which, when watched, will cause the viewer to die within a week of viewing it.&amp;nbsp; So, what better way to annoy and terrify your
 friends than by playing the &amp;quot;cursed video&amp;quot; at a time you schedule without their knowing? 
This application will use a library from Managed DirectX to play the video.&amp;nbsp; If you haven&#39;t already, grab the full

DirectX SDK and install.&amp;nbsp; Note that we will be creating a dependency on DirectX, so the victim&#39;s PC will need to have DirectX 9.0c installed.&amp;nbsp; Almost every XP desktop has it installed at this point, but be sure to test the app on the target PC.&amp;nbsp; Additionally,
 I have had mixed success drawing a semi-transparent video with every method I&#39;ve tried (DX, WPF, etc.).&amp;nbsp; It is very dependent on video drivers, so the intended effect may not be perfect on all PCs.&amp;nbsp; Again, be sure to test. 
Next, create a new C#/VB Windows Application project and set references to the Microsoft.DirectX and Microsoft.DirectX.AudioVideoPlayback assemblies as shown: 

 
Next, we need to make some modifications</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Possessed-PC-Pranks-for-Halloween</link>
      <pubDate>Mon, 29 Oct 2007 22:03:21 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Possessed-PC-Pranks-for-Halloween</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/5773776_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/5773776_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Brian Peek</dc:creator>
      <itunes:author>Brian Peek</itunes:author>
      <slash:comments>5</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Possessed-PC-Pranks-for-Halloween/RSS</wfw:commentRss>
      <category>Halloween</category>
      <category>Windows</category>
      <category>Holiday</category>
    </item>
  <item>
      <title>YeahTrivia: Creating a Trivia Server/Client with WPF and WCF</title>
      <description><![CDATA[<span id="c4fmetadata">
<table class="" cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td class="" width="50"><img height="50" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773166/yeahtriviathumb.gif" width="50"></td>
<td class=""><span class="entry_description">In this article I'll take you along for the ride as I attack the learning curve required to create a fun, interactive application using both the Microsoft Windows Presentation Foundation (WPF) and the Windows Communication
 Foundation (WCF). Afterwards, you'll have a flexible trivia client/server game ready to play by yourself or against friends, coworkers and your local know-it-all.&nbsp;
<em>And in honor of Halloween, I've included three games of horror movie trivia.</em></span></td>
</tr>
<tr>
<td class="" colspan="2">
<div class="entry_author">Steve Holstad</div>
<div class="entry_company"><a href="http://blogs.claritycon.com/blogs/steve_holstad/archive/2007/10/29/3403.aspx" target="_blank">The Bright Lights</a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Advanced</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
6-10 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input">Visual Studio Express, 2005, 2008 Beta 2
<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=10CC340B-F857-4A14-83F5-25634C3BF043&amp;displaylang=en">
Microsoft .NET Framework 3.0</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b><a class="" href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773166/YeahTrivia.zip" target="_blank">Download Source</a>
<ul>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>&nbsp;</p>
<h3>What can YeahTrivia do for me?</h3>
<p>Glad you asked. This project started when I decided I wanted to dive headfirst into learning WPF and WCF, without hacking through countless Hello World examples.&nbsp; And I wanted something fun that I could improve over time as my skills developed in these new
 technologies.&nbsp; In this article I'll take you along for the ride as I attack the learning curve required to create a fun, interactive application using both the Microsoft Windows Presentation Foundation (WPF) and the Windows Communication Foundation (WCF).
 Afterwards, you'll have a flexible trivia client/server game ready to play by yourself or against friends, coworkers and your local know-it-all.&nbsp; And in honor of Halloween, I've included three games of horror movie trivia.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773166/YeahTrivia_Client5.jpg"><img height="194" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773166/YeahTrivia_Client_thumb1.jpg" width="280" border="0"></a>
</p>
<p>In case you were wondering, the &quot;YeahTrivia&quot; name honors my new bride&nbsp;&amp; her&nbsp;favorite prefix.&nbsp; Think of it as&nbsp;YeeeeaaaaahhTrivia!</p>
<h3>Basic Setup</h3>
<p>This demo project was built using Visual Studio 2008 Beta 2, and is based on the Microsoft .NET Framework version 3.0.&nbsp; The game is fed by a small windows app that acts as a game server, providing game selection, user&nbsp;registration, question loading, response
 times, chat messaging&nbsp;and scorekeeping.&nbsp; The server loads a game by reading a predefined XML format, which we will look at a bit later.&nbsp; This dynamic load lets anyone create their own flavor of trivia game, with any number of questions.</p>
<p>The server app exposes one WCF endpoint, a wsDualHttpBinding channel that supports duplex (two-way) communication between the server and any number of game clients.&nbsp; Clients attach themselves to this endpoint and provide a callback address to the server.&nbsp;
 The server saves an instance of this callback channel and uses each client's instance to&nbsp;contact the clients en masse during general game flow.&nbsp; Enough talk, here's how to build one yourself.</p>
<h3>Trivia Common and WCF Service Interfaces</h3>
<p>The TriviaCommon project provides both the server and client projects access to shared objects.&nbsp; To keep things simple the Common project only contains two classes:</p>
<p>Constants.cs defines the AnswerItem enumeration, which gives easy access to the five answer options (None, A, B, C, D), and the QuestionItem struct.&nbsp; This structure is delivered to the client and contains question text, answer text, and the correct answer
 object of type AnswerItem.&nbsp; Notice that objects being directly passed over the wire need to be marked with the [DataContract] attribute.</p>
<p>The second class, Interfaces.cs is where our WCF fun begins.&nbsp; Take a look:</p>
<strong>C#:</strong><br>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.ServiceModel;
<span class="kwrd">using</span> System.Text;

<span class="kwrd">namespace</span> Trivia.Common
{
    <span class="preproc">#region</span> Interfaces

    <span class="preproc">#region</span> Service Interface

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Interface that defines Trivia service contract.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    [ServiceContract(CallbackContract = <span class="kwrd">typeof</span>(ITriviaCallback))]
    <span class="kwrd">public</span> <span class="kwrd">interface</span> ITrivia
    {
        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> RegisterUser(<span class="kwrd">string</span> userName);

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> AcceptAnswer(<span class="kwrd">string</span> userName, <span class="kwrd">string</span> answerValue);

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> ChatPublish(<span class="kwrd">string</span> userName, <span class="kwrd">string</span> message);
    }

    <span class="preproc">#endregion</span> Service Interface

    <span class="preproc">#region</span> Client Callback Interface

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Interface that defines Trivia client callback contract.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">interface</span> ITriviaCallback
    {        
        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnGameStart(<span class="kwrd">int</span> questionCount);

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnGameEnd();

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnUserRegistered(<span class="kwrd">string</span> userName);

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnPublishChat(<span class="kwrd">string</span> userName, <span class="kwrd">string</span> chatMessage);

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnQuestionLoad(<span class="kwrd">int</span> questionIndex, QuestionItem questionItem);

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnQuestionEnd();

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnQuestionStatusUpdate(Int64 questionTimeRemaining);

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnScoreboardUpdate(Dictionary&lt;<span class="kwrd">string</span>, Int64&gt; scoreboard);

        [OperationContract(IsOneWay = <span class="kwrd">true</span>)]
        <span class="kwrd">void</span> OnGameServerStopped();
    }

    <span class="preproc">#endregion</span> Client Callback Interface

    <span class="preproc">#endregion</span> Interfaces
}
</pre>
<pre class="csharpcode"></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong>VB:</strong></p>
<pre class="csharpcode"><span class="kwrd">Imports</span> System
<span class="kwrd">Imports</span> System.Collections.Generic
<span class="kwrd">Imports</span> System.ServiceModel
<span class="kwrd">Imports</span> System.Text

<span class="kwrd">Namespace</span> Trivia.Common

<span class="preproc">#Region</span> <span class="str">&quot;Interfaces&quot;</span>

<span class="preproc">#Region</span> <span class="str">&quot;Service Interface&quot;</span>
    
    <span class="rem">''' &lt;summary&gt;</span>
    <span class="rem">''' Interface that defines Trivia service contract.</span>
    <span class="rem">''' &lt;/summary&gt;</span>
    &lt;ServiceContract(CallbackContract:=<span class="kwrd">GetType</span>(ITriviaCallback))&gt; _
    <span class="kwrd">Public</span> <span class="kwrd">Interface</span> ITrivia
        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> RegisterUser(<span class="kwrd">ByVal</span> userName <span class="kwrd">As</span> <span class="kwrd">String</span>)

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> AcceptAnswer(<span class="kwrd">ByVal</span> userName <span class="kwrd">As</span> <span class="kwrd">String</span>, <span class="kwrd">ByVal</span> answerValue <span class="kwrd">As</span> <span class="kwrd">String</span>)

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> ChatPublish(<span class="kwrd">ByVal</span> userName <span class="kwrd">As</span> <span class="kwrd">String</span>, <span class="kwrd">ByVal</span> message <span class="kwrd">As</span> <span class="kwrd">String</span>)
    <span class="kwrd">End</span> <span class="kwrd">Interface</span>
        
<span class="preproc">#End Region</span>

<span class="preproc">#Region</span> <span class="str">&quot;Client Callback Interface&quot;</span>

    <span class="rem">''' &lt;summary&gt;</span>
    <span class="rem">''' Interface that defines Trivia client callback contract.</span>
    <span class="rem">''' &lt;/summary&gt;</span>
    <span class="rem">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span class="kwrd">Public</span> <span class="kwrd">Interface</span> ITriviaCallback
        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
      <span class="kwrd">Sub</span> OnGameStart(<span class="kwrd">ByVal</span> questionCount <span class="kwrd">As</span> <span class="kwrd">Integer</span>)

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> OnGameEnd()

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> OnUserRegistered(<span class="kwrd">ByVal</span> userName <span class="kwrd">As</span> <span class="kwrd">String</span>)

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> OnPublishChat(<span class="kwrd">ByVal</span> userName <span class="kwrd">As</span> <span class="kwrd">String</span>, <span class="kwrd">ByVal</span> chatMessage <span class="kwrd">As</span> <span class="kwrd">String</span>)

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> OnQuestionLoad(<span class="kwrd">ByVal</span> questionIndex <span class="kwrd">As</span> <span class="kwrd">Integer</span>, <span class="kwrd">ByVal</span> questionItem <span class="kwrd">As</span> QuestionItem)

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> OnQuestionEnd()

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> OnQuestionStatusUpdate(<span class="kwrd">ByVal</span> questionTimeRemaining <span class="kwrd">As</span> <span class="kwrd">Long</span>)

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> OnScoreboardUpdate(<span class="kwrd">ByVal</span> scoreboard <span class="kwrd">As</span> Dictionary(Of <span class="kwrd">String</span>, <span class="kwrd">Long</span>))

        &lt;OperationContract(IsOneWay:=<span class="kwrd">True</span>)&gt; _
        <span class="kwrd">Sub</span> OnGameServerStopped()

    <span class="kwrd">End</span> <span class="kwrd">Interface</span>

<span class="preproc">#End Region</span>

<span class="preproc">#End Region</span>

<span class="kwrd">End</span> <span class="kwrd">Namespace</span></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>A few items of interest here.&nbsp; Notice we're importing the System.ServiceModel namespace.&nbsp; This is the key assembly when using WCF, so don't forget to add a reference to your project.&nbsp; The first interface, ITrivia, defines the operations the server is required
 to implement, which handle basic user actions: Register a team, accept an answer and accept a chat message.&nbsp; Easy.</p>
<p>The second interface, cleverly named ITriviaCallback, lays out the callback contract a client must fulfill in order to play nicely with our server.&nbsp; The operations listed here describe events the server will publish.&nbsp; These aren't actual events, but the
 naming convention &quot;OnX...&quot; helps you remember that these are server published activities.</p>
<p>Notice that the [OperationContract] attribute notifies WCF that each method is part of a service contract.&nbsp; The IsOneWay flag gives us &quot;fire-and-forget&quot; behavior (the app shouldn't wait around for a response).&nbsp; So now that the common objects are ready, let's
 move on to...</p>
<h3>Building the Trivia Server</h3>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773166/YeahTrivia_Server1.jpg"><img height="202" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773166/YeahTrivia_Server.jpg" width="240" border="0"></a>
</p>
<p>The YeahTrivia Server is a simple utility app, but don't let&nbsp;the plain looks fool you; I thought about calling this the BrainStumper Pumper, but this is a family site.&nbsp; This app&nbsp;lets a user (anyone acting as game admin)&nbsp;start the service, select the desired
 game, await team registrations, and then start the game.&nbsp; If this were to become a larger scale project, I would make this an IIS hosted service that manages multiple games and provides more autonomy.&nbsp; Until those sports bar royalty checks start rolling in,
 however, a utility app will do just fine.</p>
<p>The only form, GameServerDashboard, simply provides user interaction with the GameServer class.&nbsp; On startup, the form&nbsp;inits an instance of GameServer and tells it to start the service.&nbsp; It also loads all trivia question sets from the Games directory, and
 displays them in the list.</p>
<p>GameServer is the brain behind YeahTrivia.&nbsp;The attributes below set up the GameServer for action:</p>
<p><strong>C#:</strong><br>
</p>
<pre class="csharpcode">[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant
        ,InstanceContextMode = InstanceContextMode.Single)]
    <span class="kwrd">public</span> <span class="kwrd">class</span> GameServer : ITrivia</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>&nbsp;</p>
<p><strong>VB:</strong><br>
</p>
<pre class="csharpcode">&lt;ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Reentrant, InstanceContextMode:=InstanceContextMode.<span class="kwrd">Single</span>)&gt; _
    <span class="kwrd">Public</span> <span class="kwrd">Class</span> GameServer
        <span class="kwrd">Implements</span> ITrivia</pre>
<pre class="csharpcode"></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>ConcurrencyMode.Reentrant prevents deadlocks between the&nbsp;apps&nbsp;by stating that while this service is single-threaded, callbacks are allowed to invoke&nbsp;new&nbsp;operations.</p>
<p>InstanceContextMode.Single sets the service as a singleton, so that all messages are delivered to the same object instance.</p>
<p>These are advanced topics if you're new to WCF, so I'll include some links at the end that helped clarify some of this for me.&nbsp; Let's keep moving forward by looking at a few activities of the game server:</p>
<p><em>Start the Service:</em>&nbsp; Passes in the configured base address as a Uri, inits and opens a new ServiceHost.</p>
<p><strong>C#:</strong></p>
<blockquote>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> StartService()
{
<span class="rem">   // Set base address and open service host</span>
   Uri baseAddress = <span class="kwrd">new</span> Uri(ConfigurationManager.AppSettings[CONFIG_KEY_BASEURI]);
   _serviceHost = <span class="kwrd">new</span> ServiceHost(<span class="kwrd">new</span> GameServer(), baseAddress);
   _serviceHost.Open();
}</pre>
</blockquote>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong>VB:</strong></p>
<pre class="csharpcode">  <span class="kwrd">Public</span> <span class="kwrd">Sub</span> StartService()
     <span class="rem">'Set base address and open service host</span>
     <span class="kwrd">Dim</span> baseAddress <span class="kwrd">As</span> <span class="kwrd">New</span> Uri(ConfigurationManager.AppSettings(CONFIG_KEY_BASEURI))
     _serviceHost = <span class="kwrd">New</span> ServiceHost(<span class="kwrd">New</span> GameServer(), baseAddress)
     _serviceHost.Open()
  <span class="kwrd">End Sub</span></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><em></em>&nbsp;</p>
<p><em>Register a new team:</em>&nbsp;Saves off the callback, adds it to the callback collection and scoreboard containers, notifies the user of a successful registration, and notifies all game clients of the new team.</p>
<p><strong>C#:</strong></p>
<pre class="csharpcode"> <span class="kwrd">public</span> <span class="kwrd">void</span> RegisterUser(<span class="kwrd">string</span> userName)
 {
     _currentCallback = OperationContext.Current.GetCallbackChannel&lt;ITriviaCallback&gt;();

     <span class="rem">// Store callback</span>
     <span class="kwrd">if</span> (!_callbacks.ContainsKey(userName))
     {
         _callbacks.Add(userName, _currentCallback);
         _scoreboard.Add(userName, 0);
</pre>
<pre class="csharpcode">         <span class="rem">// Notify user of registration</span>
         _currentCallback.OnUserRegistered(userName);
</pre>
<pre class="csharpcode">         <span class="rem">// Notify clients of new user</span>
         <span class="kwrd">foreach</span> (<span class="kwrd">string</span> userKey <span class="kwrd">in</span> _callbacks.Keys)
         {
            _currentCallback = _callbacks[userKey];
            _currentCallback.OnPublishChat(GAME_USERKEY, <span class="kwrd">string</span>.Format(FORMAT_USER_REGISTERED, userName));
         }                
     }
     <span class="kwrd">else</span>
     {
         <span class="rem">// User already registered, throw exception</span>
         <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(ERROR_USER_ALREADY_EXISTS);
     }
 }</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong>VB:</strong></p>
<pre class="csharpcode"><span class="kwrd">Public</span> <span class="kwrd">Sub</span> RegisterUser(<span class="kwrd">ByVal</span> userName <span class="kwrd">As</span> <span class="kwrd">String</span>) <span class="kwrd">Implements</span> ITrivia.RegisterUser
   _currentCallback = OperationContext.Current.GetCallbackChannel(Of ITriviaCallback)()

   <span class="rem">'Store callback</span>
   <span class="kwrd">If</span> <span class="kwrd">Not</span> _callbacks.ContainsKey(userName) <span class="kwrd">Then</span>
      _callbacks.Add(userName, _currentCallback)
      _scoreboard.Add(userName, 0)

      <span class="rem">'Notify user of registration</span>
      _currentCallback.OnUserRegistered(userName)

      <span class="rem">'Notify clients of new user</span>
      <span class="kwrd">For</span> <span class="kwrd">Each</span> userKey <span class="kwrd">As</span> <span class="kwrd">String</span> <span class="kwrd">In</span> _callbacks.Keys
         _currentCallback = _callbacks(userKey)
         _currentCallback.OnPublishChat(GAME_USERKEY, <span class="kwrd">String</span>.Format(FORMAT_USER_REGISTERED, userName))
      <span class="kwrd">Next</span>
   <span class="kwrd">Else</span>
      <span class="rem">'User already registered, throw exception</span>
      <span class="kwrd">Throw</span> <span class="kwrd">New</span> Exception(ERROR_USER_ALREADY_EXISTS)
   <span class="kwrd">End</span> <span class="kwrd">If</span>
<span class="kwrd">End Sub</span></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style><style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>You can start to see how the server is able to handle incoming calls and process them back to the clients using the duplex channel.&nbsp; I'll leave the rest of the server actions for you to examine on your own.</p>
<h3>Building the Game Client (WCF) </h3>
<p>Address, Binding, Contract.&nbsp; These are the ABC's of WCF.&nbsp; The client's app.config file handles connecting to the service and specifying the channel and contract used to interact with it.&nbsp; Examine the client portion of the client .config:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">client</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">endpoint</span> <span class="attr">address</span><span class="kwrd">=&quot;http://localhost:8088/Trivia&quot;</span> <span class="attr">binding</span><span class="kwrd">=&quot;wsDualHttpBinding&quot;</span>
      <span class="attr">bindingConfiguration</span><span class="kwrd">=&quot;WSDualHttpBinding_ITrivia&quot;</span> <span class="attr">contract</span><span class="kwrd">=&quot;Trivia.Common.ITrivia&quot;</span>
      <span class="attr">name</span><span class="kwrd">=&quot;WSDualHttpBinding_ITrivia&quot;</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">endpoint</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">client</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The address points to the exposed service endpoint.&nbsp; The binding sets the channel as &quot;wsDualHttpBinding&quot; (our http duplex channel).&nbsp; The bindingConfiguration attribute is an optional&nbsp;pointer to another group of configurations for the binding, and finally,
 the contract sets the interface with which our client will be interacting.</p>
<p>Next it's time to generate a proxy class.&nbsp;&nbsp;Memorize this: Svcutil.exe is your friend.&nbsp; The client needs a proxy class that it can use to interact with the service model.&nbsp; The&nbsp;utility is a bit tricky at first, because of the wealth of optional flags, but
 stick with it, it's better than coding the proxy class by hand!&nbsp; You can generate your client code by starting the service and running a command line similar to this:</p>
<pre class="csharpcode">svcutil /language:cs /out:ServerProxy.cs <a href="http://localhost:8088/Trivia">http://localhost:8088/Trivia</a></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Add the generated class to the client project and you can begin to interact with the service.&nbsp; The svcutil is available as part of the Windows SDK.&nbsp; Check out the referenced site below&nbsp;for more information on this handy utility.</p>
<h3>Building the Game Client (WPF)</h3>
<p>Building the WPF portion of the client app was really a learning experience, and it will&nbsp;be the&nbsp;priority for me to improve in a later version.&nbsp; Learning to program in XAML markup can seem daunting, and it requires a large paradigm shift on your part in order
 to grasp the new concepts.&nbsp;&nbsp;Microsoft Expression is powerful tool for XAML work, but this time I coded all of the XAML by hand in order to fully see what was taking place inside.</p>
<p>A deep discussion of WPF is beyond the scope of this article, but take a look at the example code to get an idea of the layout.&nbsp; An excellent book to start with is
<u>WPF Unleashed</u> by Adam Nathan.&nbsp; An easy read (for a programming book), and solid examples to get you rolling.</p>
<p>I've set up the client using&nbsp;a instance of the Window class, which is shown below:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Window</span> <span class="attr">x:Class</span><span class="kwrd">=&quot;Trivia.Client.GameClient&quot;</span>
    <span class="attr">xmlns</span><span class="kwrd">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>
    <span class="attr">xmlns:x</span><span class="kwrd">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>
    <span class="attr">Title</span><span class="kwrd">=&quot;YeahTrivia&quot;</span> <span class="attr">MinHeight</span><span class="kwrd">=&quot;620&quot;</span> <span class="attr">MinWidth</span><span class="kwrd">=&quot;620&quot;</span> 
    <span class="attr">WindowStartupLocation</span><span class="kwrd">=&quot;CenterScreen&quot;</span> <span class="attr">WindowState</span><span class="kwrd">=&quot;Normal&quot;</span>  <span class="attr">Style</span><span class="kwrd">=&quot;{DynamicResource MainWindowStyle}&quot;</span>
    <span class="attr">Background</span><span class="kwrd">=&quot;{DynamicResource MainWindowBackgroundBrush}&quot;</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The window class sets up the outermost container of the app, and includes two default namespaces.&nbsp; I've also set a few other properties here: a min height and width, window startup location &amp; state, and two styling attributes set by dynamic resources.</p>
<p>Resources are a great way to further separate form &amp; function, allowing a programmer to handle the behavior of an app, while a designer can work simultaneously on the look, all without stepping on too many toes.&nbsp; As a 2.0 task for this project, I would remove
 all inline styling and move them into resource dictionaries.&nbsp; A dictionary contains styles and control templates (a skin) that can be loaded &amp; switched&nbsp;at runtime.</p>
<p>ResourceDictionaries are linked to your XAML in the App.Xaml file.&nbsp; Once you've set up the reference, the&nbsp;example above show&nbsp;how to&nbsp;reference the current dictionary:&nbsp; The Background and Style&nbsp;properties are set as dynamic resources by naming&nbsp;the Keys specified
 in the&nbsp;ResourceDictionary (DefaultResources.xaml):</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">LinearGradientBrush</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;MainWindowBackgroundBrush&quot;</span> <span class="attr">StartPoint</span><span class="kwrd">=&quot;.45,.45&quot;</span> <span class="attr">EndPoint</span><span class="kwrd">=&quot;.55,.55&quot;</span> <span class="attr">SpreadMethod</span><span class="kwrd">=&quot;Reflect&quot;</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Offset</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">Color</span><span class="kwrd">=&quot;DodgerBlue&quot;</span><span class="kwrd">/&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Offset</span><span class="kwrd">=&quot;.8&quot;</span> <span class="attr">Color</span><span class="kwrd">=&quot;DarkSlateBlue&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">LinearGradientBrush</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">Style</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;{x:Type Window}&quot;</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;MainWindowStyle&quot;</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;FontFamily&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;Trebuchet MS&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Style</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Not quite as easy as CSS, but for a Forms project, it's a nice feature.&nbsp; The sample ResourceDictionary includes a button control template for all of my buttons, based on Rob Eisenberg's excellent article (link below).</p>
<p>One other interesting feature to point out: Take a look at the code-behind class MarshalToUIThread method, which accepts a SendOrPostCallback parameter.&nbsp; This is where&nbsp;the client is transferring actions from the sync thread back to the UI thread.&nbsp; In each
 interface method implementation (OnX..), you can see how I wrap any UI-directed code and assign&nbsp;it to the postCallback field.&nbsp; Passing this to the MarshalToUIThread method simply issues a SynchronizationContext.Post call, and the UI thread executes as expected.</p>
<h3>Creating a New Trivia Game (XML)</h3>
<p>New trivia games can be added at any time using&nbsp;the simple XML format shown here.&nbsp; After installing the server application, simply drop the new .XML file into the Games directory ([Server Install Location]\Yeah Trivia Server\Games).&nbsp; This demo comes pre-loaded
 with Geek Trivia, and&nbsp;a special Halloween Trivia version in case you're feeling festive.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TriviaQuestionDataSet</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;http://tempuri.org/TriviaQuestionDataSet.xsd&quot;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">TriviaQuestion</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">QuestionText</span><span class="kwrd">&gt;</span>Name the highest grossing Monty Python creation.<span class="kwrd">&lt;/</span><span class="html">QuestionText</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">AnswerTextA</span><span class="kwrd">&gt;</span>A) Holy Grail<span class="kwrd">&lt;/</span><span class="html">AnswerTextA</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">AnswerTextB</span><span class="kwrd">&gt;</span>B) The Life of Brian<span class="kwrd">&lt;/</span><span class="html">AnswerTextB</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">AnswerTextC</span><span class="kwrd">&gt;</span>C) Shrubbery<span class="kwrd">&lt;/</span><span class="html">AnswerTextC</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">AnswerTextD</span><span class="kwrd">&gt;</span>D) The Meaning of Life<span class="kwrd">&lt;/</span><span class="html">AnswerTextD</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">CorrectAnswerKey</span><span class="kwrd">&gt;</span>A<span class="kwrd">&lt;/</span><span class="html">CorrectAnswerKey</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">TriviaQuestion</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">TriviaQuestion</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">QuestionText</span><span class="kwrd">&gt;</span>Ferris Bueller's best friend was _________.<span class="kwrd">&lt;/</span><span class="html">QuestionText</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">AnswerTextA</span><span class="kwrd">&gt;</span>A) Sloane Peterson<span class="kwrd">&lt;/</span><span class="html">AnswerTextA</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">AnswerTextB</span><span class="kwrd">&gt;</span>B) Edward R. Rooney<span class="kwrd">&lt;/</span><span class="html">AnswerTextB</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">AnswerTextC</span><span class="kwrd">&gt;</span>C) Charlie Sheen<span class="kwrd">&lt;/</span><span class="html">AnswerTextC</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">AnswerTextD</span><span class="kwrd">&gt;</span>D) Cameron Frye<span class="kwrd">&lt;/</span><span class="html">AnswerTextD</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">CorrectAnswerKey</span><span class="kwrd">&gt;</span>D<span class="kwrd">&lt;/</span><span class="html">CorrectAnswerKey</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">TriviaQuestion</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">TriviaQuestionDataSet</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style><style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<h3>It's Time to Play YeahTrivia</h3>
<p>Install both the Server and Client applications.&nbsp; First, fire up the server, and then start your game client(s).&nbsp; Once everyone has registered a team, select your game and hit &quot;Start Game&quot;.&nbsp;&nbsp;&nbsp; You're off...</p>
<h3>Game Over</h3>
<p>So there you have it.&nbsp; We've seen&nbsp;how WCF manages communication between objects, extracting complicated service protocols away from your code.&nbsp; And just a&nbsp;small subset of the WPF functionality has shown us&nbsp;how quickly a rich, XAML-based UI can come together.&nbsp;
 And maybe, just maybe, you've learned why a CD is 74 minutes long... but I'm not telling.</p>
<p>I challenge you to improve on this initial version of YeahTrivia:&nbsp; Crack open the XAML and add animations, images, video, music &amp; more.&nbsp;&nbsp;Create a self-maintaining server to run multiple games at once.&nbsp; Add a High Score storage system.&nbsp; Extend the WCF settings
 to enable other communication channels.&nbsp; Add a new skin.&nbsp;Create new question files to share with us.&nbsp;&nbsp;Whatever you do, have fun and&nbsp;go nuts.&nbsp; YeahCoding4Fun.</p>
<p>Download <a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/5773166/YeahTrivia.zip">
source files</a></p>
<p>Download <a href="http://employees.claritycon.com/sholstad/blog/Coding4Fun/YeahTrivia/">
compiled demo (C# and VB)</a></p>
<h3>About The Author</h3>
<p>Steve Holstad works as a software consultant for Clarity Consulting in Chicago.&nbsp; He blogs at
<a href="http://blogs.claritycon.com/blogs/steve_holstad/default.aspx" target="_blank">
The Bright Lights</a>, and is available via email at <a href="mailto:sholstad@claritycon.com">
sholstad@claritycon.com</a></p>
<p>&nbsp;</p>
<h3>References</h3>
<p><a href="http://wcf.netfx3.com/" target="_blank">wcf.netfx3.com/</a><br>
<a href="http://wpf.netfx3.com/" target="_blank">wpf.netfx3.com/</a><br>
<a href="http://msdn2.microsoft.com/en-us/library/ms733133.aspx" target="_blank">Generating a client proxy class</a><br>
<a href="http://msdn2.microsoft.com/en-us/library/system.servicemodel.concurrencymode.aspx" target="_blank">ConcurrencyMode</a><br>
<a href="http://msdn2.microsoft.com/en-us/library/ms733133.aspx">SvcUtil.exe Tutorial</a>
<br>
<a href="http://devlicio.us/blogs/rob_eisenberg/archive/2006/12/03/net-3-0-crash-course-part-6-wpf-styles-and-control-templates.aspx" target="_blank">Rob Eisenberg's WPF control template</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><em>Special thanks to <a href="https://blogs.claritycon.com/blogs/bryan_dougherty/default.aspx" target="_blank">
Bryan Dougherty</a> for the WCF jumpstart, <a href="https://blogs.claritycon.com/blogs/kevin_marshall/default.aspx" target="_blank">
Kevin Marshall</a> for the Halloween Trivia and <a href="http://blogs.techrepublic.com.com/geekend/index.php?cat=400&amp;submit=view" target="_blank">
Jay Garmon</a>, creator of TechRepublic's Geek Trivia.</em></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:85a5cfe91af449478d329e7600d1c0ef">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/YeahTrivia-Creating-a-Trivia-ServerClient-with-WPF-and-WCF</comments>
      <itunes:summary>




In this article I&#39;ll take you along for the ride as I attack the learning curve required to create a fun, interactive application using both the Microsoft Windows Presentation Foundation (WPF) and the Windows Communication
 Foundation (WCF). Afterwards, you&#39;ll have a flexible trivia client/server game ready to play by yourself or against friends, coworkers and your local know-it-all.&amp;nbsp;
And in honor of Halloween, I&#39;ve included three games of horror movie trivia.



Steve Holstad
The Bright Lights

Difficulty: Advanced
Time Required: 
6-10 hours
Cost: Free
Software: Visual Studio Express, 2005, 2008 Beta 2

Microsoft .NET Framework 3.0
Hardware: 
Download: Download Source








&amp;nbsp; 
What can YeahTrivia do for me?
Glad you asked. This project started when I decided I wanted to dive headfirst into learning WPF and WCF, without hacking through countless Hello World examples.&amp;nbsp; And I wanted something fun that I could improve over time as my skills developed in these new
 technologies.&amp;nbsp; In this article I&#39;ll take you along for the ride as I attack the learning curve required to create a fun, interactive application using both the Microsoft Windows Presentation Foundation (WPF) and the Windows Communication Foundation (WCF).
 Afterwards, you&#39;ll have a flexible trivia client/server game ready to play by yourself or against friends, coworkers and your local know-it-all.&amp;nbsp; And in honor of Halloween, I&#39;ve included three games of horror movie trivia. 

 
In case you were wondering, the &amp;quot;YeahTrivia&amp;quot; name honors my new bride&amp;nbsp;&amp;amp; her&amp;nbsp;favorite prefix.&amp;nbsp; Think of it as&amp;nbsp;YeeeeaaaaahhTrivia! 
Basic Setup
This demo project was built using Visual Studio 2008 Beta 2, and is based on the Microsoft .NET Framework version 3.0.&amp;nbsp; The game is fed by a small windows app that acts as a game server, providing game selection, user&amp;nbsp;registration, question loading, response
 times, chat messaging&amp;nbsp;and scorekeeping.&amp;nbsp; The server </itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/YeahTrivia-Creating-a-Trivia-ServerClient-with-WPF-and-WCF</link>
      <pubDate>Mon, 29 Oct 2007 21:01:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/YeahTrivia-Creating-a-Trivia-ServerClient-with-WPF-and-WCF</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/5773166_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/5773166_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Steve Holstad</dc:creator>
      <itunes:author>Steve Holstad</itunes:author>
      <slash:comments>12</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/YeahTrivia-Creating-a-Trivia-ServerClient-with-WPF-and-WCF/RSS</wfw:commentRss>
      <category>Gaming</category>
      <category>Halloween</category>
      <category>Windows</category>
      <category>arcade</category>
      <category>windows miscellaneous</category>
      <category>card and board games</category>
    </item>
  <item>
      <title>Explosion at Ebay/PayPal offices on Halloween</title>
      <description><![CDATA[First thing's first, no one was reported injured when <a href="http://www.ktvu.com/news/10205711/detail.html" target="_blank">an explosive device detonated at the Ebay/PayPal HQ</a> in San Jose last night. One window blew out into the night sky, but otherwise there were just a lot of rustled feathers of the two dozen employees shirking their trick or treat responsibilities by working late.<br><br>Let this be a lesson to you kids; <a href="http://en.wikipedia.org/wiki/Ied" target="_blank">improvised explosive devices</a> should only be used to blow open the treat bags of other halloweenies (or to fight an insurgency). They are not considered a means of effective customer feedback.<br><br>(via <a href="http://www.valleywag.com/tech/ebay/ebay-building-bombed-exclusive-ims-from-an-ebayer-inside-the-building-211579.php" target="_blank">Valleywag</a>) <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:07aba15abb6a40f294599e1000d63ae0">]]></description>
      <comments>http://channel9.msdn.com/Blogs/jesse/Explosion-at-EbayPayPal-offices-on-Halloween</comments>
      <itunes:summary>First thing&#39;s first, no one was reported injured when an explosive device detonated at the Ebay/PayPal HQ in San Jose last night. One window blew out into the night sky, but otherwise there were just a lot of rustled feathers of the two dozen employees shirking their trick or treat responsibilities by working late.Let this be a lesson to you kids; improvised explosive devices should only be used to blow open the treat bags of other halloweenies (or to fight an insurgency). They are not considered a means of effective customer feedback.(via Valleywag)</itunes:summary>
      <link>http://channel9.msdn.com/Blogs/jesse/Explosion-at-EbayPayPal-offices-on-Halloween</link>
      <pubDate>Wed, 01 Nov 2006 19:25:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/jesse/Explosion-at-EbayPayPal-offices-on-Halloween</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/on10_8961_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/on10_8961_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/content/on10/blogs/ebay_bomb_320.jpg" height="240" width="320"></media:thumbnail>      
      <dc:creator>JD Lewin</dc:creator>
      <itunes:author>JD Lewin</itunes:author>
      <slash:comments>2</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/jesse/Explosion-at-EbayPayPal-offices-on-Halloween/RSS</wfw:commentRss>
      <category>Ebay</category>
      <category>Halloween</category>
      <category>paypal</category>
      <category>terror</category>
    </item>
  <item>
      <title>Happy Halloween - Laura and I break down our Top Four Freaky Freebies!</title>
      <description><![CDATA[This is what happens when Laura and Tina get no sleep and Halloween is approaching.&nbsp; What started off as a serious free downloads Halloween special has turned into a glimpse of something, well not so serious.&nbsp; Yes, that's me as Clifford the Big Red Dog and Laura as Cat in the Hat.&nbsp; We have been drinking many, many diet cokes by the time we actually started filming and needless to say it was a long day.&nbsp; We hope all of you have a wonderful Halloween and here are FOUR Freaky Free Downloads for your viewing pleasure.&nbsp; I've listed them here because we butcher some of the titles along the way as you're about to see.&nbsp; Happy Halloween!&nbsp; <br><br><a href="http://www.fileplanet.com/124800/120000/fileinfo/Return-to-Castle-Wolfenstein:-Enemy-Territory-Client-v2.6" target="_blank">Return to Castle Wolfenstein:&nbsp; Enemy Territory</a><br><a href="http://www.fileplanet.com/167356/160000/fileinfo/Lineage-II-Chronicle-5:-Oath-of-Blood-Client" target="_blank">Lineage II Chronicle 5:&nbsp; Oath of Blood Client</a><br><a href="http://www.fileplanet.com/166052/160000/fileinfo/Dark-Messiah-of-Might-&amp;-Magic-Singleplayer-Demo" target="_blank">Dark Messiah of Might &amp; Magic </a><br><a href="http://www.fileplanet.com/166052/160000/fileinfo/Dark-Messiah-of-Might-&amp;-Magic-Singleplayer-Demo" target="_blank">Medieval II:&nbsp; Total War</a><br> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:2a6389c0481248f8a8549e0f000c55da">]]></description>
      <comments>http://channel9.msdn.com/Blogs/Tina/Happy-Halloween-Laura-and-I-break-down-our-Top-Four-Freaky-Freebies</comments>
      <itunes:summary>This is what happens when Laura and Tina get no sleep and Halloween is approaching.&amp;nbsp; What started off as a serious free downloads Halloween special has turned into a glimpse of something, well not so serious.&amp;nbsp; Yes, that&#39;s me as Clifford the Big Red Dog and Laura as Cat in the Hat.&amp;nbsp; We have been drinking many, many diet cokes by the time we actually started filming and needless to say it was a long day.&amp;nbsp; We hope all of you have a wonderful Halloween and here are FOUR Freaky Free Downloads for your viewing pleasure.&amp;nbsp; I&#39;ve listed them here because we butcher some of the titles along the way as you&#39;re about to see.&amp;nbsp; Happy Halloween!&amp;nbsp; Return to Castle Wolfenstein:&amp;nbsp; Enemy TerritoryLineage II Chronicle 5:&amp;nbsp; Oath of Blood ClientDark Messiah of Might &amp;amp; Magic Medieval II:&amp;nbsp; Total War</itunes:summary>
      <itunes:duration>673</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/Tina/Happy-Halloween-Laura-and-I-break-down-our-Top-Four-Freaky-Freebies</link>
      <pubDate>Tue, 31 Oct 2006 18:54:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/Tina/Happy-Halloween-Laura-and-I-break-down-our-Top-Four-Freaky-Freebies</guid>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_custom_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_2MB_ch9.wmv" expression="full" duration="673" fileSize="210681694" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_ch9.mp3" expression="full" duration="673" fileSize="5388177" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_ch9.webm" expression="full" duration="673" fileSize="64825485" type="video/webm" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_ch9.wma" expression="full" duration="673" fileSize="5460243" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_ch9.wmv" expression="full" duration="673" fileSize="148105471" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_high_ch9.mp4" expression="full" duration="673" fileSize="181870414" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_low_ch9.mp4" expression="full" duration="673" fileSize="68058273" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_med_ch9.mp4" expression="full" duration="673" fileSize="139805074" type="video/mp4" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006.ism/manifest" expression="full" duration="673" fileSize="6262" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ak.channel9.msdn.com/ch9/55da/2a6389c0-4812-48f8-a854-9e0f000c55da/Halloween2006_ch9.wmv" length="148105471" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Tina</dc:creator>
      <itunes:author>Tina</itunes:author>
      <slash:comments>21</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/Tina/Happy-Halloween-Laura-and-I-break-down-our-Top-Four-Freaky-Freebies/RSS</wfw:commentRss>
      <category>free</category>
      <category>Halloween</category>
      <category>Seattle</category>
      <category>Video Games</category>
    </item>
  <item>
      <title>Reusable Body Parts</title>
      <description><![CDATA[
<p>Clint Rutkas</p>
<p>&nbsp;</p>
<p>What screams Halloween more than fake body parts? Fake body parts that twitch and are covered with blood. The second thing that screams Halloween is causing some mischief.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905562/hand1.jpg"><img height="180" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905562/hand.jpg" width="240" border="0"></a>
</p>
<p>&nbsp;</p>
<h3>Black cats of Hardware</h3>
<p>I got to say, I love <a href="http://www.phidgets.com/">Phidgets</a>. They are relatively inexpensive USB items that power motors and have a great API with tons of examples. My only issue I have is I follow what my teachers and mother told me far too much
 to the letter. I attempted to reuse and modify what I had instead of buying what I need to get the job done. After buying three separate items, I finally got the correct item for this task. I got a PhidgetMotorControl LV.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905562/phidget1.jpg"><img height="180" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905562/phidget.jpg" width="240" border="0"></a>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>The failed purchase and why.</h3>
<p>Attempt 1: The PhidgetTextLCD 8/8/8 </p>
<p>Why did this Phidget fail to work for this application? It couldn't provide enough power to the motor. The hand moved far more like something caught in a black hole than anything remotely scary.
</p>
<p>Attempt 2: The Phidget Servo 4-Motor </p>
<p>My attempt to piggy back on top of a Servo control failed pretty badly. I forgot an important thing with servos which is they are always on. I got this initially for a different project and figured I could modify it to fit my need.
</p>
<h3>Mod the hand with internal water cooling!</h3>
<p>Wait, no, I didn't do that, but it would be cooler if I did. Getting the hand to work with the Phidget was rather easy. I soldered some extension wires into the battery pack and then hooked it into the Phidget.
</p>
<h3>Black cats of Hardware</h3>
<p>This is a relatively easy program. Due to Phidget's awesome and easy to use API, I had the program up and working in a matter of minutes. I spent more time messing around with the layout and finding a cool background than I did typing.
</p>
<p>&nbsp;<a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905562/entireSetup2.jpg"><img height="317" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905562/entireSetup_thumb.jpg" width="423" border="0"></a>
</p>
<h3>The entire application, in a c# power cord.</h3>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Form1 : Form
    {
        <span class="kwrd">public</span> Form1()
        {
            InitializeComponent();
        }

        MotorControl motor;
        
        <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> btnMoveStart = <span class="str">&quot;Force Start Movement&quot;</span>;
        <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> btnMoveEnd = <span class="str">&quot;Force Stop Movement&quot;</span>;

        <span class="kwrd">private</span> <span class="kwrd">void</span> Form1_Load(<span class="kwrd">object</span> sender, EventArgs e)
        {
            motor = <span class="kwrd">new</span> MotorControl();
            Servo_Detach(<span class="kwrd">null</span>, <span class="kwrd">null</span>);
            
            motor.Attach &#43;= <span class="kwrd">new</span> AttachEventHandler(Servo_Attach);
            motor.Detach &#43;= <span class="kwrd">new</span> DetachEventHandler(Servo_Detach);
            
            btnMove.Text = btnMoveStart;
            
            motor.open();
        }

        <span class="kwrd">void</span> Servo_Detach(<span class="kwrd">object</span> sender, DetachEventArgs e)
        {
            btnMove.Enabled = <span class="kwrd">false</span>;
            txtStatus.Text = <span class="str">&quot;NOT CONNECTED&quot;</span>;
            txtStatus.ForeColor = Color.Red;
        }
        <span class="kwrd">private</span> <span class="kwrd">void</span> Servo_Attach(<span class="kwrd">object</span> sender, AttachEventArgs e)
        {
            btnMove.Enabled = <span class="kwrd">true</span>;
            txtStatus.Text = <span class="str">&quot;CONNECTED&quot;</span>;
            txtStatus.ForeColor = Color.Green;
        }

        <span class="kwrd">private</span> <span class="kwrd">void</span> btnMove_Click(<span class="kwrd">object</span> sender, EventArgs e)
        {
            <span class="kwrd">if</span> (btnMove.Text == btnMoveStart)
            {
                btnMove.Text = btnMoveEnd;
                motor.motors[1].Velocity = 75;
            }
            <span class="kwrd">else</span>
            {
                btnMove.Text = btnMoveStart;
                motor.motors[1].Velocity = 0;
            }
        }

        <span class="kwrd">private</span> <span class="kwrd">void</span> Form1_FormClosing(<span class="kwrd">object</span> sender, FormClosingEventArgs e)
        {
            <span class="kwrd">if</span> (motor.Attached)
                motor.close();
        }
    }
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>&nbsp;</p>
<h3>Now in a Visual Basic chord</h3>
<pre class="csharpcode"><span class="kwrd">Public</span> <span class="kwrd">Class</span> Form1
    <span class="kwrd">Inherits</span> Form

    <span class="kwrd">Private</span> motor <span class="kwrd">As</span> MotorControl

    <span class="kwrd">Private</span> <span class="kwrd">Const</span> btnMoveStart <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;Force Start Movement&quot;</span>

    <span class="kwrd">Private</span> <span class="kwrd">Const</span> btnMoveEnd <span class="kwrd">As</span> <span class="kwrd">String</span> = <span class="str">&quot;Force Stop Movement&quot;</span>

    <span class="kwrd">Public</span> <span class="kwrd">Sub</span> <span class="kwrd">New</span>()
        <span class="kwrd">MyBase</span>.<span class="kwrd">New</span>()
        InitializeComponent()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Private</span> <span class="kwrd">Sub</span> Form1_Load(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> <span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> EventArgs) <span class="kwrd">Handles</span> <span class="kwrd">MyBase</span>.Load
        motor = <span class="kwrd">New</span> MotorControl
        <span class="kwrd">Me</span>.Servo_Detach(<span class="kwrd">Nothing</span>, <span class="kwrd">Nothing</span>)
        <span class="kwrd">AddHandler</span> motor.Attach, <span class="kwrd">AddressOf</span> <span class="kwrd">Me</span>.Servo_Attach
        <span class="kwrd">AddHandler</span> motor.Detach, <span class="kwrd">AddressOf</span> <span class="kwrd">Me</span>.Servo_Detach
        btnMove.Text = btnMoveStart
        motor.open()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Private</span> <span class="kwrd">Sub</span> Servo_Detach(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> <span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> DetachEventArgs)
        btnMove.Enabled = <span class="kwrd">False</span>
        txtStatus.Text = <span class="str">&quot;NOT CONNECTED&quot;</span>
        txtStatus.ForeColor = Color.Red
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Private</span> <span class="kwrd">Sub</span> Servo_Attach(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> <span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> AttachEventArgs)
        btnMove.Enabled = <span class="kwrd">True</span>
        txtStatus.Text = <span class="str">&quot;CONNECTED&quot;</span>
        txtStatus.ForeColor = Color.Green
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Private</span> <span class="kwrd">Sub</span> btnMove_Click(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> <span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> EventArgs) <span class="kwrd">Handles</span> btnMove.Click
        <span class="kwrd">If</span> (btnMove.Text = btnMoveStart) <span class="kwrd">Then</span>
            btnMove.Text = btnMoveEnd
            motor.motors(1).Velocity = 75
        <span class="kwrd">Else</span>
            btnMove.Text = btnMoveStart
            motor.motors(1).Velocity = 0
        <span class="kwrd">End</span> <span class="kwrd">If</span>
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Private</span> <span class="kwrd">Sub</span> Form1_FormClosing(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> <span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> FormClosingEventArgs) <span class="kwrd">Handles</span> <span class="kwrd">MyBase</span>.FormClosing
        <span class="kwrd">If</span> motor.Attached <span class="kwrd">Then</span>
            motor.close()
        <span class="kwrd">End</span> <span class="kwrd">If</span>
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>
<span class="kwrd">End</span> <span class="kwrd">Class</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>&nbsp;</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905562/interface1.gif"><img height="205" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905562/interface.gif" width="240"></a> &nbsp;</p>
<p>&nbsp;</p>
<h3></h3>
<h3>Let the hunt begin for prank monkeys</h3>
<p>Here is one of my favorite victims, Chris King, to prank. </p>
<ul>
<li><a href="http://www.coding4fun.net/media/cking.wmv">Prank Video with motion hand</a></li></ul>
<p>&nbsp;</p>
<h3>Conclusion</h3>
<p>Hacking hardware is easy if you buy the right toys. What can be done to make this better and cooler? I could add in an IR sensor with the 8/8/8 and use that to detect if people are near the hand.
</p>
<p>&nbsp; </p>
<p>Author bio: Clint is an application developer for <a href="http://springcm.com/">
SpringCM</a>, an on-demand, web-based document and content management system. As a developer, Clint is part of an innovative team committed to supporting affordable, scalable and reliable enterprise content management. His two primary development languages
 are C# and JavaScript. Prior to the Halloween Dead Hand project, he worked on his
<a href="http://msdn.microsoft.com/coding4fun/coolapplications/disco/default.aspx">
Disco Dance Floor</a>. In his off time, he whips up other random weird projects and does twenty something activities with his friends. Clint's blog is
<a href="http://betterthaneveryone.com/">betterthaneveryone.com</a> and can be emailed at
<a href="mailto:clint@rutkas.com">clint@rutkas.com</a>. </p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:96330161f43e4441ab609e7600dc14df">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Reusable-Body-Parts</comments>
      <itunes:summary>
Clint Rutkas 
&amp;nbsp; 
What screams Halloween more than fake body parts? Fake body parts that twitch and are covered with blood. The second thing that screams Halloween is causing some mischief. 

 
&amp;nbsp; 
Black cats of Hardware
I got to say, I love Phidgets. They are relatively inexpensive USB items that power motors and have a great API with tons of examples. My only issue I have is I follow what my teachers and mother told me far too much
 to the letter. I attempted to reuse and modify what I had instead of buying what I need to get the job done. After buying three separate items, I finally got the correct item for this task. I got a PhidgetMotorControl LV.
 
&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp; 
The failed purchase and why.
Attempt 1: The PhidgetTextLCD 8/8/8  
Why did this Phidget fail to work for this application? It couldn&#39;t provide enough power to the motor. The hand moved far more like something caught in a black hole than anything remotely scary.
 
Attempt 2: The Phidget Servo 4-Motor  
My attempt to piggy back on top of a Servo control failed pretty badly. I forgot an important thing with servos which is they are always on. I got this initially for a different project and figured I could modify it to fit my need.
 
Mod the hand with internal water cooling!
Wait, no, I didn&#39;t do that, but it would be cooler if I did. Getting the hand to work with the Phidget was rather easy. I soldered some extension wires into the battery pack and then hooked it into the Phidget.
 
Black cats of Hardware
This is a relatively easy program. Due to Phidget&#39;s awesome and easy to use API, I had the program up and working in a matter of minutes. I spent more time messing around with the layout and finding a cool background than I did typing.
 
&amp;nbsp;
 
The entire application, in a c# power cord.
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        MotorControl motor;
        
        private const string btnMoveStart </itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Reusable-Body-Parts</link>
      <pubDate>Tue, 31 Oct 2006 03:39:51 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Reusable-Body-Parts</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/905562_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/905562_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Clint Rutkas</dc:creator>
      <itunes:author>Clint Rutkas</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Reusable-Body-Parts/RSS</wfw:commentRss>
      <category>Halloween</category>
      <category>events</category>
    </item>
  <item>
      <title>Scary Halloween Application</title>
      <description><![CDATA[
<p></p>
<span id="c4fmetadata">
<table cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td width="50"><img height="50" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905508/article_thumb.png" width="50"></td>
<td><span class="entry_description">Build an application that will drip animated blood down your victim's computer screen for a scary Halloween treat!</span></td>
</tr>
<tr>
<td colspan="2">
<div class="entry_author">Brian Peek</div>
<div class="entry_company"><a href="http://www.aspsoft.com/" target="_blank">ASPSOFT, Inc.</a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
Less than 1 hour</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/" target="_blank">Visual Basic or Visual C# Express Editions</a></span></div>
<div class="entry_details"><strong>Hardware: </strong>None</div>
<div class="entry_details"><b>Download: </b><a href="http://channel9.msdn.com/ShowPost.aspx?PostID=251376" target="_blank">Download</a>
</div>
<div class="entry_details">&nbsp;</div>
<h3>Introduction</h3>
</td>
</tr>
</tbody>
</table>
</span>
<p>If you're anything like me, and I hope for your friends' and family's sake you're not, you believe that annoying others is amazingly entertaining. If that's the case, then this article is for you.
</p>
<p>We are going to build an application that you will copy to a friend's PC that will, at a specified date and time, cause the computer to appear to start dripping blood down the screen and, after a few seconds, switch to a full-screen image of something terrifying
 while playing a screaming sound effect. This should sufficiently scare your victim for Halloween (hear the
<a class="" href="http://www.coding4fun.net/media/scream.wav">built-in scary sound</a>).
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905508/bloody_desktop2.png"><img height="261" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905508/bloody_desktop_thumb.png" width="348" border="0"></a>
</p>
<h3><b>The Form</b> </h3>
<p>We will be creating a full-screen, always-on-top, transparent form that will overlay the entire screen. This will be our display surface for the dripping blood.
</p>
<p>The form can be created as described by modifying the following properties: </p>
<p><b>BackColor</b> – Fuchsia </p>
<p><b>FormBorderStyle</b> – None </p>
<p><b>DoubleBuffered</b> – True </p>
<p><b>Text</b> - &lt;empty string&gt; </p>
<p><b>WindowState</b> – Maximized </p>
<p><b>ShowInTaskbar</b> – False </p>
<p><b>TransparencyKey</b> – Fuchsia </p>
<p><b>TopMost</b> - True </p>
<p>This will create our full-screen, transparent form with no visible name, no icon in the task bar, no border that will remain on top of all other windows. With this in place, we can draw whatever we want to on to the form and it will be displayed over whatever
 happens to be on the screen. A nice bonus to this is that even though the form is maximized, because it is transparent, mouse and keyboard events will pass through to the visible active forms below. The user's PC should act as though nothing is happening!
</p>
<h3><b>The Blood</b>
<h3></h3>
I created a class named <b>BloodDrop</b> to represent the on-screen blood droplets flowing down the screen. When a droplet is instantiated, it loads its frames of animation from a series of images saved as resources in the application. Each image is located
 in a directory named <b>images</b> in the project, and its <b>Build Action</b> property is set to
<b>Embedded Resource</b>. </h3>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905508/embedded1.png"><img height="240" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905508/embedded.png" width="220" border="0"></a>
</p>
<p>With the images set as resources, we can load the images in the <b>BloodDrop</b> constructor as follows:
</p>
<p><strong>Visual Basic</strong> </p>
<pre class="csharpcode"><span class="kwrd">Public</span> <span class="kwrd">Sub</span> <span class="kwrd">New</span>()
    <span class="rem">' load each animation frame from the app's resources and add it to our frame list</span>
    <span class="kwrd">For</span> <span class="kwrd">Each</span> file <span class="kwrd">As</span> <span class="kwrd">String</span> <span class="kwrd">In</span> _files
        <span class="kwrd">Dim</span> img <span class="kwrd">As</span> Image = Image.FromStream(<span class="kwrd">Assembly</span>.GetExecutingAssembly().GetManifestResourceStream(<span class="str">&quot;HalloweenVB.&quot;</span> &#43; file))
        _frames.Add(img)
    <span class="kwrd">Next</span>

    <span class="rem">' set our first frame</span>
    _image = _frames(0)
<span class="kwrd">End</span> <span class="kwrd">Sub</span>
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong></strong></p>
<p><strong>Visual C#</strong> </p>
<pre class="csharpcode"><span class="kwrd">public</span> BloodDrop()
{
    <span class="rem">// load each animation frame from the app's resources and add it to our frame list</span>
    <span class="kwrd">foreach</span>(<span class="kwrd">string</span> file <span class="kwrd">in</span> _files)
    {
        Image img = Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(<span class="str">&quot;Halloween.images.&quot;</span> &#43; file));
        _frames.Add(img);
    }

    <span class="rem">// set our first frame</span>
    _image = _frames[0];
}
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The <b>FromStream</b> method of the <b>Image</b> object allows loading of an image file from an application's embedded resource list. To get access to the stream for a specific resource, the name of the resource needs to be known, which is the fully qualified
 name of the file. In the case of the C# project, the resources are named <b>Halloween.images.&lt;filename&gt;</b>. The VB project's resources are named
<b>HalloweenVB.&lt;filename&gt;</b>. Though the images are stored in a directory named <b>
images</b> in both projects, only the C# version includes the directory name as part of the fully qualified name.
</p>
<p>In either case, each file is loaded and stored in a <b>List</b> of <b>Image</b> objects.
</p>
<h3><b>Drawing</b> </h3>
<p>In creating this application, I decided to stay entirely within the framework so deployment would be as simple as copying a single executable to your victim's machine. Therefore, I decided to use standard GDI&#43; calls for drawing, instead of Managed DirectX
 or some other method. </p>
<p>At first, I experimented with making each blood droplet a <b>PictureBox</b> control and moving the control down the screen, but that was not quick enough for smooth animation. I next tried using a timer and drawing to the screen directly inside the
<b>Tick</b> event, however this too was too jerky. Finally, I set the <b>Tick</b> event to simply invalidate the screen, causing the
<b>OnPaint</b> event to fire. I found that performing screen updates inside this method with the
<b>DoubleBuffered</b> property set to <b>True</b> allowed for the smoothest animation.
</p>
<p>When the blood is set to be drawn, a timer is started that ticks every 100 milliseconds. This timer simply calls the
<b>Invalidate</b> method of the current form object. When invalidated, the form calls its
<b>OnPaint</b> handler, which we override. </p>
<p>Inside the <b>OnPaint</b> handler, we create a new <b>BloodDrop</b> object and assign a random horizontal position and vertical velocity to it. This provides for an interesting display as the blood drips down. The newly created
<b>BloodDrop</b> is then added to a <b>List</b> of <b>BloodDrop</b> types. Finally, the full list of blood drops is enumerated, animated, and drawn.
</p>
<p><strong>Visual Basic</strong> </p>
<pre class="csharpcode"><span class="rem">' create a new blood drop</span>
<span class="kwrd">Dim</span> drop <span class="kwrd">As</span> BloodDrop = <span class="kwrd">New</span> BloodDrop()

<span class="rem">' set it to a random location on the screen</span>
drop.Location = <span class="kwrd">New</span> Point(_random.<span class="kwrd">Next</span>(SystemInformation.PrimaryMonitorSize.Width), 0)

<span class="rem">' set it's velocity to a random number</span>
drop.Velocity = _random.<span class="kwrd">Next</span>(40) &#43; 20

<span class="rem">' add it to our drawing list</span>
_dropList.Add(drop)

<span class="rem">' enumerate the drawing list</span>
<span class="kwrd">For</span> <span class="kwrd">Each</span> bd <span class="kwrd">As</span> BloodDrop <span class="kwrd">In</span> _dropList
    <span class="rem">' animate and then draw the drop            </span>
    bd.Animate()
    bd.Draw(g)
Next</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<pre class="csharpcode">&nbsp;</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong>Visual C#</strong> </p>
<pre class="csharpcode"><span class="rem">// create a new blood drop</span>
BloodDrop drop = <span class="kwrd">new</span> BloodDrop();

<span class="rem">// set it to a random location on the screen</span>
drop.Location = <span class="kwrd">new</span> Point(_random.Next(SystemInformation.PrimaryMonitorSize.Width), 0);

<span class="rem">// set it's velocity to a random number</span>
drop.Velocity = _random.Next(40) &#43; 20;

<span class="rem">// add it to our drawing list</span>
_dropList.Add(drop);

<span class="rem">// enumerate the drawing list</span>
<span class="kwrd">foreach</span>(BloodDrop bd <span class="kwrd">in</span> _dropList)
{    
    <span class="rem">// animate and then draw the drop            </span>
    bd.Animate();
    bd.Draw(g);
}
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>At application startup, an instance of the <b>Random </b>class is created and stored in our
<b>_random</b> member variable. The <b>Next</b> method requires a parameter for the maximum value of the random number to be returned. In the case of setting the drop's location, I use the maximum screen width, determined by using the
<b>SystemInformation</b> object. In the case of velocity, a maximum value of 40 pixels is requested, and an additional 20 pixels is added on in case a very low number is randomly selected.
</p>
<p>Drawing the actual drop is pretty simple. The <b>Draw</b> method of our <b>BloodDrop</b> class looks like the following:
</p>
<p><strong>Visual Basic</strong> </p>
<pre class="csharpcode"><span class="rem">' draw the drop</span>
<span class="kwrd">Public</span> <span class="kwrd">Sub</span> Draw(<span class="kwrd">ByVal</span> g <span class="kwrd">As</span> Graphics)
    <span class="rem">' if we're in &quot;drop&quot; mode, draw the stream behind it</span>
    <span class="kwrd">If</span> _index &gt;= 4 <span class="kwrd">Then</span>
        g.DrawImage(_frames(4), <span class="kwrd">Me</span>._location.X &#43; 24, 0, _frames(4).Width, <span class="kwrd">Me</span>._location.Y &#43; 10)
    <span class="kwrd">End</span> <span class="kwrd">If</span>

    <span class="rem">' if we're beyond the bottom of the screen, don't bother drawing the drop</span>
    <span class="kwrd">If</span> <span class="kwrd">Me</span>._location.Y &lt; SystemInformation.PrimaryMonitorSize.Height <span class="kwrd">Then</span>
        g.DrawImage(_image, <span class="kwrd">Me</span>._location.X, <span class="kwrd">Me</span>._location.Y, _image.Width, _image.Height)
    <span class="kwrd">End</span> <span class="kwrd">If</span>
<span class="kwrd">End</span> <span class="kwrd">Sub</span></pre>
<pre class="csharpcode"><span class="kwrd"></span>
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong>Visual C#</strong> </p>
<pre class="csharpcode"><span class="rem">// draw the drop</span>
<span class="kwrd">public</span> <span class="kwrd">void</span> Draw(Graphics g)
{
    <span class="rem">// if we're in &quot;drop&quot; mode, draw the stream behind it</span>
    <span class="kwrd">if</span>(_index &gt;= 4)
        g.DrawImage(_frames[4], <span class="kwrd">this</span>._location.X &#43; 24, 0, _frames[4].Width, <span class="kwrd">this</span>._location.Y &#43; 10);

    <span class="rem">// if we're beyond the bottom of the screen, don't bother drawing the drop</span>
    <span class="kwrd">if</span>(<span class="kwrd">this</span>._location.Y &lt; SystemInformation.PrimaryMonitorSize.Height)
        g.DrawImage(_image, <span class="kwrd">this</span>._location.X, <span class="kwrd">this</span>._location.Y, _image.Width, _image.Height);
}
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>In each case, we use the <b>Graphics</b> object provided to us and use the <b>
DrawImage</b> method to draw the correct frame number to the correct position. In order to save some CPU cycles, we first determine whether the drop has passed the lower edge of the screen and, if it is, it is not drawn. The size of the screen can be determined
 by using the <b>SystemInformation</b> object and using the <b>PrimaryMonitorSize</b> method.
</p>
<p>The second part of this method draws the blood trail that follows behind the droplet as it falls. This is done by stretching an image that is 1 pixel tall down the screen to the top of the blood drop graphic.
</p>
<p>In my first attempts at drawing the blood in this manner, I found that the <b>
DrawImage</b> method, when scaling an image as it is doing here, will anti-alias and blend the image to make it appear less blocky. Unfortunately, this caused a great deal of distortion, making the trail look awful. After some experimenting, I found that setting
 the following properties of the <b>Graphics</b> object before drawing would allow the image to be stretched without modification.
</p>
<p><strong>Visual Basic</strong> </p>
<pre class="csharpcode"><span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> OnPaint(<span class="kwrd">ByVal</span> e <span class="kwrd">As</span> System.Windows.Forms.PaintEventArgs)
    ...
    <span class="rem">' grab the Graphics object for me app and set some properties for correct drawing</span>
    <span class="kwrd">Dim</span> g <span class="kwrd">As</span> Graphics = e.Graphics
    g.PixelOffsetMode = PixelOffsetMode.Half
    g.InterpolationMode = InterpolationMode.NearestNeighbor
    g.CompositingQuality = CompositingQuality.HighSpeed
    ...
<span class="kwrd">End</span> <span class="kwrd">Sub</span>
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong></strong>&nbsp; </p>
<p><strong>Visual C#</strong> </p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnPaint(PaintEventArgs e)
{
    ...
    <span class="rem">// grab the Graphics object for this app and set some properties for correct drawing</span>
    Graphics g = e.Graphics;
    g.PixelOffsetMode = PixelOffsetMode.Half;
    g.InterpolationMode = InterpolationMode.NearestNeighbor;
    g.CompositingQuality = CompositingQuality.HighSpeed;
    ...
}
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<h3><b>The Finale</b> </h3>
<p>After the blood has dripped down the screen for several seconds (10 in the default case), the animation timer is disabled, the screen is cleared and a scary image is quickly displayed along with a loud screaming sound, which should hopefully scare the person
 at the keyboard. A running count of the time elapsed is stored in a member variable and is incremented by the timer's
<b>Interval</b> value each time our <b>OnPaint</b> method is called. </p>
<p>This is accomplished by creating a <b>PictureBox</b> on the fly and loading an image into the box. This box is then added to the
<b>Controls</b> collection of the form and displayed. Additionally, two events are handled that will dismiss the application when a user clicks the mouse or presses a key on the keyboard.
</p>
<p>The sound is then loaded from a resource and played using the <b>SoundPlay</b> object. This looks like the following:
</p>
<p><strong>Visual Basic</strong> </p>
<pre class="csharpcode"><span class="rem">' disable the animation timer </span>
tmrAnim.Enabled = <span class="kwrd">False</span>

<span class="rem">' create a Picturebox</span>
<span class="kwrd">Dim</span> pb <span class="kwrd">As</span> PictureBox = <span class="kwrd">New</span> PictureBox()

<span class="rem">' pull in the scary image from our resources</span>
pb.Image = Image.FromStream(<span class="kwrd">Assembly</span>.GetExecutingAssembly().GetManifestResourceStream(<span class="str">&quot;HalloweenVB.scary.jpg&quot;</span>))

<span class="rem">' set it to fill the screen</span>
pb.SizeMode = PictureBoxSizeMode.Zoom
pb.Width = SystemInformation.PrimaryMonitorSize.Width
pb.Height = SystemInformation.PrimaryMonitorSize.Height
pb.BackColor = Color.Black

<span class="rem">' if it gets clicked, or someone presses a key, we want to end the app</span>
<span class="kwrd">AddHandler</span> pb.Click, <span class="kwrd">AddressOf</span> pb_Click
<span class="kwrd">AddHandler</span> <span class="kwrd">Me</span>.KeyDown, <span class="kwrd">AddressOf</span> MainForm_KeyDown

<span class="rem">' add the Picturebox to the controls list</span>
<span class="kwrd">Me</span>.Controls.Add(pb)

<span class="rem">' play a scary sound</span>
<span class="kwrd">Dim</span> sp <span class="kwrd">As</span> SoundPlayer = <span class="kwrd">New</span> SoundPlayer(<span class="kwrd">Assembly</span>.GetExecutingAssembly().GetManifestResourceStream(<span class="str">&quot;HalloweenVB.scream.wav&quot;</span>))
sp.Play()</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style><style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong></strong>&nbsp;</p>
<p><strong>Visual C#</strong></p>
<pre class="csharpcode"><span class="rem">// disable the animation timer</span>
tmrAnim.Enabled = <span class="kwrd">false</span>;

<span class="rem">// create a Picturebox</span>
PictureBox pb = <span class="kwrd">new</span> PictureBox();

<span class="rem">// pull in the scary image from our resources</span>
pb.Image = Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(<span class="str">&quot;Halloween.images.scary.jpg&quot;</span>));

<span class="rem">// set it to fill the screen</span>
pb.SizeMode = PictureBoxSizeMode.Zoom;
pb.Width = SystemInformation.PrimaryMonitorSize.Width;
pb.Height = SystemInformation.PrimaryMonitorSize.Height;
pb.BackColor = Color.Black;

<span class="rem">// if it gets clicked, or someone presses a key, we want to end the app</span>
pb.Click &#43;= <span class="kwrd">new</span> EventHandler(pb_Click);
<span class="kwrd">this</span>.KeyDown &#43;= <span class="kwrd">new</span> KeyEventHandler(MainForm_KeyDown);

<span class="rem">// add the Picturebox to the controls list</span>
<span class="kwrd">this</span>.Controls.Add(pb);

<span class="rem">// play a scary sound</span>
SoundPlayer sp = <span class="kwrd">new</span> SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream(<span class="str">&quot;Halloween.scream.wav&quot;</span>));
sp.Play();
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style><style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style><style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>As you can see, the sound and image resources are loaded in an identical manner as the frames of animation shown earlier.
</p>
<h3><b>The Scheduler</b> </h3>
<p>The final piece of the puzzle was to allow a user to select the date and time that the animation would start on the victim's PC. I created a simple configuration dialog box that is displayed the first time the application is run. The dialog allows the person
 setting up the application to choose the date and time the animation should be fired. This is saved using the
<b>Settings</b> object of the project. This way, the user can put the application in the startup group, or create a registry key to load it on startup, so if the PC is rebooted before the desired time is reached, the application will restart and wait for the
 time to occur. </p>
<p>Settings can be added by right-clicking the project in the <b>Solution Explorer</b> and choosing
<b>Properties</b>. Select the <b>Settings</b> tab and a new value can be entered. The one for this application looks like the following:
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905508/Settings2.png"><img height="100" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905508/Settings_thumb.png" width="240" border="0"></a>
</p>
<p>Now, on application startup, the application's <b>Settings</b> can be checked to determine if the configuration dialog needs to be shown, or just wait for the time specified.
</p>
<p>When the application is started, a scheduler timer is created which ticks every minute. The
<b>Tick </b>method for this timer looks at the current time, and if it is greater than or equal to the specified time, it will disable the scheduler timer, maximize the hidden window, and start the animation timer, which will automatically start drawing our
 blood droplets. </p>
<p><strong>Visual Basic</strong> </p>
<pre class="csharpcode"><span class="kwrd">Private</span> <span class="kwrd">Sub</span> tmrScheduler_Tick(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> System.<span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> System.EventArgs) <span class="kwrd">Handles</span> tmrScheduler.Tick
    <span class="kwrd">If</span> DateTime.Now &gt;= My.Settings.Time <span class="kwrd">Then</span>
        <span class="rem">' re-maximize the window</span>
        <span class="kwrd">Me</span>.WindowState = FormWindowState.Maximized

        <span class="rem">' disable me timer</span>
        tmrScheduler.Enabled = <span class="kwrd">False</span>

        <span class="rem">' enable the animation timer</span>
        tmrAnim.Enabled = <span class="kwrd">True</span>
    <span class="kwrd">End</span> <span class="kwrd">If</span>
<span class="kwrd">End</span> <span class="kwrd">Sub</span></pre>
<pre class="csharpcode"><span class="kwrd"></span>
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong>Visual C#</strong> </p>
<pre class="csharpcode"><span class="rem">// called once per minute to check whether it's time to run the show</span>
<span class="kwrd">private</span> <span class="kwrd">void</span> tmrScheduler_Tick(<span class="kwrd">object</span> sender, EventArgs e)
{
    <span class="rem">// if the current time is greater than the time set by the user</span>
    <span class="kwrd">if</span>(DateTime.Now &gt;= Properties.Settings.Default.Time)
    {
        <span class="rem">// re-maximize the window</span>
        <span class="kwrd">this</span>.WindowState = FormWindowState.Maximized;

        <span class="rem">// disable this timer</span>
        tmrScheduler.Enabled = <span class="kwrd">false</span>;

        <span class="rem">// enable the animation timer</span>
        tmrAnim.Enabled = <span class="kwrd">true</span>;
    }
}
</pre>
<style type="text/css">
<!--
.csharpcode
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{margin:0em;
	width:100%;
	background-color:#f4f4f4}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<h3><b>Deployment</b> </h3>
<p>As mentioned earlier, one of the main goals of this project was to have an extremely easily deployable application. In order to achieve this, all code was kept inside the framework with no dependencies on things like Managed DirectX. Additionally, all resources
 used by the application (images and sounds) were setup as embedded resources so they do not need to be deployed separately.
</p>
<p>When you are ready to scare your friend, simply copy the Halloween.exe file to his or her PC. )You may want to enlist someone as the “lookout” so you don't get caught while doing so!) Create a shortcut to it in the Startup program group, or set it up to
 run via the registry using the following key for the logged in user: </p>
<ul>
<li>HKCU\Software\Microsoft\Windows\CurrentVersion\Run</li></ul>
<p>Simply create a new string key with any Name, and a Data value of the path to the executable.
</p>
<p>Next, start the application once on their PC to setup the date and time for the show to begin. Once that is done, the application will remain running in the background. If the PC is restarted, and the application is setup to run at startup as described above,
 it will start silently and remain running, waiting for the date and time specified.
</p>
<h3><b>Summary</b> </h3>
<p>And there we have it. A very simple application requiring very little code that will elicit quite a reaction from your victim. The code can be very easily modified to include different images, a different sound effect, or even different animation effects.
 There is plenty of time between now and April Fool's Day to modify the project for even more fun.
</p>
<h3><b>Thanks</b> </h3>
<p>A special thanks to <a href="http://www.joeybphotography.com/" target="_blank">
Joey Buczek</a> for drawing up the blood drop animation, <a href="http://www.markzaugg.com/" target="_blank">
Mark Zaugg</a>&nbsp;for testing on a few machines outside my house, and Michelle Leavitt for making my writing a bit more palatable for the masses.</p>
<h3>Bio</h3>
<p>Though Brian is a recognized .NET expert with over 6 years experience developing .NET solutions, and over 9 years of professional experience architecting and developing solutions using Microsoft technologies and platforms, he has been &quot;coding for fun&quot; for
 as long as he can remember.&nbsp; Outside the world of .NET and&nbsp;business applications, Brian enjoys developing&nbsp;both hardware and software projects in the areas of gaming, robotics, and&nbsp;whatever else strikes his fancy for the next ten minutes.&nbsp;He rarely passes up
 an opportunity to dive into a C/C&#43;&#43;&nbsp;or assembly language project.&nbsp; You can reach Brian via his blog at
<a href="http://www.brianpeek.com/" target="_blank">http://www.brianpeek.com/</a>.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:d725cf69cbcf4a1aa08c9e7600dc1cd8">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Scary-Halloween-Application</comments>
      <itunes:summary>
 





Build an application that will drip animated blood down your victim&#39;s computer screen for a scary Halloween treat!



Brian Peek
ASPSOFT, Inc.

Difficulty: Easy
Time Required: 
Less than 1 hour
Cost: Free
Software: Visual Basic or Visual C# Express Editions
Hardware: None
Download: Download

&amp;nbsp;
Introduction





If you&#39;re anything like me, and I hope for your friends&#39; and family&#39;s sake you&#39;re not, you believe that annoying others is amazingly entertaining. If that&#39;s the case, then this article is for you.
 
We are going to build an application that you will copy to a friend&#39;s PC that will, at a specified date and time, cause the computer to appear to start dripping blood down the screen and, after a few seconds, switch to a full-screen image of something terrifying
 while playing a screaming sound effect. This should sufficiently scare your victim for Halloween (hear the
built-in scary sound).
 

 
The Form 
We will be creating a full-screen, always-on-top, transparent form that will overlay the entire screen. This will be our display surface for the dripping blood.
 
The form can be created as described by modifying the following properties:  
BackColor – Fuchsia  
FormBorderStyle – None  
DoubleBuffered – True  
Text - &amp;lt;empty string&amp;gt;  
WindowState – Maximized  
ShowInTaskbar – False  
TransparencyKey – Fuchsia  
TopMost - True  
This will create our full-screen, transparent form with no visible name, no icon in the task bar, no border that will remain on top of all other windows. With this in place, we can draw whatever we want to on to the form and it will be displayed over whatever
 happens to be on the screen. A nice bonus to this is that even though the form is maximized, because it is transparent, mouse and keyboard events will pass through to the visible active forms below. The user&#39;s PC should act as though nothing is happening!
 
The Blood

I created a class named BloodDrop to represent the on-screen blood droplets flowing down the screen</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Scary-Halloween-Application</link>
      <pubDate>Tue, 31 Oct 2006 03:06:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Scary-Halloween-Application</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/905508_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/905508_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Brian Peek</dc:creator>
      <itunes:author>Brian Peek</itunes:author>
      <slash:comments>7</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Scary-Halloween-Application/RSS</wfw:commentRss>
      <category>Halloween</category>
      <category>events</category>
    </item>
  <item>
      <title>Motion-Detecting, Blood Squirting Halloween Skull</title>
      <description><![CDATA[<span id="c4fmetadata">
<table cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td width="50"><img height="50" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/article_thumb.jpg" width="50"></td>
<td><span class="entry_description">Create a scary surprise for your Halloween trick-or-treaters! With some off-the-shelf components and a bit of code, you can have some fun with your visitors...</span></td>
</tr>
<tr>
<td colspan="2">
<div class="entry_author">&nbsp;</div>
<div class="entry_author">Brian Peek</div>
<div class="entry_company"><a href="http://www.aspsoft.com/">ASPSOFT, Inc.</a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Intermediate</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">$100-$200</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.microsoft.com/express/" target="_blank">Visual C# Express</a>,
<a href="http://www.phidgets.com/modules.php?op=modload&amp;name=Downloads&amp;file=index&amp;req=viewdownload&amp;cid=3" target="_blank">
Phidgets SDK</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"><a href="http://www.airlink101.com/products/aic250w.html">AirLink101 AIC -250W wireless IP camera</a>,
<a href="http://www.phidgetsusa.com/cat/viewproduct.asp?category=1000&amp;subcategory=1100&amp;SKU=1014">
Phidgets 0/0/4 Interface Kit</a>, Westinghouse 3-Outlet Heavy Duty Remote, Beckett M60AUL Small Fountain Pump, rubber tubing, plastic skull, solder and soldering iron, external speakers</span></div>
<div class="entry_details"><b>Download: </b><a href="http://channel9.msdn.com/ShowPost.aspx?PostID=251371">Download</a>
</div>
<div class="entry_details">&nbsp;</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>I wanted to build a small device that would terrify small children as they approached my door for Halloween. I suppose this makes me a bad person, but it's still a lot of fun.
</p>
<p>The concept here is pretty simple. We will be using motion detection from a web cam or network-enabled/IP camera to trigger a small fountain pump fitted into a bucket of water to spray anyone that approaches your front door. And, to make it a bit more creepy,
 we will fit the spray mechanism into a plastic skull. </p>
<p><b>WARNING: The pump being used will be connected to an A/C wall socket. While the pump is certainly designed to be used with water, please be aware of the fact that you will have water and electricity in close proximity to each other.</b>
</p>
<h3><b>What You Will Need</b> </h3>
<ul>
<li>A web or network-enabled camera.&nbsp; I am using the <a href="http://www.airlink101.com/products/aic250w.html">
AirLink101 AIC-250W wireless IP camera</a>. </li><li>A <a href="http://www.phidgetsusa.com/cat/viewproduct.asp?category=1000&amp;subcategory=1100&amp;SKU=1014">
Phidget Interface Kit</a> 0/0/4 – a USB-controlled board with 4 relays. </li><li>A remote-controlled A/C power outlet. I chose the Westinghouse 3-Outlet Heavy Duty Remote, Item #T28074, normally used for Christmas lights.<br>
<a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/outlet1.jpg"><img height="240" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/outlet.jpg" width="180" border="0"></a>
<br>
</li><li>A fountain water pump. The one I used in this article is the Beckett M60AUL Small Fountain Pump. Almost any fountain pump will work, however be aware of how far the water will need to be pumped and choose a pump to meet your needs.<br>
<a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/pump1.jpg"><img height="240" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/pump.jpg" width="180" border="0"></a>
<a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/pump21.jpg">
<img height="180" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/pump2.jpg" width="240" border="0"></a>
<br>
</li><li>Rubber tubing of the appropriate size to fit the pump, preferably black if you can find it.<br>
<a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/hose1.jpg"><img height="180" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/hose.jpg" width="240" border="0"></a>
<br>
</li><li>A Plastic Skull.<br>
<a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/skull1.jpg"><img height="240" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/skull.jpg" width="180" border="0"></a>
<br>
</li><li>Red food coloring. </li><li>A soldering iron, solder and some spare wire. </li><li>A set of external speakers with an audio extension cable. </li><li>Optional: A strobe light. </li><li>Microsoft Visual C# 2005 Express Edition.</li></ul>
<p><b></b></p>
<h3><b>The Hardware</b> </h3>
<p>Let's start by setting up the hardware. We will be using the remote controlled A/C outlet to toggle power to the pump at will. The remote control for the unit I purchased has a separate on and off switch, so we will wire one relay from the Phidget board
 to the on switch, and one relay to the off switch. </p>
<p>Open the remote control unit. Inside, you should see something similar to the image below:
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/opened_remote1.jpg"><img height="180" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/opened_remote.jpg" width="240" border="0"></a>
</p>
<p>Flip the unit over to access the side with the button contacts. My unit had two metal spring-type contacts taped to the board. Once removed, I was able to access the contacts directly. You should see contact pads similar to the following:
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/contacts1.jpg"><img height="180" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/contacts.jpg" width="240" border="0"></a>
</p>
<p>The pads each contain a common ground contact and an active contact. When the two are bridged, which happens when the button is pressed, the circuit closes and the remote sends the appropriate signal to the receiving unit. We will replicate the button action
 by tying a relay to each pad so that when the relay closes at our command, the circuit will close, sending the signal to the outlet unit.
</p>
<p>Cut 4 equal lengths of wire and strip a bit of insulation off of each end. Carefully solder one end of each wire to each contact pad on the remote control as shown:
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/soldered1.jpg"><img height="240" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/soldered.jpg" width="180" border="0"></a>&nbsp;
</p>
<p>Additionally, use some electrical tape or rubber bands to affix the battery in place on the remote, if required.
</p>
<p>Next, put the opposite end of each wire into the appropriate screw terminal on the Phidget relay board. You will notice on the Phidget board that there are 3 terminals per relay, labeled NO, XC, and NC, where “X” is a number from 0 to 3. These stand for
 “Normally Open”, “Relay X Common”, and “Normally Closed”. Since we want each circuit to be normally open, we will put one wire of each button to the NO terminal, and one to the XC terminal of each relay. For the on button, insert one wire into the NO terminal
 of relay 0, and one wire into the 0C screw terminal. Do the same with the wires from the off button, but wire them into relay 1. You should wind up with something looking like the picture below:
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/connected1.jpg"><img height="180" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/connected.jpg" width="240" border="0"></a>&nbsp;
</p>
<p>With this in place, we now have a computer-controlled remote control for the outlet. When the fountain pump (or anything else) is plugged into the outlet, it will toggle on and off as we open and close each relay.
</p>
<p>Next, we will modify our plastic skull. If you have access to a real skull, feel free to use that instead. I decided to puncture a small hole in the bottom and drill a hole in the nose of the skull. I then fed the tubing through the nose hole and out of
 the bottom of the skull. You may also wish to run the tubing out of the eyes by either splitting the tubing near the eyes, or using two separate pumps plugged into the remote outlet.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/skull_bottom1.jpg"><img height="180" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/skull_bottom.jpg" width="240" border="0"></a>
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/inserting_hose1.jpg"><img height="240" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/inserting_hose.jpg" width="180" border="0"></a>
</p>
<p>Cut holes in the appropriate areas and push the rubber tubing through, leaving just a tiny bit hanging out of the exit hole.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/nose_hose1.jpg"><img height="240" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/nose_hose.jpg" width="180" border="0"></a>
</p>
<p>Leave a generous amount of tubing coming out of the bottom of the skull. You will cut this later to the desired length once the prop is setup outside. When the gadget is later setup outside, you will fill a bucket with warm (or COLD!) water and add some
 food coloring, and the fountain pump. The pump I used submerges entirely in water, but yours may use an intake tube instead. Then, plug the pump into the remote controlled outlet, and plug the outlet into a standard A/C wall socket.
</p>
<p>When the on signal is sent to the remote controlled outlet, the pump will turn on, and water will squirt from the rubber hose inside the skull!
</p>
<p>Our skull is set to spray water out of its nose. Let's set all of this aside for now and move onto the software side of things.
</p>
<h3><b>The Camera</b> </h3>
<p>For motion detection, I chose to use the AIC-250W wireless IP camera. This allows me to freely mount the camera wherever I wish and not worry about cords. Of course, it will require that you have a wireless access point somewhere nearby to connect the camera
 and the laptop together. You also could use an ad-hoc network with the camera, but I have not tested this. With the software we will be using, you also should be able to use a standard USB web camera. Regardless of the method chosen, please configure the camera
 appropriately so that the video output can be seen. In the case of the AIC-250W, it is as simple as running the included utility and setting it up to use your wireless network.
</p>
<h3><b>The Software</b> </h3>
<p>We will need several pieces installed before we can begin coding. First, ensure that you have Microsoft Visual C# 2005 Express Edition installed.
</p>
<p>Following <a href="http://msdn.microsoft.com/coding4fun/someassemblyrequired/babies/default.aspx" target="_blank">
Scott Hanselman's lead</a>, I too will be using the excellent <a href="http://www.codeproject.com/cs/media/Motion_Detection.asp" target="_blank">
motion detection project</a> from Andrew Kirillov. </p>
<p>Download the source code for this project, as we will be modifying what is there to meet our requirements.
</p>
<p>You also will need to download and install the latest <a href="http://www.phidget.com/modules.php?op=modload&amp;name=Downloads&amp;file=index&amp;req=viewdownload&amp;cid=3">
Phidget's library</a>. </p>
<p>With those pieces installed and ready, we can begin modifying the software motion detection code.
</p>
<p>I am not going to give you a tutorial of Andrew's source code as that is done at the original site linked above. I suggest reading through that article and exploring the source code a bit to learn what's going on behind the scenes. The code is somewhat complex
 in areas, however the project itself, along with the original article, are a fantastic learning experience.
</p>
<p>Open the <b>motion_src.sln</b> file in Visual C# 2005 Express. When the solution is opened, the IDE will prompt you to upgrade the solution to the latest version. Accept the defaults and make your way through the wizard. When complete, you should see your
 solution with three projects loaded into the IDE. </p>
<p>The first thing we will add to the application is a handler to actually deal with firing the pump when the motion detection alarm is fired, which means we will need to communicate with the PhidgetInterfaceKit. Ensure the Phidget library listed above is installed.
 Then, right-click on the <b>References </b>folder in the <b>motion</b> project and select
<b>Add Reference…</b> . Scroll down and select <b>Phidget21.NET</b> with runtime version
<b>2.0.50727</b>. </p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/phidget1.png"><img height="197" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/phidget.png" width="240" border="0"></a>
</p>
<p>The pump is controlled in a separate thread, so we need to add the <b>System.Threading
</b>library to our code along with the Phidget library. Finally, to play a loud sound through some external speakers, we need to use the
<b>System.Media </b>library. All of this can be done by adding the following <b>using
</b>statements to the top of our <b>MainForm.cs </b>code: </p>
<pre class="csharpcode"><span class="kwrd">using</span> System.Threading;
<span class="kwrd">using</span> Phidgets;
<span class="kwrd">using</span> Phidgets.Events;
<span class="kwrd">using</span> System.Media;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>When motion is detected, we want to call a method that will turn the pump on for a bit and then turn it back off. After the pump has been activated, we also want it to wait for the user to click a button or press a button on the keyboard to setup the “trap”
 again. Otherwise, we run the potential of having the pump fire over and over again while handing out candy or before the “trick-or-treater” leaves. Alternatively, we can have the trap turn off for a specified period of time and then re-enable itself. We will
 discuss both methods. </p>
<p>First, add a <b>bool</b> variable named <b>pumpOn</b> to the <b>MainForm</b> class. This will maintain whether we are inside of our event handler, firing the pump.
</p>
<p></p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">bool</span> pumpOn = <span class="kwrd">false</span>; </pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Next, we need to create an instance of the <b>InterfaceKit</b> object to communicate with the Phidget board. Under the statement added above, add the following:
</p>
<p></p>
<pre class="csharpcode"><span class="kwrd">private</span> InterfaceKit ifKit = <span class="kwrd">new</span> InterfaceKit(); </pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Now that we have created an instance of the <b>InterfaceKit</b> object, we need to open communication with the device. In the
<b>MainForm</b> constructor, after the call to <b>InitializeComponent</b>, add the following line:
</p>
<pre class="csharpcode"><span class="rem">// open the Phidget device</span>
ifKit.open();</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Next, look for a method named <b>camera_Alarm </b>in <b>MainForm.cs</b>. This is the event that is fired when motion is detected on the camera. Modify the
<b>camera_Alarm</b> method to look like the following: </p>
<p>&nbsp;</p>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> camera_Alarm( <span class="kwrd">object</span> sender, System.EventArgs e )
{
    <span class="rem">// save movie for 5 seconds after motion stops</span>   
    intervalsToSave = (<span class="kwrd">int</span>) ( 5 * ( 1000 / timer.Interval ) );

    <span class="kwrd">if</span>(!pumpOn)
    {
        Thread thread = <span class="kwrd">new</span> Thread(<span class="kwrd">new</span> ThreadStart(ActivatePump));
        thread.Start();
    }
}</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>This will, as long as the pump is not activated, spawn a new thread using the <b>
ActivatePump</b> method. Add the following <b>ActivatePump </b>method to the <b>MainForm
</b>class: </p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> ActivatePump()
{
    pumpOn = <span class="kwrd">true</span>;

    <span class="rem">// play the terrifying sound</span>
    SoundPlayer sp = <span class="kwrd">new</span> SoundPlayer(<span class="str">&quot;scream.wav&quot;</span>));
    sp.Play();

    <span class="rem">// press on switch, make sure off switch is not pressed</span>
    ifKit.outputs[0] = <span class="kwrd">true</span>;
    ifKit.outputs[1] = <span class="kwrd">false</span>;

    <span class="rem">// leave the pump on for 2 seconds</span>
    Thread.Sleep(2000);

    <span class="rem">// press off switch, make sure on switch is not pressed</span>
    ifKit.outputs[0] = <span class="kwrd">false</span>;
    ifKit.outputs[1] = <span class="kwrd">true</span>;

    <span class="rem">// hold it for half a second</span>
    Thread.Sleep(500);

    <span class="rem">// ensure no button is pressed</span>
    ifKit.outputs[0] = <span class="kwrd">false</span>;
    ifKit.outputs[1] = <span class="kwrd">false</span>;

    <span class="kwrd">try</span>
    {
        <span class="rem">// kill the current thread</span>
        Thread.CurrentThread.Abort();
    }
    <span class="kwrd">catch</span>
    {
    }
}
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>This method will set our <b>pumpOn</b> variable to true and then create a new <b>
SoundPlayer </b>object, loading the file <b>scream.wav </b>as an embedded resource. The scream.wav file should be from the same directory as the source code. The sound will then be played asynchronously using the
<b>Play</b> method. Note that the scream.wav file located in the project solution is setup to be copied to the output directory on compilation. This can be done by selecting the file in the Solution Explorer and then choosing
<b>Copy always</b> in the <b>Copy to Output Directory</b> option of the <b>Properties</b> window.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/copyoutput1.png"><img height="240" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/copyoutput.png" width="228" border="0"></a>
</p>
<p>Next, we set the relays. Relay 0 (which is the On button if you wired as suggested above) is turned on while relay 1 (the Off button) is turned off. This is held for 2 seconds to allow the water to squirt out by putting the thread to sleep. Then, the relays
 are switched. The Off button is pressed (relay 1) and the On button is opened (relay 0). This is held for half a second, and then both relays are returned to their open positions. When this completes, we terminate our current thread so the process can begin
 again. Note that we wrap the call to <b>Abort</b> in an exception handler. When a thread is aborted, an exception is generated by the CLR. In this case we don't care about the exception, so it is caught and thrown away.
</p>
<p>At this point, you have two ways to handle resetting the software. One option is to add an additional
<b>Thread.Sleep</b> call to the method above, wait for several minutes, and reset
<b>pumpOn</b> to false:&nbsp;&nbsp;</p>
<pre class="csharpcode">...</pre>
<pre class="csharpcode">ifKit.outputs[1] = <span class="kwrd">false</span>;

<span class="rem">// wait two minutes</span>
Thread.Sleep(120000);

pumpOn = <span class="kwrd">false</span>;

<span class="kwrd">try</span>
... </pre>
<p>The other option is to add a button to the <b>MainForm</b> and set the <b>pumpOn</b> member variable to false when clicked. This will allow you to manually reset the effect after the candy has been handed out and the door is closed.
</p>
<p>To do this, simply drag a button over to the <b>MainForm</b>, double-click it, and add the following to the generated
<b>Click</b> event handler: </p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> btnReset_Click(<span class="kwrd">object</span> sender, EventArgs e)
{
    pumpOn = <span class="kwrd">false</span>;
}
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<h3><b>Running the Application</b> </h3>
<p>Press F5 to compile and run the application. When running, click on the <b>File</b> menu and choose the appropriate option to open the camera type you have. For the AIC-250W, we will be using the MJPEG URL option. You can connect to this camera with the
 following URL: </p>
<p>http://&lt;camera's IP address&gt;/mjpeg.cgi </p>
<p>If everything has gone to plan, you should see the output from the camera show up in the center of the window.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/app1.png"><img height="226" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/905480/app.png" width="240" border="0"></a>
</p>
<p>The red lines around objects in the scene denote changes sensed by the software.
</p>
<h3><b>Final Tweaks</b> </h3>
<p>For my environment, I noticed that the motion detection alarm was a bit too sensitive. If you find the same, there is a simple modification you can make to decrease the sensitivity.
</p>
<p>The level at which the alarm is set is determined by a private member variable inside the
<b>Camera </b>class. If we expose that variable through a public property, we can then set that property when our application starts. By testing various values of this property, you should find one that is suitable for your area.
</p>
<p>Open the <b>Camera.cs</b> file and add the following property to the code: </p>
<pre class="csharpcode"><span class="rem">// AlarmLevel property</span>
<span class="kwrd">public</span> <span class="kwrd">double</span> AlarmLevel
{
    get { <span class="kwrd">return</span> alarmLevel; }
    set { alarmLevel = <span class="kwrd">value</span>; }
}
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Next, move back to the <b>MainForm.cs</b> file. Look for a method named <b>OpenVideoSource</b>. This method is where the
<b>Camera</b> object is created. Right below the call to the <b>Camera</b> object's constructor, add the following line, substituting a value that works for you:
</p>
<pre class="csharpcode"><span class="rem">// create camera</span>
Camera camera = <span class="kwrd">new</span> Camera( source, detector );

<span class="rem">// ADD: level at which alarm is fired</span>
camera.AlarmLevel = 0.010;
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>For some additional fun, note that the <b>Motion</b> menu of the application contains an option to record video when motion is detected. With this checked, the application will write an AVI file out to its running directory when the alarm is fired…that is,
 when the scream is played and the blood is squired on your unsuspecting visitor!
</p>
<h3><b>Putting It All Together</b> </h3>
<p>The final setup is quite simple. </p>
<ol>
<li>Fill up a bucket of water and add the red food coloring. </li><li>Submerge the pump (or the intake hose) into the water. </li><li>Hide the bucket behind a covered stand or inside a box. </li><li>Place the skull on top of the stand or box with the tubing running down into the pump's output.
</li><li>Plug the pump into the remote controlled A/C power outlet. </li><li>For some extra fun, plug a strobe light into the remote controlled outlet as well!
</li><li>Plug that outlet into your outdoor power outlet, or run a cord to an outlet inside your home.
</li><li>Configure and install the camera in an inconspicuous location near the skull and plug it into an outlet that isn't the remote-controlled outlet. Make sure the camera is mounted sturdily so the camera doesn't move and interfere with the motion detection.
</li><li>Hide some external PC speakers near the skull and run the audio cable inside your home to your PC or laptop. (Make sure to turn up the volume!)
</li><li>Back inside, plug the Phidget board (with the remote control connected to it ) into a USB port on your PC.
</li><li>If you are using a wired camera of some sort, plug that in as well. </li><li>Run the application and wait for someone to approach the door!</li></ol>
<p>When the software senses motion on the camera, the sound will play through the speakers and the relays will fire, turning on the outlet, which will fire the water pump. The “blood” will spray out of the skull and terrify the person outside that you've either
 a) just watched on the output screen, or b) recorded to an AVI file for later embarrassment. When you are ready to engage the gadget again, just click the “Reset” button and wait for the next visitor.
</p>
<h3><b>Conclusion</b> </h3>
<p>That's all there is to it! With a bit of soldering and some off-the-shelf components, you can create a scary, fun, and wet surprise for your trick-or-treaters!
</p>
<h3></h3>
<h3>Bio</h3>
<p>Though Brian is a recognized .NET expert with over 6 years experience developing .NET solutions, and over 9 years of professional experience architecting and developing solutions using Microsoft technologies and platforms, he has been &quot;coding for fun&quot; for
 as long as he can remember.&nbsp; Outside the world of .NET and&nbsp;business applications, Brian enjoys developing&nbsp;both hardware and software projects in the areas of gaming, robotics, and&nbsp;whatever else strikes his fancy for the next ten minutes.&nbsp;He rarely passes up
 an opportunity to dive into a C/C&#43;&#43;&nbsp;or assembly language project.&nbsp; You can reach Brian via his blog at
<a href="http://www.brianpeek.com/" target="_blank">http://www.brianpeek.com/</a>.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/halloween/RSS&WT.dl=0&WT.entryid=Entry:RSSView:690f82a116cf4130be349e7600dc2cb3">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Motion-Detecting-Blood-Squirting-Halloween-Skull</comments>
      <itunes:summary>




Create a scary surprise for your Halloween trick-or-treaters! With some off-the-shelf components and a bit of code, you can have some fun with your visitors...



&amp;nbsp;
Brian Peek
ASPSOFT, Inc.

Difficulty: Intermediate
Time Required: 
1-3 hours
Cost: $100-$200
Software: Visual C# Express,

Phidgets SDK
Hardware: AirLink101 AIC -250W wireless IP camera,

Phidgets 0/0/4 Interface Kit, Westinghouse 3-Outlet Heavy Duty Remote, Beckett M60AUL Small Fountain Pump, rubber tubing, plastic skull, solder and soldering iron, external speakers
Download: Download

&amp;nbsp;





I wanted to build a small device that would terrify small children as they approached my door for Halloween. I suppose this makes me a bad person, but it&#39;s still a lot of fun.
 
The concept here is pretty simple. We will be using motion detection from a web cam or network-enabled/IP camera to trigger a small fountain pump fitted into a bucket of water to spray anyone that approaches your front door. And, to make it a bit more creepy,
 we will fit the spray mechanism into a plastic skull.  
WARNING: The pump being used will be connected to an A/C wall socket. While the pump is certainly designed to be used with water, please be aware of the fact that you will have water and electricity in close proximity to each other.
 
What You Will Need 

A web or network-enabled camera.&amp;nbsp; I am using the 
AirLink101 AIC-250W wireless IP camera. A 
Phidget Interface Kit 0/0/4 – a USB-controlled board with 4 relays. A remote-controlled A/C power outlet. I chose the Westinghouse 3-Outlet Heavy Duty Remote, Item #T28074, normally used for Christmas lights.


A fountain water pump. The one I used in this article is the Beckett M60AUL Small Fountain Pump. Almost any fountain pump will work, however be aware of how far the water will need to be pumped and choose a pump to meet your needs.




Rubber tubing of the appropriate size to fit the pump, preferably black if you can find it.


A Plastic Skull.


Red food color</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Motion-Detecting-Blood-Squirting-Halloween-Skull</link>
      <pubDate>Tue, 31 Oct 2006 02:43:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Motion-Detecting-Blood-Squirting-Halloween-Skull</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/905480_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/905480_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Brian Peek</dc:creator>
      <itunes:author>Brian Peek</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Motion-Detecting-Blood-Squirting-Halloween-Skull/RSS</wfw:commentRss>
      <category>Halloween</category>
      <category>events</category>
    </item>    
</channel>
</rss>