<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Coding4Fun</title><subtitle type="html">&lt;div id="menuContainer"&gt;&lt;/div&gt;</subtitle><id>http://blogs.msdn.com/coding4fun/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/coding4fun/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-10-31T18:37:42Z</updated><entry><title>IronRuby sketch up</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/12/16/9937778.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/12/16/9937778.aspx</id><published>2009-12-16T18:20:18Z</published><updated>2009-12-16T18:20:18Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blog.jimmy.schementi.com/2009/12/ironruby-rubyconf-2009-part-35.html"&gt;Jimmy Schementi posted about his talk at RubyConf 2009&lt;/a&gt; and talked about embedding IronRuby in another program.&amp;#160; His goals were:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;2D rendering surface with simple primitive shapes &lt;/li&gt;    &lt;li&gt;Simple animation support – callbacks for each frame and each object on the canvas &lt;/li&gt;    &lt;li&gt;User-loadable “macros” for drawing and animating&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;His outcome looks amazing!&amp;#160; It is worth noting Jimmy is using Visual Studio 2010 beta 2 for the demo here.&amp;#160; His blog states he hasn’t tried it in Visual Studio 2008.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:7be7f167-1ea1-4505-9525-9cfe595696eb" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;object width="400" height="280"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=8185302&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=8185302&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="280"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9937778" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="IronRuby" scheme="http://blogs.msdn.com/coding4fun/archive/tags/IronRuby/default.aspx" /></entry><entry><title>use Less to reduce CSS clutter!</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/12/11/9932669.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/12/11/9932669.aspx</id><published>2009-12-11T18:16:00Z</published><updated>2009-12-11T18:16:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx" mce_href="http://haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx"&gt;Reading a post by Phil Haack&lt;/a&gt;, I learned about a neat technology called LESS that helps reduce the amount of CSS and duplicated code you have to create.&amp;#160; It was &lt;a href="http://lesscss.org/" mce_href="http://lesscss.org/"&gt;originally a Ruby Gem&lt;/a&gt; but now has a .Net port called .Less which can be found at &lt;a href="http://www.dotlesscss.com/" mce_href="http://www.dotlesscss.com"&gt;www.dotlesscss.com&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;It lets you do some amazing things like global changes and even operations!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Variable:&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;@brand_color: #4D926F;
 
#header {
  color: @brand_color;
}
 
h2 {
  color: @brand_color;
}&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Operation:&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;@the-border: 1px;
@base-color: #111;
 
#header {
  color: @base-color * 3;
  border-left: @the-border;
  border-right: @the-border * 2;
}
 
#footer { 
  color: (@base-color + #111) * 1.5; 
}&lt;/pre&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9932669" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="web" scheme="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx" /><category term="CSS" scheme="http://blogs.msdn.com/coding4fun/archive/tags/CSS/default.aspx" /><category term="ASP.Net" scheme="http://blogs.msdn.com/coding4fun/archive/tags/ASP.Net/default.aspx" /></entry><entry><title>Build your own Windows 7 Sensors!</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/12/10/9934884.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/12/10/9934884.aspx</id><published>2009-12-10T13:00:00Z</published><updated>2009-12-10T13:00:00Z</updated><content type="html">&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/BuildyourownWindows7Sensors_A690/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/BuildyourownWindows7Sensors_A690/image_2.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: 0px; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: 0px" title=image border=0 alt=image align=right src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/BuildyourownWindows7Sensors_A690/image_thumb.png" width=240 height=220 mce_src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/BuildyourownWindows7Sensors_A690/image_thumb.png"&gt;&lt;/A&gt; Tired of having a computer with no sensors?&amp;nbsp; We’ve created a &lt;A href="http://code.msdn.microsoft.com/motionsensor" mce_href="http://code.msdn.microsoft.com/motionsensor"&gt;parallax windows 7 sensor driver with source code&lt;/A&gt; so you can create your own!&lt;/P&gt;
&lt;P&gt;The sensor device we made here is a Passive-Infrared Sensor.&amp;nbsp; So basically it is a motion sensor.&amp;nbsp; The board used in the white paper is the Parallax “BASIC Stamp HomeWork Board”.&amp;nbsp; Sadly these only come in a 10-pack so the fallback would be the &lt;A href="http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/CategoryID/11/List/0/SortField/0/Level/a/ProductID/1/Default.aspx" mce_href="http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/CategoryID/11/List/0/SortField/0/Level/a/ProductID/1/Default.aspx"&gt;BASIC Stamp 2 Module ($49.00)&lt;/A&gt; and getting either the &lt;A href="http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/SortField/0/Level/a/ProductID/121/Default.aspx" mce_href="http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/SortField/0/Level/a/ProductID/121/Default.aspx"&gt;BASIC Stamp 2 Carrier Board” ($15.99)&lt;/A&gt; or &lt;A href="http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/Level/a/ProductID/126/Default.aspx?SortField=ProductName%2cProductName" mce_href="http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/Level/a/ProductID/126/Default.aspx?SortField=ProductName%2cProductName"&gt;the Board of Education Dev Board (USB) ($41.99)&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The code example also has a .Net application that interprets the data from the sensor.&lt;/P&gt;
&lt;P&gt;More of an Arduino fan?&amp;nbsp; Coding4Fun is working with Brian Jepson (&lt;A href="http://twitter.com/bjepson" mce_href="http://twitter.com/bjepson"&gt;@bjepson&lt;/A&gt;) of &lt;A href="http://www.makezine.com/" mce_href="http://www.makezine.com/"&gt;MAKE&lt;/A&gt; and O'Reilly to create a driver that works with Arduino!&amp;nbsp; I’ll post more when it gets finished.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9934884" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="hardware" scheme="http://blogs.msdn.com/coding4fun/archive/tags/hardware/default.aspx" /><category term="Windows 7" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Windows+7/default.aspx" /></entry><entry><title>Windows 7: Jump Lists</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/12/09/9933039.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/12/09/9933039.aspx</id><published>2009-12-10T00:59:00Z</published><updated>2009-12-10T00:59:00Z</updated><content type="html">&lt;p&gt;In this article, learn how to provide quick access to links and actions in your Windows 7 application by creating a Jump List.&lt;/p&gt; &lt;table border="0" cellspacing="0" cellpadding="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" width="282"&gt; &lt;p&gt;Arian T. Kulp &lt;br&gt;&lt;a title="http://www.ariankulp.com" href="http://www.ariankulp.com/"&gt;http://www.ariankulp.com&lt;/a&gt;&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="356"&gt; &lt;p&gt;&lt;b&gt;Code It:&lt;/b&gt; &lt;a href="http://c4fjumplist.codeplex.com"&gt;Download&lt;/a&gt;&lt;strong&gt; &lt;br&gt;&lt;/strong&gt;&lt;b&gt;Difficulty:&lt;/b&gt; Intermediate &lt;br&gt;&lt;b&gt;Time Required:&lt;/b&gt; 3 hours &lt;br&gt;&lt;b&gt;Cost:&lt;/b&gt; Free! &lt;br&gt;&lt;b&gt;Software Needed:&lt;/b&gt; &lt;a href="http://www.microsoft.com/express/download/"&gt;Visual Basic or Visual C# Express (or higher&lt;/a&gt;, &lt;a href="http://code.msdn.microsoft.com/WindowsAPICodePack" target="_blank"&gt;Windows API Code Pack&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;h3&gt;Introduction&lt;/h3&gt; &lt;p&gt;Windows 7 includes a wealth of new features for developers to take advantage of.&amp;nbsp; This includes better rendering subsystems, new sensor and location API's, file libraries, federated search, and of course, the improved taskbar.&amp;nbsp; My last article discussed the taskbar's ability to show custom previews and toolbar icons.&amp;nbsp; This article focuses on Jump Lists - the replacement for notification area context menus.&lt;/p&gt; &lt;p&gt;To get started, download &lt;a href="http://www.microsoft.com/exPress/" target="_blank"&gt;Visual Studio 2008 Express Edition&lt;/a&gt; or higher (C# or VB).&amp;nbsp; Or, just go for &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank"&gt;Visual Studio 2010 Beta 2&lt;/a&gt; - it's available now and well worth the download.&amp;nbsp; All Express editions are free, and either 2008 or 2010 versions will work fine with this article's accompanying code.&lt;/p&gt; &lt;h3&gt;What's a Jump List?&lt;/h3&gt; &lt;p&gt;Jump Lists are a new concept in Windows 7 that allow developers to provide shortcuts for users right from their icon's context menu in the taskbar or Start menu.&amp;nbsp; The shortcuts could be simple links to the documents folder or a library for a given application, or links back to the same application with a parameter passed to cause something to happen.&lt;/p&gt; &lt;p&gt;You can use this method in Live Messenger to change online status, display the new message window, or open web pages relating to the application.&amp;nbsp; In the end, all of these are shortcuts.&amp;nbsp; Shortcuts to URL's, or shortcuts back to the executable with an argument that causes some change to occur.&lt;/p&gt; &lt;h3&gt;Windows API Code Pack&lt;/h3&gt; &lt;p&gt;The Windows API Code Pack lets you take advantage of specific features of Windows Vista and Windows 7 that aren't available across the general framework, as well as native features that don't make sense in the common CLR used across all the supported configurations. Much of it consists of interop wrappers.  &lt;p&gt;With the Code Pack, you get access to the new taskbar, Direct2D, DirectWrite, shell properties, Jump Lists, and more. The download also includes numerous sample code projects to get you started, so there's no excuse for avoiding new features!  &lt;h3&gt;Adding a Jump List&lt;/h3&gt; &lt;p&gt;Adding a Jump List is easy.&amp;nbsp; After you create the list itself, add items (shortcuts to files or folders, and tasks) to it.&amp;nbsp; Then, you can choose how a user's recent or frequently used documents show up.&amp;nbsp; Windows manages the user documents list, which relieves you of some work.  &lt;p&gt;It's important to note that in order to make a change to the list, you have to recreate the entire thing.&amp;nbsp; In other words, you'll replace the old list with a new one, rather than updating it.  &lt;p&gt;Here's how the process works:  &lt;p&gt;First, add the two required references from the Windows API Code Pack.&amp;nbsp; You can either build a project and reference the DLL's, or directly add projects to your solution:  &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Windows API Code Pack references" border="0" alt="Windows API Code Pack references" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_thumb_1.png" width="244" height="84"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;For convenience, you can add the namespaces to your &lt;em&gt;using &lt;/em&gt;block to shorten typing later: &lt;/p&gt; &lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; Microsoft.WindowsAPICodePack.Taskbar
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; Microsoft.WindowsAPICodePack.Shell&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.WindowsAPICodePack.Taskbar;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.WindowsAPICodePack.Shell;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;Microsoft.WindowsAPICodePack.Taskbar.JumpList &lt;/em&gt;class is where most of the action is.&amp;nbsp; There's a static factory method, &lt;em&gt;CreateJumpList&lt;/em&gt;, to create the list.&amp;nbsp; Always start by calling this method, even if the application has created a Jump List in the past.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; CreateJumpList()
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; jl &lt;span class="kwrd"&gt;As&lt;/span&gt; JumpList = JumpList.CreateJumpList()&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateJumpList()
{
    JumpList jl = JumpList.CreateJumpList();&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Next, you have several options, depending on what you need in the list.&amp;nbsp; The most basic group is the list of files.&amp;nbsp; You can choose to show Recent files, Frequent files, or neither-but you can't have both.&amp;nbsp; If you don't make a choice here, you'll get Recent files automatically, as long as you have a registered file type. 
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;' Show user files: Recent, Frequent, or None&lt;/span&gt;
jl.KnownCategoryToDisplay = JumpListKnownCategoryType.Recent&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="rem"&gt;// Show user files: Recent, Frequent, or None&lt;/span&gt; &lt;br&gt;jl.KnownCategoryToDisplay = JumpListKnownCategoryType.Recent; &lt;br&gt;&lt;/p&gt;
&lt;p&gt;Now you can add one or more custom categories of items.&amp;nbsp; These are either folders or files.&amp;nbsp; There are two very important rules:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The files/folders must exist!&amp;nbsp; If necessary, check the path before adding the &lt;em&gt;JumpListItem &lt;/em&gt;or you'll have a crash.&amp;nbsp; &lt;li&gt;The files you add have to be of a type registered for your application, or you'll crash. Even worse: the exception won't occur on the line where you add it, but rather when you're done setting it up and try to refresh the list. &lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;I've commented out the last item here, but you would use a &lt;em&gt;JumpListItem &lt;/em&gt;for actual file system files, and &lt;em&gt;JumpListLink &lt;/em&gt;objects for non-filesystem references.&amp;nbsp; Again, don't add a JumpListItem unless you know that it exists and that you're registered to handle it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;' Add my own links (nouns)&lt;/span&gt;
&lt;span class="kwrd"&gt;Dim&lt;/span&gt; catActions &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; JumpListCustomCategory(&lt;span class="str"&gt;"Destinations"&lt;/span&gt;)

catActions.AddJumpListItems(
    &lt;span class="kwrd"&gt;New&lt;/span&gt; JumpListLink(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), &lt;span class="str"&gt;"My Pictures"&lt;/span&gt;), _
    &lt;span class="kwrd"&gt;New&lt;/span&gt; JumpListLink(&lt;span class="str"&gt;"http://blogs.msdn.com/coding4fun"&lt;/span&gt;, &lt;span class="str"&gt;"Visit Coding4Fun"&lt;/span&gt;), _
    &lt;span class="kwrd"&gt;New&lt;/span&gt; JumpListLink(&lt;span class="str"&gt;"http://code.msdn.microsoft.com/WindowsAPICodePack"&lt;/span&gt;, &lt;span class="str"&gt;"Windows API Code Pack"&lt;/span&gt;))
    &lt;span class="rem"&gt;'new JumpListItem(@"c:\Test1.c4f")&lt;/span&gt;

jl.AddCustomCategories(catActions)&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Add my own links (nouns)&lt;/span&gt;
JumpListCustomCategory catActions = &lt;span class="kwrd"&gt;new&lt;/span&gt; JumpListCustomCategory(&lt;span class="str"&gt;"Destinations"&lt;/span&gt;);
catActions.AddJumpListItems(
    &lt;span class="kwrd"&gt;new&lt;/span&gt; JumpListLink(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), &lt;span class="str"&gt;"My Pictures"&lt;/span&gt;),
    &lt;span class="kwrd"&gt;new&lt;/span&gt; JumpListLink(&lt;span class="str"&gt;"http://blogs.msdn.com/coding4fun"&lt;/span&gt;, &lt;span class="str"&gt;"Visit Coding4Fun"&lt;/span&gt;),
    &lt;span class="kwrd"&gt;new&lt;/span&gt; JumpListLink(&lt;span class="str"&gt;"http://code.msdn.microsoft.com/WindowsAPICodePack"&lt;/span&gt;, &lt;span class="str"&gt;"Windows API Code Pack"&lt;/span&gt;)
    &lt;span class="rem"&gt;//new JumpListItem(@"c:\Test1.c4f")&lt;/span&gt;
    );

jl.AddCustomCategories( catActions);&lt;/pre&gt;
&lt;p&gt;You can add one or more tasks as&amp;nbsp; links to system executables by using the &lt;em&gt;AddUserTasks &lt;/em&gt;method of the JumpList object.&amp;nbsp; Either create multiple objects and add them as a variable argument list, or add them one at a time, as I have here.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;' Add our user tasks (verbs)&lt;/span&gt;
jl.AddUserTasks(&lt;span class="kwrd"&gt;New&lt;/span&gt; JumpListLink(Path.Combine(systemFolder, &lt;span class="str"&gt;"notepad.exe"&lt;/span&gt;), &lt;span class="str"&gt;"Open Notepad"&lt;/span&gt;) _
    &lt;span class="kwrd"&gt;With&lt;/span&gt; {.IconReference = &lt;span class="kwrd"&gt;New&lt;/span&gt; IconReference(Path.Combine(systemFolder, &lt;span class="str"&gt;"notepad.exe"&lt;/span&gt;), 0)})&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;jl.AddUserTasks(&lt;span class="kwrd"&gt;new&lt;/span&gt; JumpListLink(Path.Combine(systemFolder, &lt;span class="str"&gt;"notepad.exe"&lt;/span&gt;), &lt;span class="str"&gt;"Open Notepad"&lt;/span&gt;)
{
    IconReference = &lt;span class="kwrd"&gt;new&lt;/span&gt; IconReference(Path.Combine(systemFolder, &lt;span class="str"&gt;"notepad.exe"&lt;/span&gt;), 0)
});&lt;/pre&gt;
&lt;p&gt;The &lt;em&gt;IconReference&lt;/em&gt; property sets a pointer to the icon by referencing a DLL or EXE and then an index.&amp;nbsp; Specifying an EXE with "0" is a good way to get the default icon for an executable that you are linking to.&lt;/p&gt;
&lt;p&gt;You can add a separator to the list whenever you need to.&amp;nbsp; The &lt;i&gt;JumpListSeparator &lt;/i&gt;class represents a separator and can be added using the &lt;i&gt;AddUserTasks &lt;/i&gt;call. 
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;jl.AddUserTasks(&lt;span class="kwrd"&gt;New&lt;/span&gt; JumpListSeparator())&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;jl.AddUserTasks(&lt;span class="kwrd"&gt;new&lt;/span&gt; JumpListSeparator());&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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; }&lt;/style&gt;

&lt;p&gt;The final links in our Jump List link back to our own executable. This is the most common use of Jump Lists.&amp;nbsp; Just having a Recent/Frequent list is nice, but being able to trigger actions on the program itself-even when it's not started-is really handy.&amp;nbsp; It's almost like a menu of command line options! 
&lt;p&gt;Commands in the list that invoke actions on the application itself involve calling the same application with different arguments.&amp;nbsp; Remember that this isn't a true menu; you won't receive a &lt;em&gt;Click&lt;/em&gt; event.&amp;nbsp; Instead, you need to deal with an argument that's passed to you, even if you're already running. 
&lt;p&gt;Remember that the first argument on the command line is always the fully-qualified location to the running executable.&amp;nbsp; The &lt;i&gt;Arguments &lt;/i&gt;property lets you specify command line arguments that users don't directly see.&amp;nbsp; For this sample application, I've defined three dummy arguments.&amp;nbsp; If one of these is passed in, the application changes the background color of a label and indicates which argument it was. 
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;jl.AddUserTasks(&lt;span class="kwrd"&gt;New&lt;/span&gt; JumpListLink(&lt;span class="kwrd"&gt;Assembly&lt;/span&gt;.GetEntryAssembly().Location, &lt;span class="str"&gt;"Action 1 (Green)"&lt;/span&gt;) _
    &lt;span class="kwrd"&gt;With&lt;/span&gt; {.Arguments = &lt;span class="str"&gt;"-1"&lt;/span&gt;, .IconReference = &lt;span class="kwrd"&gt;New&lt;/span&gt; IconReference(&lt;span class="kwrd"&gt;Assembly&lt;/span&gt;.GetEntryAssembly().Location, 0)})&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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; }
&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;Visual C#&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;jl.AddUserTasks(&lt;span class="kwrd"&gt;new&lt;/span&gt; JumpListLink(Assembly.GetEntryAssembly().Location, &lt;span class="str"&gt;"Action 1 (Green)"&lt;/span&gt;)
{
    IconReference = &lt;span class="kwrd"&gt;new&lt;/span&gt; IconReference(Assembly.GetEntryAssembly().Location, 0),
    Arguments = &lt;span class="str"&gt;"-1"&lt;/span&gt;
});&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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; }&lt;/style&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Sample JumpList" border="0" alt="Sample JumpList" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_thumb_2.png" width="267" height="367"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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; }&lt;/style&gt;

&lt;h3&gt;Invoking Self Actions&lt;/h3&gt;
&lt;p&gt;Windows Live Messenger uses Jump List actions for setting its own available status, and Windows Media Player has Jump List actions for skipping tracks or stopping.&amp;nbsp; Likewise, you can add tasks that invoke actions on the same executable.&amp;nbsp; If the application isn't running (remember that the Jump List is still available), this will cause it to be launched with the right argument.&amp;nbsp; That's no problem.&amp;nbsp; What if it's already running though?&lt;/p&gt;
&lt;p&gt;The key is to find a way to pass messages between running instances.&amp;nbsp; When the application starts up, check to see if another instance is running by using a &lt;em&gt;Mutex &lt;/em&gt;(see &lt;em&gt;Program.cs&lt;/em&gt;).&amp;nbsp; If not, just use the arguments directly.&amp;nbsp; If it is running, send the information about the parameter to the other instance and then quit.&amp;nbsp; You could use temporary files, shared registry keys, or memory-mapped files.&amp;nbsp; I find it easiest to use window messages.&lt;/p&gt;
&lt;p&gt;You can find the code to create custom message ID's, to find the right window, and to send the message in my &lt;em&gt;WindowsMessageHelper &lt;/em&gt;class.&lt;/p&gt;
&lt;p&gt;From the main window code, override the &lt;em&gt;WndProc &lt;/em&gt;method.&amp;nbsp; This is the message loop for everything: mouse events, key events, window closing, and much more.&amp;nbsp; Ensure that the message is something you need; otherwise pass it on to the underlying handler.&lt;/p&gt;
&lt;p&gt;If the application is already running, post a message.&amp;nbsp; If not, start as usual and watch your message queue.&amp;nbsp; If you see a message of interest, take some action (in this case, just showing a message and changing a color).&amp;nbsp; &lt;/p&gt;
&lt;p&gt;The only other tricky thing to remember, is that you might startup as the only instance, and &lt;em&gt;also &lt;/em&gt;have a parameter.&amp;nbsp; For example, if the user clicked a task on the Jump List but the application isn't running.&amp;nbsp; I take the easy way out and check for parameters after fully starting up and then post to my own queue if needed!&amp;nbsp; That simplifies some of the logic anyway.&lt;/p&gt;
&lt;p&gt;If you don't mind using the &lt;strong&gt;Microsoft.VisualBasic.ApplicationServices&lt;/strong&gt; namespace from C#, then you can take advantage of the VB SingleInstance application mode.&amp;nbsp; This removes the need for any explicit mutex, interop, or message passing.&amp;nbsp; You can find some great information about this on Jocelyn Villaraza's excellent &lt;a href="http://aimeegurl.com/2009/11/13/making-your-win7-jumplists-trigger-on-the-same-application-instance/" target="_blank"&gt;blog post&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Registering a File Type&lt;/h3&gt;
&lt;p&gt;Remember: unless you're registered as a file handler for the type, you can't show recent or frequent files or point to individual files.&amp;nbsp; Register to be a file handler by creating a registry write operation to a key under HKEY_CLASSES.&amp;nbsp; &lt;p&gt;The problem is, you can't write to the HKEY_CLASSES branch of the registry without proper permissions.&amp;nbsp; By default, permission is only granted to the Administrators group.&amp;nbsp; You really don't want to require that your application run under administrative privileges-that would be &lt;i&gt;so &lt;/i&gt;Windows XP! 
&lt;p&gt;There are two alternatives: you could create a second application that can run elevated in order to perform the registration.&amp;nbsp; This is how the samples do it with the Windows API Code Pack. A better method is to create a custom installer for the project and perform the association there.&amp;nbsp; Installers always require administrative rights, and they only need to run once. 
&lt;p&gt;&lt;/p&gt;
&lt;h3&gt;Creating the Installer&lt;/h3&gt;
&lt;p&gt;To create the installer, first add a setup project to your solution, following the usual steps. Then, from the &lt;b&gt;Project types &lt;/b&gt;list, click &lt;b&gt;Other Project Types | Setup and Deployment&lt;/b&gt;.&amp;nbsp; In the &lt;b&gt;Templates &lt;/b&gt;list, click &lt;b&gt;Setup Project&lt;/b&gt;. Give it a name, then add it.&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="New project types" border="0" alt="New project types" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_thumb_4.png" width="640" height="463"&gt;&lt;/a&gt; &lt;/h3&gt;
&lt;p&gt;From &lt;strong&gt;Solution Explorer&lt;/strong&gt;, right-click the setup project, then click the &lt;strong&gt;View | File Types &lt;/strong&gt;menu command.&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="View File Types" border="0" alt="View File Types" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_thumb_3.png" width="418" height="264"&gt;&lt;/a&gt; &lt;/h3&gt;
&lt;p&gt;From the File Types list, right-click &lt;strong&gt;File Types on Target Machine&lt;/strong&gt;, and then click &lt;strong&gt;Add File Type&lt;/strong&gt;.&amp;nbsp; Fill out the properties to name the file type and provide the extension.&amp;nbsp; For &lt;strong&gt;Command&lt;/strong&gt;, be sure to set it to the Primary output of the main project.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="File type properties" border="0" alt="File type properties" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_thumb_6.png" width="342" height="194"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The file type should appear like the following in the &lt;strong&gt;File Types &lt;/strong&gt;tab:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="File Types list" border="0" alt="File Types list" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Windows7Jumplists_12963/image_thumb_5.png" width="196" height="87"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Now you have a registered file type.&amp;nbsp; You still need to modify your setup project to copy the primary output (the EXE) to Program Files and customize any other properties in the setup project, but these are the special steps for file types.&amp;nbsp; If in doubt, take a look at sample code to see how the Setup project is configured.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Working with the Windows API Code Pack makes it much easier to customize the taskbar and add Jump Lists, and gives you a great experience that really integrates well with the system.&amp;nbsp; Download Visual Studio Express, grab the Windows API Code Pack, and start digging in.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The new features won't work on machines prior to Windows 7, so be sure to check that they're supported.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9933039" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="windows miscellaneous" scheme="http://blogs.msdn.com/coding4fun/archive/tags/windows+miscellaneous/default.aspx" /><category term="Windows 7" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Windows+7/default.aspx" /></entry><entry><title>bugs on your screen?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/12/07/9932678.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/12/07/9932678.aspx</id><published>2009-12-07T18:13:00Z</published><updated>2009-12-07T18:13:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://adamkinney.wordpress.com/2009/12/03/bugcamsmash-motion-detection-with-silverlight-4-beta/"&gt;Adam Kinney created a fun example squishing bugs to show off Silverlight 4.0’s webcam support&lt;/a&gt;.&amp;#160; He created simple motion detection using a diff calculation on multiple threads to figure out where his finger was to smooth the bugs!&amp;#160; Here is a video showing off the project.&lt;/p&gt;  &lt;p&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="512" height="384"&gt; &lt;param name="source" value="http://channel9.msdn.com/App_Themes/default/vp09_11_30.xap" /&gt; &lt;param name="initParams" value="deferredLoad=true,duration=0,m=http://ecn.channel9.msdn.com/o9/ch9/3/1/5/0/1/5/BugCamSmash_ch9.wmv,autostart=false,autohide=true,showembed=true, postid=510513" /&gt; &lt;param name="background" value="#00FFFFFF" /&gt; &lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt; &lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt; &lt;/a&gt; &lt;/object&gt;&lt;/p&gt;  &lt;p&gt;If you want to check out the &lt;a href="http://adamkinney.wordpress.com/2009/12/03/bugcamsmash-motion-detection-with-silverlight-4-beta/"&gt;source code for BugCamSmash&lt;/a&gt;, Adam has that along with a few other helpful hints at his blog post.&lt;/p&gt;  &lt;p&gt;In addition, Adam is posting articles on how he created the application as well.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://adamkinney.wordpress.com/2009/12/04/bugcamsmash-dissected-part-1-smash-a-bug/"&gt;Smash a bug&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://adamkinney.wordpress.com/2009/12/05/bugcamsmash-dissected-part-2-make-the-bugs-crawl/"&gt;Make the bugs crawl&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://adamkinney.wordpress.com/2009/12/07/bugcamsmash-dissected-part-3-give-the-bugs-brains/"&gt;Giving the bugs Brains&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9932678" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="web" scheme="http://blogs.msdn.com/coding4fun/archive/tags/web/default.aspx" /><category term="Silverlight" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx" /><category term="Beta" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Beta/default.aspx" /><category term="Silverlight 4.0" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight+4.0/default.aspx" /></entry><entry><title>Coding4Fun at PDC 2009 – Video Montage</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/12/04/9931631.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/12/04/9931631.aspx</id><published>2009-12-04T18:25:00Z</published><updated>2009-12-04T18:25:00Z</updated><content type="html">&lt;p&gt;We’ll be posting one project each month but here is the Coding4Fun booth at PDC 2009!&amp;#160; You can even view the Iron Bartender challenge at GeekFest as well!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/posts/Clint/Coding4Fun-at-PDC-2009/"&gt;Overall Recap of each project&lt;/a&gt;     &lt;br /&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="512" height="384"&gt; &lt;param name="source" value="http://channel9.msdn.com/App_Themes/default/vp09_11_30.xap" /&gt; &lt;param name="initParams" value="deferredLoad=true,duration=0,m=http://ecn.channel9.msdn.com/o9/ch9/4/4/0/8/0/5/coding4funAtPdc_ch9.wmv,autostart=false,autohide=true,showembed=true, postid=508044, thumbnail=http://ecn.channel9.msdn.com/o9/ch9/4/4/0/8/0/5/coding4funAtPdc_512_ch9.png" /&gt; &lt;param name="background" value="#00FFFFFF" /&gt; &lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt; &lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt; &lt;/a&gt; &lt;/object&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/posts/LauraFoy/Coding4Fun-DrinkTendr/"&gt;Iron Bartender!&lt;/a&gt;     &lt;br /&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="512" height="384"&gt; &lt;param name="source" value="http://channel9.msdn.com/App_Themes/default/vp09_11_30.xap" /&gt; &lt;param name="initParams" value="deferredLoad=true,duration=0,m=http://ecn.channel9.msdn.com/o9/ch9/9/4/1/0/1/5/DrinkTendr_ch9.wmv,autostart=false,autohide=true,showembed=true, postid=510149, thumbnail=http://ecn.channel9.msdn.com/o9/ch9/9/4/1/0/1/5/DrinkTendr_512_ch9.png
" /&gt; &lt;param name="background" value="#00FFFFFF" /&gt; &lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt; &lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt; &lt;/a&gt; &lt;/object&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9931631" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="hardware" scheme="http://blogs.msdn.com/coding4fun/archive/tags/hardware/default.aspx" /><category term="hardwarehacks" scheme="http://blogs.msdn.com/coding4fun/archive/tags/hardwarehacks/default.aspx" /><category term="XNA" scheme="http://blogs.msdn.com/coding4fun/archive/tags/XNA/default.aspx" /><category term="wiimote" scheme="http://blogs.msdn.com/coding4fun/archive/tags/wiimote/default.aspx" /><category term="WPF" scheme="http://blogs.msdn.com/coding4fun/archive/tags/WPF/default.aspx" /></entry><entry><title>Is this frame straight?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/12/02/9931839.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/12/02/9931839.aspx</id><published>2009-12-03T07:27:39Z</published><updated>2009-12-03T07:27:39Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Isthisframestraight_149E9/Preview%5B1%5D_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Preview[1]" border="0" alt="Preview[1]" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Isthisframestraight_149E9/Preview%5B1%5D_thumb.png" width="500" height="265" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Joel Ivory Johnson created a rather functional program for his Zune HD.&amp;#160; &lt;a href="http://www.codeproject.com/KB/game/XNALevel.aspx"&gt;Joel created a bubble level&lt;/a&gt; based on the accelerometer in the Zune HD to get the tilt of the device.&amp;#160; From that data and &lt;a href="http://en.wikipedia.org/wiki/Pythagorean_theorem"&gt;everyone’s favorite theorem&lt;/a&gt;, he created a bubble level!&lt;/p&gt;  &lt;p&gt;Joel also explains the math needed for doing this such as calculating the direction and the magnitude.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;Vector3 accelReading = accelState.Acceleration;

tiltDirection = (&lt;span class="kwrd"&gt;float&lt;/span&gt;)Math.Atan2(accelReading.Y, accelReading.X);
tiltMagnitude = (&lt;span class="kwrd"&gt;float&lt;/span&gt;)Math.Sqrt(accelReading.X * accelReading.X + 
                 accelReading.Y * accelReading.Y );&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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; }&lt;/style&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9931839" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="XNA" scheme="http://blogs.msdn.com/coding4fun/archive/tags/XNA/default.aspx" /><category term="Zune" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Zune/default.aspx" /><category term="ZuneHD" scheme="http://blogs.msdn.com/coding4fun/archive/tags/ZuneHD/default.aspx" /></entry><entry><title>Creating a Pinball Game in Silverlight: Using the Physics Helper Library + Farseer Physics</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/11/30/9896181.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/11/30/9896181.aspx</id><published>2009-11-30T22:20:00Z</published><updated>2009-11-30T22:20:00Z</updated><content type="html">&lt;p&gt;In this tutorial, we'll create a Silverlight pinball game using &lt;u&gt;Behaviors&lt;/u&gt;&lt;b&gt;, &lt;/b&gt;a new addition to Expression Blend 3 &amp;amp; Silverlight that allows you to create interactivity with little or no coding. &lt;/p&gt;  &lt;p&gt;Below you'll find a video and step-by-step walkthrough. &lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="157"&gt;Andy Beaulieu          &lt;br /&gt;&lt;a title="http://www.andybeaulieu.com/" href="http://www.andybeaulieu.com/"&gt;http://www.andybeaulieu.com/&lt;/a&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="481"&gt;&lt;strong&gt;Run It: &lt;/strong&gt;&lt;a href="http://www.andybeaulieu.com/silverlight/3.0/pinballgame/Coding4FunPinball.htm"&gt;View The Demo&lt;/a&gt;           &lt;br /&gt;&lt;strong&gt;Code It: &lt;/strong&gt;&lt;a href="http://physicshelper.codeplex.com/Release/ProjectReleases.aspx"&gt;Download the Source&lt;/a&gt;           &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Difficulty: &lt;/strong&gt;Intermediate           &lt;br /&gt;&lt;b&gt;Time Required:&lt;/b&gt; 4 Hour           &lt;br /&gt;&lt;strong&gt;Cost: &lt;/strong&gt;Free!           &lt;br /&gt;&lt;strong&gt;Software Needed: &lt;/strong&gt;&lt;a href="http://www.microsoft.com/expression/products/Blend_Overview.aspx"&gt;Microsoft Expression Blend 3&lt;/a&gt; (Free Trial), Microsoft Visual Studio 2008 or &lt;a href="http://www.microsoft.com/express/vcsharp/"&gt;Visual C# Express&lt;/a&gt;, &lt;a href="http://www.silverlight.net/GetStarted"&gt;Visual Studio Tools for Silverlight&lt;/a&gt;, &lt;a href="http://physicshelper.codeplex.com"&gt;Physics Helper Library&lt;/a&gt;.&amp;#160; To help get setup quicker, try &lt;a href="http://www.microsoft.com/web"&gt;Web Platform Installer&lt;/a&gt;.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt; &lt;iframe height="500" src="http://www.coding4fun.net/media/slpinball/slpinball.html" frameborder="0" width="100%"&gt;&lt;/iframe&gt;&lt;a href="http://www.andybeaulieu.com/silverlight/3.0/pinballgame/coding4funtutorial.htm#_Toc237838546"&gt;&lt;/a&gt;  &lt;br /&gt;  &lt;h3 align="center"&gt;&lt;a href="http://www.coding4fun.net/media/slpinball/slpinball.html" target="_blank"&gt;Open the video player in a new window/tab&lt;/a&gt;&lt;/h3&gt;  &lt;h3&gt;&amp;#160;&lt;/h3&gt;  &lt;h3&gt;&lt;a name="_Toc237838538"&gt;Setup and Prerequisites&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;First you have to setup Physics Helper controls into Expression Blend. Follow these steps:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Download the Physics Helper ZIP file from &lt;a href="http://physicshelper.codeplex.com/Release/ProjectReleases.aspx"&gt;http://physicshelper.codeplex.com/Release/ProjectReleases.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Extract the ZIP file contents and dump them into a folder. &lt;/li&gt;    &lt;li&gt;Run &lt;b&gt;install.bat&lt;/b&gt;. (Note: this copies a few required assemblies to a folder in Blend 3.&lt;b&gt;)&lt;/b&gt;       &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image001.jpg" /&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;&lt;a name="_Toc237838539"&gt;Getting Started &amp;amp; Making the Ball&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;Next, you create the controller and the pinball. Here's how.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open Expression Blend 3 and create a new “Silverlight 3 Application + Website” named PinballGame.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image002.jpg" width="400" height="324" /&gt; &lt;/li&gt;    &lt;li&gt;Change your default layout container to a Canvas. You can do this in the Objects and Timeline panel by right-clicking LayoutRoot and selecting Change Layout Type/Canvas. Canvas layout containers are better for games because they allow for positioning of elements at absolute (x,y) coordinates.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image003.jpg" width="290" height="266" /&gt; &lt;/li&gt;    &lt;li&gt;Give the application a bigger default size. Select the UserControl element in the Objects and Timeline panel. Then, in the Properties panel, change the Width to 800 and the Height to 600.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image004.png" width="269" height="190" /&gt; &lt;/li&gt;    &lt;li&gt;Add a &lt;b&gt;Physics Controller Behavior&lt;/b&gt; to our main game Canvas. From the Asset Panel, find the PhysicsController Behavior and drag it to the Objects and Timeline Panel. Then, drop it on the LayoutRoot Canvas.       &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image005.jpg" width="233" height="253" /&gt;       &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image006.jpg" width="233" height="122" /&gt; &lt;/li&gt;    &lt;li&gt;Change a few of the PhysicsController's properties, to make it easier to use. In the Objects and Timeline Panel, select the PhysicsControllerBehavior assigned to LayoutRoot. Then, set the highlighted properties as follows in the Properties Window:      &lt;br /&gt;1.)&amp;#160; Decrease the vertical gravity to 250       &lt;br /&gt;2.)&amp;#160; Increase the iterations to 200. This will help with collision detection in a fast-action game.       &lt;br /&gt;3.)&amp;#160; Set MousePickEnabled to true. This will allow us to manipulate objects with the mouse during development and testing.       &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image007.png" width="261" height="218" /&gt; &lt;/li&gt;    &lt;li&gt;Create a &amp;quot;playing field&amp;quot; for the pinball. To do this, draw out a Rectangle onto the artboard, just off the bottom of the user control bounds. Set the properties of the Rectangle as follows:      &lt;br /&gt;      &lt;br /&gt;&lt;b&gt;Name&lt;/b&gt;: rectPlatform       &lt;br /&gt;&lt;b&gt;Fill&lt;/b&gt;: select a color of your choosing (light blue is selected below).       &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image008.jpg" width="364" height="317" /&gt; &lt;/li&gt;    &lt;li&gt;To make “rectPlatform” a physics element, we need to add a PhysicsObjectBehavior to it. Find the PhysicsObjectBehavior in the Assets panel and drag/drop it onto rectPlatform on the Artboard.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image009.png" width="343" height="369" /&gt; &lt;/li&gt;    &lt;li&gt;In the Objects and Timeline Panel, select the PhysicsObjectBehavior belonging to rectPlatform. Then in the Properties Panel, set the IsStatic property to True so that the platform will stay in place.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image010.png" width="264" height="173" /&gt; &lt;/li&gt;    &lt;li&gt;Next we’ll create the ball. Draw out an Ellipse near the very top of the UserControl and set the following properties:      &lt;br /&gt;&lt;b&gt;       &lt;br /&gt;Name: &lt;/b&gt;ellBall&lt;b&gt;        &lt;br /&gt;Height&lt;/b&gt;: 50       &lt;br /&gt;&lt;b&gt;Width&lt;/b&gt;: 50       &lt;br /&gt;&lt;b&gt;Fill&lt;/b&gt;: A color of your choosing.       &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image011.jpg" width="378" height="326" /&gt; &lt;/li&gt;    &lt;li&gt;To make the ball a Physics Object, we need to add a PhysicsObjectBehavior to it. From the Asset Library, drag and drop a PhysicsObjectBehavior onto ellBall. &lt;/li&gt;    &lt;li&gt;Run the project by clicking F5. The ball should fall and hit the platform. Use the mouse to manipulate the ball. &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;&lt;a name="_Toc237838540"&gt;Making the Flippers&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;In a pinball game, the Flippers are controlled by the player and are used to move the ball up the playfield. Standard pinball games have one right and one left flipper, but many games have three or more flippers located in various locations on the playfield. We’ll create two user controls to represent the flippers – a right flipper and a left flipper – that way we can easily add as many flippers as we want to our main playfield.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In the Projects Panel, right-click the PinballGame (Silverlight) project and select Add New Item. Select UserControl and name the control LeftFlipper.xaml.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image012.jpg" width="222" height="241" /&gt; &lt;/li&gt;    &lt;li&gt;In the Objects and Timeline Panel, right-click LayoutRoot and select Change Layout Type/Canvas. This is required for the Physics Helper to work with nested User Controls.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image013.jpg" width="256" height="281" /&gt; &lt;/li&gt;    &lt;li&gt;In the Objects and Timeline Panel, select the UserControl element and set its Width and Height to 200 x 200 pixels in the Properties Panel. &lt;/li&gt;    &lt;li&gt;Draw out a Rectangle that is about 200 x 50 pixels big, centered in the user control. Round the corners of the Rectangle.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image014.png" width="235" height="185" /&gt; &lt;/li&gt;    &lt;li&gt;From the main Blend menu, select Object/Path/Convert to Path. This will create a new Path element from the Rectangle primitive. Then select the Direct Selection tool from the Toolbox, which will allow you to manipulate the individual points on the Path.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image015.png" width="37" height="84" /&gt; &lt;/li&gt;    &lt;li&gt;Select the top, left two points on the Path and move them down so that you end up with a more “flipper like” shape:      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image016.png" width="224" height="171" /&gt; &lt;/li&gt;    &lt;li&gt;In the Toolbox, select the Selection arrow and rotate the flipper 45 degrees so that it looks similar to this (be sure the flipper is still within the bounds of the user control):      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image017.jpg" width="196" height="186" /&gt; &lt;/li&gt;    &lt;li&gt;Right-click the flipper Path and select Group Into/Canvas. Name the Canvas &lt;b&gt;cnvLeftFlipper&lt;/b&gt; and resize it so that it surrounds the entire flipper Path. Note that you could “embellish” the cnvLeftFlipper with additional elements if you wish. &lt;/li&gt;    &lt;li&gt;Next we’ll create a Joint so that the Flipper can rotate on an axis. We’ll need something to anchor the joint to, so first let’s add a small Static object to hold the Joint in place. Draw out a Rectangle at the upper left of the flipper and name the Rectangle &lt;b&gt;rectHolder&lt;/b&gt;.       &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image018.jpg" width="196" height="197" /&gt; &lt;/li&gt;    &lt;li&gt;To add a Joint, we will need a UI element to visually represent where we want the joint created. You can use any element you want for this, but an Ellipse works pretty well. Draw out an Ellipse on top of the rectHolder.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image019.jpg" width="196" height="197" /&gt; &lt;/li&gt;    &lt;li&gt;Now we can add all of the required Physics Behaviors to the User Control.      &lt;ol&gt;       &lt;li&gt;From the Asset Library, drag a PhysicsObjectBehavior to the rectHolder Rectangle. Set its IsStatic property to True. Since we don’t really want to see the rectHolder in our UI, just send it to the back of the elements (Right-click, then select Order/Send to Back). &lt;/li&gt;        &lt;li&gt;Drag a PhysicsObjectBehavior to the cnvLeftFlipper Canvas. Set the RestitutionCoefficent property to “0.1”. (This makes the flipper a bit more “bouncy” on collisions) &lt;/li&gt;        &lt;li&gt;Drag a PhysicsJointBehavior to the Ellipse. Set the Body1 property to “cnvLeftFlipper” and the Body2 property to “rectHolder”. Set the CollisionGroup to “1” and the AngleLimitLower and AngleLimitUpper to 0 and 50 respectively. Also enable the AngleSpring:          &lt;br /&gt;&lt;/li&gt;        &lt;li&gt;Drag a PhysicsApplyTorqueBehavior to cnvLeftFlipper. We want to apply Torque when the user presses the Left arrow key, so we’ll create a Trigger for this. Select the Behavior and in the Properties Panel, click the New Trigger button.          &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image021.png" width="267" height="191" /&gt;&amp;#160; &lt;br /&gt;          &lt;br /&gt;Select the PhysicsKeyTrigger type from the popup.           &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image022.jpg" width="197" height="296" /&gt;           &lt;br /&gt;Set the Key property for the Trigger to “Left” and the TorqueValue to -100000           &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image023.png" width="264" height="187" /&gt; &lt;/li&gt;     &lt;/ol&gt;   &lt;/li&gt;    &lt;li&gt;Build the Project so that the LeftFlipper user control is available. &lt;/li&gt;    &lt;li&gt;Open MainPage.xaml and drag an instance of LeftFlipper from the Asset Library onto the Artboard. Position it near the bottom of the user control and slightly to the Left.      &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image024.jpg" width="373" height="321" /&gt; &lt;/li&gt;    &lt;li&gt;Run the project and try the flipper with the Left arrow key. &lt;/li&gt;    &lt;li&gt;In this step, we’ll create a copy of “LeftFlipper” to make&amp;#160; a “RightFlipper”. In the Projects Panel, right-click LeftFlipper.xaml and select Copy. Then right-click the PinBallGame Project and select Paste.      &lt;br /&gt;You now have a new User Control named “Copy of LeftFlipper.xaml”. Rename this to RightFlipper.xaml. Then in the code-behind file, make sure the Class and Constructor are also renamed to “RightFlipper”.       &lt;br /&gt;Change to XAML view for RightFlipper.xaml and change the x:Class attribute so that it inherits from RightFlipper:&amp;#160; &lt;br /&gt;      &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;       &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #ff0000"&gt;xmlns:x&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #ff0000"&gt;xmlns:d&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/expression/blend/2008&amp;quot;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #ff0000"&gt;xmlns:mc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.openxmlformats.org/markup-compatibility/2006&amp;quot;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #ff0000"&gt;mc:Ignorable&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;d&amp;quot;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #ff0000"&gt;xmlns:i&lt;/span&gt;=&amp;amp;&lt;span style="color: #ff0000"&gt;amp&lt;/span&gt;;&lt;span style="color: #ff0000"&gt;quotclr-namespace:System&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Windows&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Interactivity&lt;/span&gt;;&lt;span style="color: #ff0000"&gt;assembly&lt;/span&gt;=&lt;span style="color: #ff0000"&gt;System&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Windows&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Interactivity&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot; &lt;br /&gt;    xmlns:pb=&amp;quot;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;clr-namespace:Spritehand&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;PhysicsBehaviors&lt;/span&gt;;&lt;span style="color: #ff0000"&gt;assembly&lt;/span&gt;=&lt;span style="color: #ff0000"&gt;Spritehand&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;PhysicsBehaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot; &lt;br /&gt;x:Class=&amp;quot;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;PinballGame&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;RightFlipper&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot; &lt;br /&gt;d:DesignWidth=&amp;quot;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;640&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot; d:DesignHeight=&amp;quot;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;480&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot; Height=&amp;quot;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;200&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot; Width=&amp;quot;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;200&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;
Open RightFlipper.xaml and find the pathLeftFlipper element. Rename this to pathRightFlipper. Then, rename “cnvLeftFlipper” to “cnvRightFlipper”. Rename “rectHolder” to “rectRightHolder” and position the rectHolder and joint ellipse so that they are in the correct location for the flipper: 

    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image026.png" width="163" height="159" /&gt; 

    &lt;br /&gt;Modify the PhysicsJointBehavior for the joint in the Objects and Timeline Panel. Change BodyOne to “cnvRightFlipper”, BodyTwo to “rectRightHolder” and change the Angle limits so they are appropriate for the opposite flipper: 

    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image027.png" width="264" height="219" /&gt; 

    &lt;br /&gt;Select the PhysicsApplyTorqueBehavior for cnvRightFlipper in the Objects and Timeline Panel. Change the Key property for the trigger to “Right” so that it will initiate on the Right Arrow key down. Also change the TorqueValue so that it will apply torque clockwise: 

    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image028.png" width="265" height="190" /&gt; 

    &lt;br /&gt;&lt;/li&gt;

  &lt;li&gt;Add an instance of RightFlipper onto the MainPage.xaml and position it to the right of LeftFlipper. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image029.jpg" width="372" height="325" /&gt; &lt;/li&gt;

  &lt;li&gt;Test the project by clicking F5. You can now click left and right arrows keys to manipulate the paddles. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;&lt;a name="_Toc237838541"&gt;Creating the Playfield + Scrolling&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Now let’s create more of a playfield for our Pinball game and add a Camera control so that the game will scroll and always follow the pinball. Feel free to tweak the design as you wish.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Open MainPage.xaml in Expression Blend and zoom out by using Ctrl plus minus (Ctrl -). &lt;/li&gt;

  &lt;li&gt;Draw out a Path using the Pen tool for the right border. Note that you can extend above the upper bounds of the User Control. Group this into a Canvas named “cnvLeftBorder” (right click the Path and select Group Into/Canvas). &lt;/li&gt;

  &lt;li&gt;Drag a PhysicsObjectBehavior from the Asset Library onto cnvLeftBorder and set the IsStatic property to True. Also set the CollisionGroup property to “1” so that collisions will not occur between the border and the Flippers. &lt;/li&gt;

  &lt;li&gt;Repeat Steps 2 and 3 above for the right border, naming that cnvRightBorder. You should have something similar to the following: 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image030.jpg" width="281" height="267" /&gt; &lt;/li&gt;

  &lt;li&gt;Continue adding border controls and applying physics behaviors until you are happy with your playfield. Make the playfield completely closed in so that the ball cannot escape (except by the bottom trap of course!) &lt;/li&gt;

  &lt;li&gt;You can also add more LeftFlipper and RightFlipper controls so that the player can more easily move the ball up the playfield. Here is one example playfield design: 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image031.jpg" width="238" height="336" /&gt; &lt;/li&gt;

  &lt;li&gt;To enable scrolling, we can add a Camera Controller to the ball, causing the camera to follow the ball around the screen. Drag a PhysicsCameraBehavior from the Asset Library onto the ellBall element. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;&lt;a name="_Toc237838542"&gt;Creating a Kicking Target&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Pinball games have lots of different types of targets – some are simple sensors which give points on contact, others are little toys that gobble up the ball for a few seconds. In this step, we’ll create a Kicking Target, which gives points when hit by the ball but also kicks the ball back in the opposite direction.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Create a new User Control named KickingTarget. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image032.jpg" width="203" height="220" /&gt; &lt;/li&gt;

  &lt;li&gt;Change the LayoutRoot container to a Canvas by right-clicking and selecting Change Layout Type/Canvas. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image033.jpg" width="255" height="234" /&gt; &lt;/li&gt;

  &lt;li&gt;Select the [UserControl] in the Objects and Timeline Panel and set its Width and Height to 100 x 100. &lt;/li&gt;

  &lt;li&gt;Draw out an Ellipse that is 90x90 pixels, and positioned at Left, Top 5,5 (so that it is centered in the control). 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image034.png" width="484" height="141" /&gt; &lt;/li&gt;

  &lt;li&gt;Draw out a second Ellipse that is 70x70 pixels and positioned and Left, Top 15, 15. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image035.png" width="131" height="130" /&gt; &lt;/li&gt;

  &lt;li&gt;Group the two Ellipses into a Canvas by selecting them both in the Objects and Timeline Panel and selecting Group Into/Canvas. Name the Canvas “cnvKicker”. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image036.png" width="281" height="204" /&gt; &lt;/li&gt;

  &lt;li&gt;Drag a PhysicsObjectBehavior from the Asset Library onto cnvKicker. Set the IsStatic and RestitutionCoefficient properties as shown below. Setting the RestitutionCoefficient above a value of 1 will make the object “kick” things back. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image037.png" width="265" height="174" /&gt; &lt;/li&gt;

  &lt;li&gt;Build the project so that the new user control is available. Then open MainPage.xaml and add a few instance of “KickingTarget” to the page. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image038.jpg" width="208" height="296" /&gt; &lt;/li&gt;

  &lt;li&gt;Run the project and try out the Kicking Targets. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;&lt;a name="_Toc237838543"&gt;Optimizing Performance&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Our pinball game is looking up, but the performance could be a lot better. The startup time for the game is taking quite awhile because the Physics Helper Library is determining the outline of all of the shapes. Also, the frame rate is too low.&lt;/p&gt;

&lt;p&gt;By default, Silverlight has a target frame rate of 60 frames per second. This is great for a lot of casual games, but Pinball requires a bit more speed. Additionally, Silverlight 3 introduces GPU Acceleration which can greatly increase the performance of our game by offloading graphics operations to the Video Card.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Open the Default.html page in the website project. This page hosts the Silverlight control and exposes the plugin parameters. Add the following parameters to the plug in to increase the default frame rate and enable GPU Acceleration for our game. 
    &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
      &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;object&lt;/span&gt; &lt;span style="color: #ff0000"&gt;data&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;data:application/x-silverlight,&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;application/x-silverlight-2&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;800&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;height&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;600&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;source&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ClientBin/PinballGame.xap&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;onerror&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;onSilverlightError&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;background&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#010141&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;minRuntimeVersion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;3.0.40624.0&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MaxFrameRate&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;160&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;EnableGPUAcceleration&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;EnableCacheVisualization&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;autoUpgrade&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;a&lt;/span&gt; &lt;span style="color: #ff0000"&gt;href&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://go.microsoft.com/fwlink/?LinkID=149156&amp;amp;ampv=3.0.40624.0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;text-decoration: none;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;img&lt;/span&gt; &lt;span style="color: #ff0000"&gt;src&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://go.microsoft.com/fwlink/?LinkId=108181&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;alt&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Get Microsoft Silverlight&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;border-style: none&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;a&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;object&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;Apply the CacheMode attribute to &lt;b&gt;&lt;i&gt;all elements&lt;/i&gt;&lt;/b&gt; in the game that are static. Since our pinball game’s elements are not animated, we can apply the CacheMode to each of them. (If the objects contained animations within them, then the Cache would be invalidated during animation). 

    &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
      &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Rectangle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;rectPlatform&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CacheMode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;BitmapCache&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Fill&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#FF8AD0C9&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Height&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;70&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;800&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Canvas&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Left&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;-14&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Canvas&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Top&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;2172&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Opacity&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;i:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;pb:PhysicsObjectBehavior&lt;/span&gt; &lt;span style="color: #ff0000"&gt;IsStatic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;i:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Rectangle&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;Now we’ll speed up the startup time by adding in a pre-calculated Point Cache. The Physics Helper Library echoes out the calculated points at runtime. Open the project in Visual Studio, and run with debugging on. In the Output Window, Find the ReadBoundaryCache method that was echoed out and Copy the entire method. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image041.jpg" width="523" height="218" /&gt; &lt;/li&gt;

  &lt;li&gt;Note that the copied code can contain multiple rows of the same points. You can trim out any rows that are duplicated, for example cnvRightFlipper_1 is a copy of cnvRightFlipper, so you can remove that from the list of points. &lt;/li&gt;

  &lt;li&gt;In order to load the list of boundary outlines into the Physics Controller, we need to get a reference to the controller through code. Open up MainPage.xaml.cs and add the highlighted code: 
    &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
      &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MainPage : UserControl &lt;br /&gt;{ &lt;br /&gt;    PhysicsControllerMain _physicsController; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MainPage() &lt;br /&gt;    { &lt;br /&gt;        &lt;span style="color: #008000"&gt;// Required to initialize variables &lt;/span&gt;&lt;br /&gt;        InitializeComponent(); &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Loaded += &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RoutedEventHandler(MainPage_Loaded); &lt;br /&gt;    } &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; MainPage_Loaded(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e) &lt;br /&gt;    { &lt;br /&gt;        _physicsController = LayoutRoot.GetValue( PhysicsControllerMain.PhysicsControllerProperty) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PhysicsControllerMain; &lt;br /&gt;        BoundaryCache.ReadBoundaryCache(_physicsController); &lt;br /&gt;    } &lt;br /&gt;}&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;Run the project and test the performance. Note that items that have a tint applied to them (Red, Blue, etc.) are NOT being cached and GPU accelerated. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;&lt;a name="_Toc237838544"&gt;Scoring&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;In this section, we’ll embellish our game with a Score.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;We’ll create a Canvas that overlays our main Canvas to contain a High Score TextBlock. This is so that the Score TextBlock will not scroll with the rest of the Playfield. Open MainPage.xaml and the select LayoutRoot in the Objects and Timeline Panel. Right-click LayoutRoot and select Group Into/Canvas. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image043.jpg" width="227" height="200" /&gt; &lt;/li&gt;

  &lt;li&gt;Add a new StackPanel into this outside Canvas that contains two TextBlock aligned Horizontally. The first TextBlock should contain the Text “Score:” and the second TextBlock should contain the Text “0”. Set the Font Size to a larger value, around 12 pt. Position the TextBlock at the Top, Left portion of the Canvas. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image044.jpg" width="367" height="273" /&gt; &lt;/li&gt;

  &lt;li&gt;Next we’ll handle the Collision event for the Physics Controller so we can add to the score. Open MainPage.xaml.cs and add in a Property wrapper for the current&amp;#160; score: 
    &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
      &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Score &lt;br /&gt;{ &lt;br /&gt;    get &lt;br /&gt;    { &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Convert.ToInt32(txtScore.Text); &lt;br /&gt;    } &lt;br /&gt;    set &lt;br /&gt;    { &lt;br /&gt;        txtScore.Text = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;.ToString(); &lt;br /&gt;    } &lt;br /&gt;}&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;Handle the Collision event for the Physics Controller and increment the Score. 
    &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
      &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; MainPage_Loaded(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e) &lt;br /&gt;{ &lt;br /&gt;    _physicsController = LayoutRoot.GetValue(PhysicsControllerMain.PhysicsControllerProperty) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PhysicsControllerMain; &lt;br /&gt;    BoundaryCache.ReadBoundaryCache(_physicsController); &lt;br /&gt;        _physicsController.Collision += &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PhysicsControllerMain.CollisionHandler(_physicsController_Collision); &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; _physicsController_Collision(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; sprite1, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; sprite2) &lt;br /&gt;{ &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (sprite1 == &amp;quot;ellBall&lt;span style="color: #006080"&gt;&amp;quot; &amp;amp;&amp;amp; sprite2.StartsWith(&amp;quot;ellKicker&amp;quot;&lt;/span&gt;)) &lt;br /&gt;        Score += 10; &lt;br /&gt;}&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;&lt;a name="_Toc237838545"&gt;Tracking Lives&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;When the ball collides with the “rectPlatform” obstacle at the bottom, the ball has been lost and we should launch a new ball. &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Add a new ChildWindow to the project named “LostTheBall.xaml”. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image047.jpg" width="269" height="292" /&gt; &lt;/li&gt;

  &lt;li&gt;Set the “Cancel” button’s Visibility to Collapsed. &lt;/li&gt;

  &lt;li&gt;Add a TextBlock and set its Text to a message for the user stating the ball was lost. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image048.jpg" width="320" height="239" /&gt; &lt;/li&gt;

  &lt;li&gt;Add code in MainPage.xaml.cs to display the dialog and reset the ball. 
    &lt;br /&gt;LostTheBall _lostTheBall; 

    &lt;div style="border-bottom: silver 1px solid; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
      &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; _physicsController_Collision(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; sprite1, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; sprite2) &lt;br /&gt;{ &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (sprite1 == &lt;span style="color: #006080"&gt;&amp;quot;ellBall&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; sprite2.StartsWith(&lt;span style="color: #006080"&gt;&amp;quot;cnvKicker&amp;quot;&lt;/span&gt;)) &lt;br /&gt;    { &lt;br /&gt;        Score += 10; &lt;br /&gt;    } &lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_lostTheBall == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;ampsprite1 == &lt;span style="color: #006080"&gt;&amp;quot;ellBall&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; sprite2 == &lt;span style="color: #006080"&gt;&amp;quot;rectPlatform&amp;quot;&lt;/span&gt;) &lt;br /&gt;    { &lt;br /&gt;        _lostTheBall = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LostTheBall(); &lt;br /&gt;        _lostTheBall.Closed += &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; EventHandler(dialog_Closed); &lt;br /&gt;        _lostTheBall.Show(); &lt;br /&gt;    } &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; dialog_Closed(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e) &lt;br /&gt;{ &lt;br /&gt;    _lostTheBall = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;; &lt;br /&gt;    PhysicsSprite ball = _physicsController.PhysicsObjects[&lt;span style="color: #006080"&gt;&amp;quot;ellBall&amp;quot;&lt;/span&gt;]; &lt;br /&gt;    ball.BodyObject.Position = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Vector2(460, 430); &lt;br /&gt;    }&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;&lt;a name="_Toc237838546"&gt;Adding Sound Effects&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;We can easily add buffered sound effects using the PhysicsSoundBehavior.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;In Visual Studio, Import two sound files into the project, score.wma and click.wma. Set their Build Action to Content. 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image050.jpg" width="220" height="315" /&gt; &lt;/li&gt;

  &lt;li&gt;Open MainPage.xaml in Expression Blend. Drag a PhysicsSoundBehavior to the LayoutRoot Canvas. Set the TriggerType to PhysicsCollisionTrigger and set the following properties: 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image051.png" width="268" height="288" /&gt; &lt;/li&gt;

  &lt;li&gt;Drag another PhysicsSoundBehavior to the LayoutRoot Canvas. Set the TriggerType to PhysicsCollisionTrigger and set the following properties: 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image052.png" width="265" height="263" /&gt; &lt;/li&gt;

  &lt;li&gt;Drag another PhysicsSoundBehavior to the LayoutRoot Canvas. Set the TriggerType to PhysicsCollisionTrigger and set the following properties: 
    &lt;br /&gt;&lt;img border="0" src="http://www.coding4fun.net/media/slpinball/images/image053.png" width="267" height="263" /&gt; &lt;/li&gt;

  &lt;li&gt;Run the project. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;About the Author&lt;/h3&gt;

&lt;p&gt;Andy Beaulieu is a software developer and trainer who is well versed in many Microsoft technologies including Silverlight, ASP.NET, ADO.NET and WindowsForms. &lt;a href="http://www.andybeaulieu.com"&gt;Visit Andy's Blog&lt;/a&gt; for more fun and games with Silverlight.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9896181" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="gaming" scheme="http://blogs.msdn.com/coding4fun/archive/tags/gaming/default.aspx" /><category term="Silverlight" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx" /></entry><entry><title>INotify on new changes</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/11/29/9930051.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/11/29/9930051.aspx</id><published>2009-11-30T06:57:14Z</published><updated>2009-11-30T06:57:14Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/jaimer/archive/2009/09/22/wpf-discussion-090922.aspx"&gt;Jaime Rodriguez has a great post on some of the interesting things we at Microsoft have on one of our internal discussions, namely the WPF one.&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;The big one I noticed was that my favorite was smack at the top.&amp;#160; INotifyCollection is now going to be part of system.dll so you can make your now see if stuff gets modified!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;b&gt;Subject:&lt;/b&gt; Any chance of INotifyCollectionChanged moving to the core .NET libraries? &lt;/p&gt;    &lt;p&gt;The&amp;#160; System.Collections.Specialized.INotifyCollectionChanged interface is defined in WindowsBase.dll (primarily a WPF assembly) but my customer believes it should be pushed down into the core BCL so that other project types can benefit from it without requiring a reference to WPF/WindowsBase.&lt;/p&gt;    &lt;p&gt;Is this planned for 4.0 or later?&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Answer:        &lt;br /&gt;&lt;/strong&gt;INotifyCollectionChanged, ObservableCollection&amp;lt;T&amp;gt;, and ReadOnlyObservableCollection&amp;lt;T&amp;gt; have been type forwarded into System.dll for .NET 4.&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9930051" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="WPF" scheme="http://blogs.msdn.com/coding4fun/archive/tags/WPF/default.aspx" /></entry><entry><title>Silverlight Development</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/11/18/9922257.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/11/18/9922257.aspx</id><published>2009-11-18T23:00:00Z</published><updated>2009-11-18T23:00:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/SilverlightDevelopment_9377/sliverPlusLight_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="sliverPlusLight" border="0" alt="sliverPlusLight" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/SilverlightDevelopment_9377/sliverPlusLight_thumb.jpg" width="483" height="164" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With Silverlight 4.0 just announced, here are some great posts / helpful tips on getting started with Silverlight in general.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://r.ch9.ms/sl4cl"&gt;Channel9 has a training course&lt;/a&gt;.&lt;/li&gt;    &lt;li&gt;Tim Heuer has a 7-part series “&lt;a href="http://timheuer.com/blog/articles/getting-started-with-silverlight-development.aspx"&gt;Getting Started with Silverlight&lt;/a&gt;”.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.shinedraw.com/"&gt;Shine Draw is an awesome “Flash vs Silverlight” repository&lt;/a&gt; that can show you how to do an event in either technology.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://silverlight.net/"&gt;Silverlight.net&lt;/a&gt; has an abundance of information.&amp;#160; They also have &lt;a href="http://silverlight.net/community/samples/silverlight-samples"&gt;Community Samples&lt;/a&gt; as well.&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9922257" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="Silverlight" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx" /><category term="Getting Started" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Getting+Started/default.aspx" /></entry><entry><title>Coding4Fun at PDC!</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/11/17/9923716.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/11/17/9923716.aspx</id><published>2009-11-17T18:09:56Z</published><updated>2009-11-17T18:09:56Z</updated><content type="html">&lt;p&gt;Coding4Fun is in attendance at the Microsoft Professional Developer Conference!&amp;#160; We are demoing 5 projects that will have full how-to’s and will be open-sourced as well.&amp;#160; Drinktendr, Mind Blaster, Laser Graffiti, Augmented Reality, and Wi-Fi Warthogs are powered by .Net, XNA, WPF, Ling2Sql, WiiMote, MSMQ, Power Wheels, a Mind Set and a giant freaking laser!&lt;/p&gt;  &lt;h3&gt;Drinktendr&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4372.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IMG_4372" border="0" alt="IMG_4372" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4372_thumb.jpg" width="240" height="160" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Ever get tired of pouring your own drink?&amp;#160; Have someone get upset at you since it was too strong or too weak?&amp;#160; Well, why not have a machine pour you the perfect beverage every time!&amp;#160; Drinktendr uses Linq2Sql and SQL Server to know what drinks it can make with what is on hand.&amp;#160; Combine this with WPF; the end user is given a top end experience.&lt;/p&gt;  &lt;h3&gt;Mind Blaster&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4328.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IMG_4328" border="0" alt="IMG_4328" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4328_thumb.jpg" width="240" height="160" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With aliens threatening to invade Earth, it’s your job to travel into outer space and destroy the alien threat…with your mind!&amp;#160; Wearing a brainwave detecting headset, coupled with head tracking hardware using a wiimote, use only your brain to destroy alien ships before they destroy you and the rest of humanity.&lt;/p&gt;  &lt;h3&gt;Laser Graffiti&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4323.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IMG_4323" border="0" alt="IMG_4323" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4323_thumb.jpg" width="240" height="160" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Putting graffiti on something is not a very nice thing to do but what if with a flick of a switch, it was gone.&amp;#160; With a projector, an off the shelf webcam and a laser pointer, you can do just that.&amp;#160; Aim the laser at the building and start drawing.&amp;#160; Turn off the laser and it all goes away!&amp;#160; Using WPF and XNA, we can apply a variety of effects including fire, paint, and various particles.&amp;#160; This project was influenced by the Graffiti Research Lab.&lt;/p&gt;  &lt;h3&gt;Augmented Reality&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4340.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IMG_4340" border="0" alt="IMG_4340" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4340_thumb.jpg" width="240" height="160" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We’ll be showing off two AR games.&amp;#160; ARroller and AR Domino Knockdown. ARroller is a single-player “marble game” experienced through a 3DOF-tracked video–see-through head-worn display. The player holds a tracked board on which a virtual marble must be manipulated through a maze of obstacles by tilting and moving the board. AR Domino Knockdown is a two-player first-person-shooter. Players hold 6DOF-tracked UMPCs through which they fire virtual balls at a configuration of virtual dominos on a shared table.&lt;/p&gt;  &lt;h3&gt;Wi-Fi Warthogs&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4311.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IMG_4311" border="0" alt="IMG_4311" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/Coding4FunatPDC_8947/IMG_4311_thumb.jpg" width="240" height="160" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Go big or go home.&amp;#160; After seeing Halo, we decided we had to make some remote control wart hogs to play laser tag with.&amp;#160; Using Xbox controllers, a wireless network, and Power Wheel cars, we’ve made a game of laser tag like no other.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9923716" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="hardware" scheme="http://blogs.msdn.com/coding4fun/archive/tags/hardware/default.aspx" /><category term="XNA" scheme="http://blogs.msdn.com/coding4fun/archive/tags/XNA/default.aspx" /><category term="wiimote" scheme="http://blogs.msdn.com/coding4fun/archive/tags/wiimote/default.aspx" /><category term="WPF" scheme="http://blogs.msdn.com/coding4fun/archive/tags/WPF/default.aspx" /><category term="PDC" scheme="http://blogs.msdn.com/coding4fun/archive/tags/PDC/default.aspx" /></entry><entry><title>XNA Role Playing Game (RPG) Starter Kit</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/11/16/9922196.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/11/16/9922196.aspx</id><published>2009-11-16T20:31:00Z</published><updated>2009-11-16T20:31:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/charlie/archive/2009/09/27/xna-role-playing-game.aspx"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="Figure04-WorldMap_2[1]" border="0" alt="Figure04-WorldMap_2[1]" align="right" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/XNARolePlayingGameRPGStarterKit_B013/Figure04-WorldMap_2%5B1%5D_39a576b6-43dd-4aa2-aa5b-1f0fe4674485.png" width="240" height="140" /&gt; Charlie Calvert has created great post&lt;/a&gt; covering the &lt;a href="http://creators.xna.com/en-US/starterkit/roleplayinggame"&gt;XNA Role Playing Game Starter Kit from the XNA team&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Charlie talks about the tile engine and the quest engine.&amp;#160; The tile engine supports several layers to create a complex final level.&amp;#160; The first layer allows you to define a basic landscape or the interior of a building. A second layer allows you to decorate it with trees, chairs, or other objects. A third layer contains your sprites, and a fourth layer defines the boundaries inside which the sprites can move.&lt;/p&gt;  &lt;p&gt;The downloads for the &lt;a href="http://creators.xna.com/en-US/starterkit/roleplayinggame"&gt;RGP Starter Kit&lt;/a&gt; are broken out into versions for XNA Game Studio 2.0 and 3.0. There is also a distinction between code that targets Windows and code for the XBox:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://creators.xna.com/downloads/?id=220"&gt;For XNA Game Studio 3.0 Windows&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://creators.xna.com/downloads/?id=221"&gt;For XNA Game Studio 3.0 XBox 360&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://creators.xna.com/downloads/?id=83"&gt;For XNA Game Studio 2.0 Windows&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://creators.xna.com/downloads/?id=84"&gt;For XNA Game Studio 2.0 XBox 360&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here are some additional links&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://creators.xna.com/en-US/starterkit/roleplayinggame"&gt;Home page and some documentation&lt;/a&gt; for the starter kit. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://forums.xna.com/forums/t/11880.aspx"&gt;Forum thread for discussing the kit&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;Information on the &lt;a href="http://creators.xna.com/en-US/tutorial/roleplayinggametutorial1"&gt;quest engine&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;Information the the &lt;a href="http://creators.xna.com/en-US/tutorial/roleplayinggametutorial2"&gt;tile engine&lt;/a&gt;. &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9922196" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="XNA" scheme="http://blogs.msdn.com/coding4fun/archive/tags/XNA/default.aspx" /><category term="Getting Started" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Getting+Started/default.aspx" /></entry><entry><title>Facebook SDK</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/11/11/9920962.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/11/11/9920962.aspx</id><published>2009-11-11T18:26:14Z</published><updated>2009-11-11T18:26:14Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/FacebookSDK_92C5/facebook_logo%5B1%5D_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="facebook_logo[1]" border="0" alt="facebook_logo[1]" align="right" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/FacebookSDK_92C5/facebook_logo%5B1%5D_thumb.png" width="240" height="240" /&gt;&lt;/a&gt;Microsoft just released a Facebo ok client library to help make it easier for everyone to create some interesting applications.&amp;#160; The SDK is broken into a few core DLLs, each serving a core purpose.&amp;#160; You can download the SDK from &lt;a title="Download the SDK" href="http://facebooktoolkit.codeplex.com/"&gt;Download the SDK&lt;/a&gt;.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Facebook.dll&lt;/strong&gt;: This is the main assembly that will be used by all applications. This has all the logic to handle communication with the Facebook application. This assembly also has specific support of XAML applications (Silverlight and WPF) to enhance the Facebook platform to make databinding and data caching easier. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Facebook.Silverlight.dll&lt;/strong&gt;: This is the Silverlight version of the main assembly that will be used by all Silverlight applications. This has all the logic to handle communication with the Facebook application. This assembly also has specific support of XAML applications to enhance the Facebook platform to make databinding and data caching easier. The REST API in this assembly is Asynchronous only. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Facebook.Web.dll&lt;/strong&gt;: This assembly should be used by Canvas applications. The main functionality supported in this assembly is to encapsulate the handshake between the Facebook application and a canvas application (both FBML and IFrame) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Facebook.Web.Mvc.dll&lt;/strong&gt;: Provide a support building canvas applications using ASP.NET MVC. Separated from Facebook.Web.dll to avoid all developers from needing to install the MVC bits. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Facebook.Winforms.dll&lt;/strong&gt;: This assembly provides support for writing Facebook applications using Winform technology. This provides a Component that wraps the API to make it easier to use from Winforms. This also contains some user controls to help display Facebook data easily.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;If you want some helpful starting points, the Facebook Developer Wiki has some help too.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://wiki.developers.facebook.com/index.php/Anatomy_of_a_Facebook_App"&gt;Anatomy_of_a_Facebook_App&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://wiki.developers.facebook.com/index.php/Platform_Core_Components"&gt;Platform_Core_Components&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://wiki.developers.facebook.com/index.php/How-to_Guides"&gt;How-to_Guides&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://wiki.developers.facebook.com/index.php/Creating_a_Platform_Application"&gt;Creating_a_Platform_Application&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9920962" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="Silverlight" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Silverlight/default.aspx" /><category term="Facebook" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Facebook/default.aspx" /><category term="ASP.Net MVC" scheme="http://blogs.msdn.com/coding4fun/archive/tags/ASP.Net+MVC/default.aspx" /></entry><entry><title>Does the S in SQL stand for Scary?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/11/09/9919667.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/11/09/9919667.aspx</id><published>2009-11-09T17:54:04Z</published><updated>2009-11-09T17:54:04Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DoestheSinSQLstandforScary_8B3B/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/DoestheSinSQLstandforScary_8B3B/image_thumb.png" width="240" height="138" /&gt;&lt;/a&gt; Nope, it stands for structured actually.&amp;#160; But if you are a bit afraid of SQL, MSDev.com has &lt;a href="http://www.msdev.com/Directory/SeriesDescription.aspx?CourseId=124"&gt;20 how-to videos about SQL Server 2008 Express&lt;/a&gt;!&amp;#160; This series of short how-to-videos will touch on SQL Server Express 2008 features such as: how to backup a SQL Express database, how to backup a remote SQL Express database, how to restore a SQL Express database, how to update SQL Server Express 2005 to SQL Server Express 2008 and more.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9919667" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="c4fnews" scheme="http://blogs.msdn.com/coding4fun/archive/tags/c4fnews/default.aspx" /><category term="starter kit" scheme="http://blogs.msdn.com/coding4fun/archive/tags/starter+kit/default.aspx" /><category term="SQL" scheme="http://blogs.msdn.com/coding4fun/archive/tags/SQL/default.aspx" /></entry><entry><title>Halloween Gremlins</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/coding4fun/archive/2009/10/31/9915768.aspx" /><id>http://blogs.msdn.com/coding4fun/archive/2009/10/31/9915768.aspx</id><published>2009-11-01T01:37:42Z</published><updated>2009-11-01T01:37:42Z</updated><content type="html">&lt;p&gt;This article describes a quick and easy application to play Halloween tricks on the PC.&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="157"&gt;         &lt;p&gt;Randall Maas&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="481"&gt;         &lt;p&gt;&lt;b&gt;Run It:&lt;/b&gt; &lt;a href="http://gremlin.codeplex.com/Release/ProjectReleases.aspx"&gt;Download&lt;/a&gt;&lt;b&gt;              &lt;br /&gt;Code It:&lt;/b&gt; &lt;a href="http://gremlin.codeplex.com/SourceControl/ListDownloadableCommits.aspx"&gt;Download&lt;/a&gt;&lt;/p&gt;          &lt;p&gt;&lt;b&gt;Difficulty:&lt;/b&gt; Intermediate             &lt;br /&gt;&lt;b&gt;Time Required:&lt;/b&gt; 4 hours             &lt;br /&gt;&lt;b&gt;Cost:&lt;/b&gt; Free!             &lt;br /&gt;&lt;b&gt;Software Needed:&lt;/b&gt; &lt;a href="http://www.microsoft.com/express/download/"&gt;Visual Basic or Visual C# Express&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/HalloweenGremlins_105FE/clip_image001_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/HalloweenGremlins_105FE/clip_image001_thumb.jpg" width="282" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;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.&lt;/p&gt;  &lt;h3&gt;Deployment&lt;/h3&gt;  &lt;p&gt;&lt;b&gt;Run it right away&lt;/b&gt;. 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.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Run it later.&lt;/b&gt; 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!&lt;/p&gt;  &lt;p&gt;If the computer you're using runs on Windows XP the path is: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;C:\Documents and Settings\All Users\Start Menu\Programs\Startup&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;With Vista and Windows 7 the path looks like: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;C:\Users\&lt;i&gt;USERNAME&lt;/i&gt;\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Just remember to change &lt;i&gt;USERNAME&lt;/i&gt; to the name of the user on your machine.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h4&gt;Commandline&lt;/h4&gt;  &lt;p&gt;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:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;b&gt;-aggressive&lt;/b&gt; will make the gremlin's actions more obvious&lt;/p&gt;    &lt;p&gt;&lt;b&gt;-help&lt;/b&gt; will display the command line options&lt;/p&gt;    &lt;p&gt;&lt;b&gt;-name&lt;/b&gt; &lt;i&gt;NAME&lt;/i&gt; 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)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To stop the program, press CTRL+F2.&lt;/p&gt;  &lt;h3&gt;And now … the dodgy bits&lt;/h3&gt;  &lt;p&gt;The overall structure of the program is broken down into three kinds of functionality – actions, triggers and some interstitial glue:&lt;/p&gt;  &lt;p&gt;Actions&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;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. &lt;/li&gt;    &lt;li&gt;A random event might kick the windows around—either friction will slow them down, or... &lt;/li&gt;    &lt;li&gt;Gremlin will type nonsensical messages from the keyboard. These messages are then sent from a virtual keyboard, or they: &lt;/li&gt;    &lt;li&gt;Move the mouse around, or &lt;/li&gt;    &lt;li&gt;Press the mouse buttons, or &lt;/li&gt;    &lt;li&gt;Randomly switch the focus to another window &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Triggers&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;An audio module listens for sounds that trigger the module that shakes your screen. &lt;/li&gt;    &lt;li&gt;Otherwise, the software uses a p/invoke to &lt;strong&gt;GetLastInputInfo()&lt;/strong&gt; 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. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Other&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A hidden window receives key press events. I tend to reuse this module a lot, as a way to &lt;i&gt;stop&lt;/i&gt; experimental programs that may have made my machine unusable. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For fun, I’ll describe a couple of these modules below.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h4&gt;Screen shaker&lt;/h4&gt;  &lt;p&gt;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).&lt;/p&gt;  &lt;p&gt;The screen shaker is special in four ways:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It is a top-level window – no other windows are allowed to go over it. &lt;/li&gt;    &lt;li&gt;This top-level window never becomes the focus window (the window that gets the keyboard events). &lt;/li&gt;    &lt;li&gt;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 &amp;quot;real&amp;quot; desktop shaking, by allowing a person to click on a button or text that passes the click thru to the &lt;i&gt;real&lt;/i&gt; button or text. &lt;/li&gt;    &lt;li&gt;It shakes each of the monitor's screens independently &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;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.&amp;#160; I’ll describe ScrShake first.&lt;/p&gt;  &lt;p&gt;The screen shaking process requires five instance variables:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;i&gt;animTimer&lt;/i&gt; is a System.Windows.Forms.Timer used to force painting of a new frame on the screen. &lt;/li&gt;    &lt;li&gt;&lt;i&gt;bx&lt;/i&gt;, and &lt;i&gt;by &lt;/i&gt;are how far the screen has shaken up or down, left or right. &lt;/li&gt;    &lt;li&gt;&lt;i&gt;angle &lt;/i&gt;is how much the screen has twisted during shaking. &lt;/li&gt;    &lt;li&gt;&lt;i&gt;screenBitmap&lt;/i&gt; is an array of bitmaps, one for each of the monitors. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;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.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;C#      &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ScrShake : UnfocusableForm
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; ScrShake(&lt;span class="kwrd"&gt;double&lt;/span&gt; ShakeCoef, &lt;span class="kwrd"&gt;double&lt;/span&gt; AngleCoef) : &lt;span class="kwrd"&gt;base&lt;/span&gt;(&lt;span class="kwrd"&gt;true&lt;/span&gt;)
   {
      &lt;span class="kwrd"&gt;this&lt;/span&gt;.SuspendLayout();
      … other setup code …
      &lt;span class="rem"&gt;// This is needed since we're over the whole display, and we don't&lt;/span&gt;
      &lt;span class="rem"&gt;// want the other areas to be blurry&lt;/span&gt;
      TransparencyKey =  BackColor = ForeColor = System.Drawing.Color.Fuchsia;
      DoubleBuffered = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
      TopMost = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
      FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

      ClientSize = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Size(300, 300);
      Name = &lt;span class="str"&gt;&amp;quot;topimage&amp;quot;&lt;/span&gt;;
      ResumeLayout(&lt;span class="kwrd"&gt;false&lt;/span&gt;);

      &lt;span class="rem"&gt;// This is need to pass mouse clicks thru to lower layers&lt;/span&gt;
      ExStyle |= (&lt;span class="kwrd"&gt;int&lt;/span&gt;) WS . EX_TRANSPARENT;

      … More code that will be described later…
   }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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; }&lt;/style&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; Stop()
{
   animTimer . Stop();
   Hide();
   screenBitmap = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Screens()
{
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (Visible)
   {
      Stop();
      &lt;span class="kwrd"&gt;return&lt;/span&gt; ;
   }
   &lt;span class="rem"&gt;// Grab the screens&lt;/span&gt;
   screenBitmap = Program.GrabScreens();
   CountDown = 10;

   animTimer.Start();
   angle = 0.0f;
   … code to display the window and get shape of monitors (see below)…
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The screen capture portion is in ScreenCapture.cs. The method GrabScreens() creates an individual bitmap for each monitor and returns them as an array.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Screens()
{
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (Visible)
   {
      Stop();
      &lt;span class="kwrd"&gt;return&lt;/span&gt; ;
   }
   &lt;span class="rem"&gt;// Grab the screens&lt;/span&gt;
   screenBitmap = Program.GrabScreens();
   CountDown = 10;

   animTimer.Start();
   angle = 0.0f;
   … code to display the window and get shape of monitors (see below)…
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Screen[] AllScreens = Screen.AllScreens;

&lt;span class="rem"&gt;// full width/height of all monitors combined&lt;/span&gt;
Rectangle fullSize = AllScreens[0].Bounds;

&lt;span class="rem"&gt;// find a rectangle that will encompass all monitors on the system&lt;/span&gt;
&lt;span class="rem"&gt;// (assuming the primary monitor is on the left/top!)&lt;/span&gt;
&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 1; i &amp;lt; AllScreens.Length &amp;amp;&amp;amp; i &amp;lt; screenBitmap.Length; i++)
{
    Rectangle Bounds = AllScreens[i].Bounds;

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (Bounds.Left &amp;lt; fullSize.Left)
        fullSize.X = Bounds.X;

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (Bounds.Right &amp;gt; fullSize.Right)
        fullSize.Width = Bounds.Right - fullSize.X;

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (Bounds.Top &amp;lt; fullSize.Top)
        fullSize.Y = Bounds.Y;

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (Bounds.Bottom &amp;gt; fullSize.Bottom)
        fullSize.Height = Bounds.Bottom - fullSize.Y;
}&lt;/pre&gt;

&lt;p&gt;The code to show the window, fill the whole screen, and move it to the top looks like:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Show();
WindowState = FormWindowState.Normal;
&lt;span class="rem"&gt;// cover all monitors with one gigantic window&lt;/span&gt;
Location = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(fullSize.Left, fullSize.Top);
Size = &lt;span class="kwrd"&gt;new&lt;/span&gt; Size(fullSize.Width, fullSize.Height);

&lt;span class="rem"&gt;// bring it to the top&lt;/span&gt;
BringToFront();&lt;/pre&gt;

&lt;p&gt;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 &lt;i&gt;AngleCoef&lt;/i&gt; and &lt;i&gt;ShakeCoef&lt;/i&gt;).&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;animTimer = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Windows.Forms.Timer();
animTimer.Tick += &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;object&lt;/span&gt; A, EventArgs E)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (--CountDown &amp;lt; 1)
        Stop();

    angle += (&lt;span class="kwrd"&gt;float&lt;/span&gt;)((Program.Rnd.NextDouble() - 0.5) * AngleCoef);
    bx = (&lt;span class="kwrd"&gt;float&lt;/span&gt;)((Program.Rnd.NextDouble() - 0.5) * ShakeCoef);
    by = (&lt;span class="kwrd"&gt;float&lt;/span&gt;)((Program.Rnd.NextDouble() - 0.5) * ShakeCoef);
    Invalidate();
};

&lt;span class="rem"&gt;// Sets the timer interval to 30 milliseconds.&lt;/span&gt;
animTimer.Interval = 30;&lt;/pre&gt;

&lt;p&gt;Although each monitor shifts up &amp;amp; down, left &amp;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. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnPaint(PaintEventArgs e)
{
    &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnPaint(e);
    Graphics g = e.Graphics;
    g.CompositingQuality = CompositingQuality.HighQuality;

    &lt;span class="rem"&gt;// for each monitor, draw the effect&lt;/span&gt;
    Screen[] AllScreens = Screen.AllScreens;
    &lt;span class="kwrd"&gt;for&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; screenBitmap.Length; i++)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; == screenBitmap[i])&amp;#160;&amp;#160; &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
        g.SmoothingMode = SmoothingMode.HighQuality;

        &lt;span class="rem"&gt;// grab the size of the current monitor&lt;/span&gt;
        Rectangle region = AllScreens[i].Bounds;

        &lt;span class="kwrd"&gt;double&lt;/span&gt; ImWidth = screenBitmap[i].Width  * &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; e.Graphics.DpiX / screenBitmap[i].HorizontalResolution;
        &lt;span class="kwrd"&gt;double&lt;/span&gt; ImHeight= screenBitmap[i].Height * &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; e.Graphics.DpiY / screenBitmap[i].VerticalResolution;
        Matrix m = &lt;span class="kwrd"&gt;new&lt;/span&gt; Matrix();
        m.Translate( (&lt;span class="kwrd"&gt;float&lt;/span&gt;)(- ImWidth  /2), 
                  (&lt;span class="kwrd"&gt;float&lt;/span&gt;)(- ImHeight /2), MatrixOrder.Append);

        &lt;span class="rem"&gt;// rotate the bitmap about the center&lt;/span&gt;
        m.RotateAt(angle, &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(0,0), MatrixOrder.Append);

        &lt;span class="rem"&gt;// center the image no matter what its size is&lt;/span&gt;
        m.Translate( region.Width /2 - bx, 
                  region.Height/2 - by, MatrixOrder.Append);

        &lt;span class="rem"&gt;// assign our transformation matrix&lt;/span&gt;
        g.Transform = m;

        &lt;span class="rem"&gt;// draw it&lt;/span&gt;
        g.DrawImage(screenBitmap[i], region.Left, region.Top);
    }&lt;/pre&gt;

&lt;h4&gt;The Form that does nothing!&lt;/h4&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;This window has no trappings – no border, no resize gripper, no icon, no minimize / maximize buttons, no title bar.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; UnfocusableForm : Form
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; UnfocusableForm(&lt;span class="kwrd"&gt;bool&lt;/span&gt; X) : &lt;span class="kwrd"&gt;base&lt;/span&gt;()
   {
      &lt;span class="kwrd"&gt;if&lt;/span&gt; (X)
        {
           ControlBox = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
           FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
           ShowInTaskbar = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
           ShowIcon = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
           MinimizeBox = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
           SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
           StartPosition = System.Windows.Forms.FormStartPosition.Manual;
        }
   }&lt;/pre&gt;

&lt;p&gt;Then it overrides the ShowWithoutActivation method so that the window will &lt;i&gt;not&lt;/i&gt; become the active when it is shown.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ShowWithoutActivation
{ get {  &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;; } }&lt;/pre&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; CreateParams CreateParams
{
  get
  {
     CreateParams cp=&lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateParams;
     cp . ExStyle |= ExStyle;
     &lt;span class="kwrd"&gt;return&lt;/span&gt; cp;
  }
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;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):&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MA_NOACTIVATE = 0x0003;
&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WndProc(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message m)
{
  &lt;span class="kwrd"&gt;if&lt;/span&gt; (m.Msg == (&lt;span class="kwrd"&gt;int&lt;/span&gt;) WM.MOUSEACTIVATE)
  {
     m.Result = (IntPtr) MA_NOACTIVATE;
     &lt;span class="kwrd"&gt;return&lt;/span&gt;;
  }
  &lt;span class="kwrd"&gt;if&lt;/span&gt; (m.Msg == (&lt;span class="kwrd"&gt;int&lt;/span&gt;) WM.FOCUS)
  {
     m.Result = (IntPtr)1;
     &lt;span class="kwrd"&gt;return&lt;/span&gt;;
  }
  &lt;span class="kwrd"&gt;base&lt;/span&gt;.WndProc(&lt;span class="kwrd"&gt;ref&lt;/span&gt; m);
}&lt;/pre&gt;

&lt;h4&gt;Sending Mouse Events&lt;/h4&gt;

&lt;p&gt;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 &lt;a href="http://blogs.msdn.com/oldnewthing/archive/2009/08/13/9867383.aspx"&gt;a blog posting by Raymond Chen&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[DllImport(&lt;span class="str"&gt;&amp;quot;user32.dll&amp;quot;&lt;/span&gt;, EntryPoint = &lt;span class="str"&gt;&amp;quot;SendInput&amp;quot;&lt;/span&gt;, SetLastError = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;extern&lt;/span&gt; &lt;span class="kwrd"&gt;uint&lt;/span&gt; SendInput(&lt;span class="kwrd"&gt;uint&lt;/span&gt; nInputs, INPUT[] Inputs, &lt;span class="kwrd"&gt;int&lt;/span&gt; cbSize);
[DllImport(&lt;span class="str"&gt;&amp;quot;user32.dll&amp;quot;&lt;/span&gt;, EntryPoint = &lt;span class="str"&gt;&amp;quot;GetMessageExtraInfo&amp;quot;&lt;/span&gt;, SetLastError = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;extern&lt;/span&gt; IntPtr GetMessageExtraInfo();

[StructLayout(LayoutKind.Sequential)]
&lt;span class="kwrd"&gt;struct&lt;/span&gt; INPUT
{
   &lt;span class="kwrd"&gt;internal&lt;/span&gt; INPUTTYPE   type;
   &lt;span class="kwrd"&gt;internal&lt;/span&gt; INPUT_UNION i;
}

 &lt;span class="rem"&gt;// This generates the anonymous union&lt;/span&gt;
[StructLayout(LayoutKind.Explicit)]
&lt;span class="kwrd"&gt;struct&lt;/span&gt; INPUT_UNION
{
   [FieldOffset(0)]
   &lt;span class="kwrd"&gt;public&lt;/span&gt; MOUSEINPUT mi;
   [FieldOffset(0)]
   &lt;span class="kwrd"&gt;public&lt;/span&gt; KEYBDINPUT ki;
   [FieldOffset(0)]
   &lt;span class="kwrd"&gt;public&lt;/span&gt; HARDWAREINPUT hi;
};

[StructLayout(LayoutKind.Sequential)]
&lt;span class="kwrd"&gt;struct&lt;/span&gt; MOUSEINPUT
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;    dx;
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;    dy;
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;    mouseData;
   &lt;span class="kwrd"&gt;public&lt;/span&gt; MOUSEEVENTF dwFlags;
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;    time;
   &lt;span class="kwrd"&gt;public&lt;/span&gt; IntPtr dwExtraInfo;
}

[Flags]
&lt;span class="kwrd"&gt;enum&lt;/span&gt; MOUSEEVENTF : &lt;span class="kwrd"&gt;int&lt;/span&gt;
{
   MOVE       = 0x01,
   LEFTDOWN   = 0x02,
   LEFTUP     = 0x04,
   RIGHTDOWN  = 0x08,
   RIGHTUP    = 0x10,
   MIDDLEDOWN = 0x20,
   MIDDLEUP   = 0x40,
   ABSOLUTE   = 0x8000
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;MOUSEINPUT MEvent = &lt;span class="kwrd"&gt;new&lt;/span&gt; MOUSEINPUT();
MEvent.dwFlags = MOUSEEVENTF.MOVE;
MEvent.dx = Rnd . Next(-8, 8) ;
MEvent.dy = Rnd . Next(-8, 8);
MEvent.dwExtraInfo = GetMessageExtraInfo();
Send(MEvent);&lt;/pre&gt;

&lt;p&gt;Sending the event takes a few more steps that are all wrapped in a helper methdo called Send(). Send these &lt;i&gt;human interface device&lt;/i&gt; 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:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Send(MOUSEINPUT Event)
{
  INPUT[] Events = &lt;span class="kwrd"&gt;new&lt;/span&gt; INPUT[1];
  Events[0] . type = INPUTTYPE . MOUSE;
  Events[0] . i.mi = MEvent;
  &lt;span class="kwrd"&gt;return&lt;/span&gt; SendInput((&lt;span class="kwrd"&gt;uint&lt;/span&gt;)Events.Length, Events, Marshal.SizeOf(Events[0])) &amp;gt; 0; 
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;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”.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;MOUSEINPUT MEvent = &lt;span class="kwrd"&gt;new&lt;/span&gt; MOUSEINPUT();
MEvent.dwFlags = (MOUSEEVENTF) (1 &amp;lt;&amp;lt; (2*Rnd.Next(0, 3)+1)) ;
MEvent.dwExtraInfo = GetMessageExtraInfo ();
Send(MEvent);

MEvent.dwFlags = (MOUSEEVENTF)((&lt;span class="kwrd"&gt;int&lt;/span&gt;) MEvent.dwFlags &amp;lt;&amp;lt; 1);
MEvent.dwExtraInfo = GetMessageExtraInfo ();
Send(MEvent);&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;h4&gt;Generating deranged text&lt;/h4&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;SendKeys . SendWait(GenerateSentence());
SendKeys . SendWait(&lt;span class="str"&gt;&amp;quot;{ENTER}&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/HalloweenGremlins_105FE/clip_image001%5B6%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image001[6]" border="0" alt="clip_image001[6]" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/HalloweenGremlins_105FE/clip_image001%5B6%5D_thumb.jpg" width="282" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;i&gt;Starts&lt;/i&gt; variable is array which holds just these words. Then, in the Transition method, this word is used to find the &lt;i&gt;next&lt;/i&gt; word that can be included in the sentence. It does this by using a dictionary, called &lt;i&gt;NonStart&lt;/i&gt;, 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.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;,&lt;span class="kwrd"&gt;string&lt;/span&gt;[]&amp;gt; NonStart ;
&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] Starts;
&lt;span class="kwrd"&gt;static&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;,&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; Terminal ;

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GenerateSentence()
{
  StringBuilder SB = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();
  &lt;span class="kwrd"&gt;string&lt;/span&gt; Word = Starts[ Rnd.Next(0, Starts.Length) ];

  Transition(SB, Word);
  &lt;span class="kwrd"&gt;return&lt;/span&gt; SB.ToString();
}

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Transition(StringBuilder SB, &lt;span class="kwrd"&gt;string&lt;/span&gt; Word)
{
  &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;)
  {
     SB.Append(Word);
     SB.Append(&lt;span class="str"&gt;' '&lt;/span&gt;);

     &lt;span class="rem"&gt;// Look up word after this&lt;/span&gt;
     &lt;span class="kwrd"&gt;string&lt;/span&gt;[] Nexts;
     &lt;span class="kwrd"&gt;if&lt;/span&gt; (!NonStart.TryGetValue(Word, &lt;span class="kwrd"&gt;out&lt;/span&gt; Nexts))
       &lt;span class="kwrd"&gt;break&lt;/span&gt;;
     &lt;span class="kwrd"&gt;int&lt;/span&gt; Idx = Rnd.Next(Terminal . ContainsKey(Word) ? -1 :0, Nexts.Length);
     &lt;span class="kwrd"&gt;if&lt;/span&gt; (Idx &amp;lt; 0)
       &lt;span class="kwrd"&gt;break&lt;/span&gt;;
     Word = Nexts[Idx];
  }
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;i&gt;Starts&lt;/i&gt; 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 &lt;i&gt;NonStarts&lt;/i&gt; dictionary. The last word of the sentence is also placed into the &lt;i&gt;Terminal&lt;/i&gt; dictionary, to indicate that this might be the end of a sentence.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BuildSuffixTree()
{
  &lt;span class="rem"&gt;// First, build up a list of words that start sentence, and transitions&lt;/span&gt;
  List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; Starts1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();
  Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;,List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;&amp;gt; Trans = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;,List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;&amp;gt;();
  &lt;span class="kwrd"&gt;foreach&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; S1 &lt;span class="kwrd"&gt;in&lt;/span&gt; S.Split(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[]{&lt;span class="str"&gt;'.'&lt;/span&gt;,&lt;span class="str"&gt;'?'&lt;/span&gt;,&lt;span class="str"&gt;'!'&lt;/span&gt;}))
  {
     &lt;span class="kwrd"&gt;string&lt;/span&gt; Prev=&lt;span class="kwrd"&gt;null&lt;/span&gt;;
     &lt;span class="kwrd"&gt;foreach&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; S2 &lt;span class="kwrd"&gt;in&lt;/span&gt; S1.Split(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[]{&lt;span class="str"&gt;' '&lt;/span&gt;,&lt;span class="str"&gt;'\n'&lt;/span&gt;,&lt;span class="str"&gt;'\r'&lt;/span&gt;,&lt;span class="str"&gt;'\t'&lt;/span&gt;,&lt;span class="str"&gt;','&lt;/span&gt;,&lt;span class="str"&gt;';'&lt;/span&gt;}))
     {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (S2 . Length &amp;lt; 1)
          &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; == Prev)
          {
             Starts1.Add(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Intern(S2.ToLower()));
             Prev = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Intern(S2.ToLower());
             &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
          }
        List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; Nextsa;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (! Trans.TryGetValue(Prev, &lt;span class="kwrd"&gt;out&lt;/span&gt; Nextsa))
          Trans[Prev] = Nextsa = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();
        Prev = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Intern(S2.ToLower());
        Nextsa.Add(Prev);
     }
     &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; != Prev)
       Terminal[Prev] = Prev;
 }

 &lt;span class="rem"&gt;// Next, flatten the list of words that start a sentence&lt;/span&gt;
 Starts = Starts1.ToArray();

 &lt;span class="rem"&gt;// Flatten the transition table&lt;/span&gt;
 &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; S3 &lt;span class="kwrd"&gt;in&lt;/span&gt; Trans.Keys)
  NonStart[S3] = Trans [S3].ToArray();
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;h3&gt;The things that trigger action&lt;/h3&gt;

&lt;h4&gt;The audio trigger&lt;/h4&gt;

&lt;p&gt;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 &lt;i&gt;all&lt;/i&gt; audio input devices:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; WaveIn[] StartMics()
{
  &lt;span class="kwrd"&gt;int&lt;/span&gt; NumDevices = WaveIn.DeviceCount;
  WaveIn[] AudIns = &lt;span class="kwrd"&gt;new&lt;/span&gt; WaveIn[NumDevices];
  &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; waveInDevice = 0; waveInDevice &amp;lt; NumDevices ; waveInDevice++)
  {
     AudIns[waveInDevice] = &lt;span class="kwrd"&gt;new&lt;/span&gt; WaveIn();
     AudIns[waveInDevice].DeviceNumber = waveInDevice;
     AudIns[waveInDevice].DataAvailable += waveIn_DataAvailable;
     AudIns[waveInDevice].WaveFormat = &lt;span class="kwrd"&gt;new&lt;/span&gt; WaveFormat(8000, 1);
     AudIns[waveInDevice].StartRecording();
  }
  &lt;span class="kwrd"&gt;return&lt;/span&gt; AudIns;
}&lt;/pre&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/HalloweenGremlins_105FE/clip_image002_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/coding4fun/WindowsLiveWriter/HalloweenGremlins_105FE/clip_image002_thumb.jpg" width="372" height="210" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; AudioThresh  = 0.8;
&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; AudioThresh2 = 0.09;

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; waveIn_DataAvailable(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, WaveInEventArgs e)
{
  &lt;span class="kwrd"&gt;bool&lt;/span&gt; Tr = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
  &lt;span class="kwrd"&gt;double&lt;/span&gt; Sum2  = 0;
  &lt;span class="kwrd"&gt;int&lt;/span&gt; Count = e.BytesRecorded / 2;
  &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; index = 0; index &amp;lt; e.BytesRecorded; index += 2)
  {
     &lt;span class="kwrd"&gt;double&lt;/span&gt; Tmp = (&lt;span class="kwrd"&gt;short&lt;/span&gt;)((e.Buffer[index + 1] &amp;lt;&amp;lt; 8) | e.Buffer[index + 0]);
     Tmp /= 32768.0;
     Sum2 += Tmp*Tmp;
     &lt;span class="kwrd"&gt;if&lt;/span&gt; (Tmp &amp;gt; AudioThresh)
       Tr = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
  }
  Sum2 /= Count;

  &lt;span class="rem"&gt;// If the Mean-Square is greater than a threshold, set a flag to indicate that noise has happened&lt;/span&gt;
  &lt;span class="kwrd"&gt;if&lt;/span&gt; (Tr || Sum2 &amp;gt; AudioThresh2)
    Interlocked.Exchange(&lt;span class="kwrd"&gt;ref&lt;/span&gt; AudioTrigger, 1);
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;
    &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;This sets a flag – AudioTrigger – which will be seen (and reset) in the main loop, with a bit of code that looks like:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;while&lt;/span&gt; (0 == Shutdown)
{
    &lt;span class="rem"&gt;// Do some lovely events&lt;/span&gt;
    Application . DoEvents();
    Thread . Sleep (20);

    &lt;span class="rem"&gt;//… do some other stuff ..&lt;/span&gt;

    &lt;span class="rem"&gt;// Check for a kick from the sound system&lt;/span&gt;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (0 != AudioTrigger)
    {
        Interlocked . Exchange(&lt;span class="kwrd"&gt;ref&lt;/span&gt; AudioTrigger, 0);
        …
        ScreenShaker . Screens();
        &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
    }
    &lt;span class="rem"&gt;//… more checks for the user idle trigger…&lt;/span&gt;
}&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/pre&gt;

&lt;h4&gt;Waiting for the user to be idle&lt;/h4&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;uint&lt;/span&gt; LastTime = Win32.LastInputTime();
&lt;span class="kwrd"&gt;if&lt;/span&gt; ((&lt;span class="kwrd"&gt;uint&lt;/span&gt;) Environment.TickCount &amp;lt; IdleTimeTrigger + LastTime)
    &lt;span class="kwrd"&gt;continue&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[DllImport(&lt;span class="str"&gt;&amp;quot;User32.dll&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;extern&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; GetLastInputInfo(&lt;span class="kwrd"&gt;ref&lt;/span&gt; LASTINPUTINFO LastInfo);

[StructLayout(LayoutKind.Sequential)]
&lt;span class="kwrd"&gt;struct&lt;/span&gt; LASTINPUTINFO
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;uint&lt;/span&gt; cbSize;

  &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
  &lt;span class="rem"&gt;/// Number of system tickes&lt;/span&gt;
  &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;uint&lt;/span&gt; dwTime;
}&lt;/pre&gt;

&lt;p&gt;Then, these two structures are wrapped up into the LastInputTime() helper procedure, which does the dirty work of allocating and initializing a structure. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;C# &lt;/b&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;uint&lt;/span&gt; LastInputTime()
{
  LASTINPUTINFO lastInput=&lt;span class="kwrd"&gt;new&lt;/span&gt; LASTINPUTINFO();
  lastInput.cbSize = (&lt;span class="kwrd"&gt;uint&lt;/span&gt;)Marshal.SizeOf(lastInput);
  GetLastInputInfo(&lt;span class="kwrd"&gt;ref&lt;/span&gt; lastInput);
  &lt;span class="kwrd"&gt;return&lt;/span&gt; lastInput . dwTime;
}&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/pre&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;If you want to try this out, the download link for the &lt;a href="http://gremlin.codeplex.com/Release/ProjectReleases.aspx"&gt;executable&lt;/a&gt; and &lt;a href="http://gremlin.codeplex.com/SourceControl/ListDownloadableCommits.aspx"&gt;source code&lt;/a&gt; are at the top of the article!&lt;/p&gt;

&lt;h4&gt;Resources and References&lt;/h4&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://pinvoke.net/"&gt;Pinvoke.net&lt;/a&gt; – a wiki-style site with many useful bits of example code related to calling the Windows API from within .NET. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/coding4fun/archive/2009/10/08/9905168.aspx"&gt;“.NET Audio Recorder”&lt;/a&gt; by Mark Heath, from which I stole code to make the audio trigger. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/coding4fun/archive/2007/10/29/5773776.aspx"&gt;“Possessed PC Pranks for Halloween”&lt;/a&gt; by Brian Peek, from which I stole the basic code for sending keystrokes. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/coding4fun/archive/2007/03/29/1991785.aspx"&gt;“April Fools’ Day Application”&lt;/a&gt; by Brian Peek, from which I stole code to grab the screen and rotate it. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;About The Author&lt;/h3&gt;

&lt;p&gt;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 &lt;a href="mailto:randym@acm.org"&gt;randym@acm.org&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9915768" width="1" height="1"&gt;</content><author><name>Coding4Fun</name><uri>http://blogs.msdn.com/members/Coding4Fun.aspx</uri></author><category term="halloween" scheme="http://blogs.msdn.com/coding4fun/archive/tags/halloween/default.aspx" /><category term="holiday" scheme="http://blogs.msdn.com/coding4fun/archive/tags/holiday/default.aspx" /><category term="Audio" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Audio/default.aspx" /><category term="Pranks" scheme="http://blogs.msdn.com/coding4fun/archive/tags/Pranks/default.aspx" /></entry></feed>