<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Janne Mattila's blog : Fun</title><link>http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx</link><description>Tags: Fun</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>My Chess (another chess application)</title><link>http://blogs.msdn.com/jannemattila/archive/2009/10/22/my-chess-another-chess-application.aspx</link><pubDate>Thu, 22 Oct 2009 14:43:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9911395</guid><dc:creator>jannemattila</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/9911395.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=9911395</wfw:commentRss><description>&lt;p&gt;I came up with the idea of &lt;em&gt;My Chess&lt;/em&gt; when I wanted to play games with my friends and I noticed that I don’t have time to do that &lt;strong&gt;:-)&lt;/strong&gt; So I decided to write an application that allows me to play chess with my friends just by using small amount of time every now and then (approach is pretty different compared to the “&lt;em&gt;normal&lt;/em&gt;” chess). Small amount of time means something like 10 seconds per move so and not more... Of course if you WANT to use more time you’re allowed to do that.&lt;/p&gt;  &lt;p&gt;Here is list of other &lt;em&gt;features&lt;/em&gt; that I wanted from &lt;em&gt;My Chess&lt;/em&gt;:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Possibility to play offline. In another words I don’t want to think about the transport at all. I would just like to pass the transport related stuff to someone else. &lt;/li&gt;    &lt;li&gt;Mobile version of the application (HTC Touch Pro since I have one) &lt;/li&gt;    &lt;li&gt;“Social chess”: I wanted to have possibility to add comment when making move. Just because I want to tell to my opponents how good move I have made and remind them about their bad ones &lt;strong&gt;:-)&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Game should be fast and easy. You should be able to make your move with just few clicks. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I decided to go with C++ since I didn’t want to take start up delay of .NET application on my mobile device. This one was easy decision :-)&lt;/p&gt;  &lt;p&gt;Then I thought that I could use email as my transport because it automatically solves issues with the connectivity. On desktop I could rely on Outlook and mobile device I could rely on Pocket Outlook. More about technical details later in this post. &lt;/p&gt;  &lt;p&gt;But then I was forced to think proper way to solve how to transmit the game state. I mean that how could I pass the current state of the game to my opponent so that it would be easy for him/her to continue from that state.&amp;#160; Use of attachment at the email was one option. But the story for the end user on mobile device with attachments isn’t that good so I didn’t use effort on this option. I took another approach which was to define URL format that I could use to serialize the game state. Here is one example game state:    &lt;br /&gt;&lt;em&gt;my://chess/MczrFh7z?w=player1@contoso.com%26b=player2@contoso.com&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Game state uses &lt;em&gt;my&lt;/em&gt; protocol which I have mapped to application (&lt;a href="http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx" target="_blank"&gt;Registering an Application to a URL Protocol&lt;/a&gt; on MSDN). Of course &lt;em&gt;My Chess&lt;/em&gt; is configured according to the article so that it will called when &lt;em&gt;my &lt;/em&gt;protocol is launched. Here is example &lt;em&gt;.reg&lt;/em&gt; how custom application can be mapped to protocol:&lt;/p&gt;  &lt;table cellspacing="10"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" align="right"&gt;         &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top"&gt;
        &lt;pre&gt;Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\my]
@=&amp;quot;URL:My Chess Protocol&amp;quot;
&amp;quot;URL Protocol&amp;quot;=&amp;quot;&amp;quot;

[HKEY_CLASSES_ROOT\my\shell]

[HKEY_CLASSES_ROOT\my\shell\open]

[HKEY_CLASSES_ROOT\my\shell\open\command]
@=&amp;quot;\&amp;quot;C:\\path\\My Chess (x64).exe\&amp;quot; %1&amp;quot;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;So it really is that simple. Just define own key under HKEY_CLASSES_ROOT and set path to your application and it will be called automatically by the OS.&lt;/p&gt;

&lt;p&gt;If you look the same with &lt;em&gt;regedit&lt;/em&gt; it looks like this: &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="Registry" border="0" alt="Registry" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Registry_6.png" width="806" height="381" /&gt;&lt;/p&gt;

&lt;p&gt;If you now open up links starting with &lt;em&gt;my&lt;/em&gt; protocol they will eventually take you to the configured application. But you probably see this kind of security dialogs before your own application starts (at least for the first time): 

  &lt;br /&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="IE Confirmation dialog" border="0" alt="IE Confirmation dialog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/IE%20Confirmation_1.png" width="599" height="377" /&gt;&amp;#160; &lt;br /&gt;Just uncheck “&lt;em&gt;Always ask before opening this type of address&lt;/em&gt;” and press &lt;em&gt;Allow&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&amp;#160;&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="My Chess Security Warning" border="0" alt="My Chess Security Warning" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/image_15.png" width="486" height="302" /&gt;&lt;/p&gt;

&lt;p&gt;Same goes with this dialog. Just check “&lt;em&gt;Do not show me the warning for this program again”&lt;/em&gt; and press &lt;em&gt;Allow&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;em&gt;&lt;strong&gt; &lt;/strong&gt;Make sure you understand the consequences of allowing protocol to map to application. If you’re application doesn’t validate data correctly it may lead to security issues when someone passes malicious data to your application. Remember you have been warned!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After that you should finally be at your application and you can use the information passed on the command line to execute the required actions.&lt;/p&gt;

&lt;p&gt;So basically now I have tools to build the application... But I haven’t yet solved the “&lt;em&gt;creating the email message&lt;/em&gt;” part of this solution. Remember I have both desktop application and mobile application to built.&lt;/p&gt;

&lt;p&gt;On desktop I’m using Outlook as my mail transport and it has pretty good instructions in here: 
  &lt;br /&gt;&lt;a href="http://support.microsoft.com/kb/259298" target="_blank"&gt;How to use an Outlook Object Model from Visual C++ by using a #import statement&lt;/a&gt; 

  &lt;br /&gt;&lt;a href="http://support.microsoft.com/kb/199870" target="_blank"&gt;How To Send a Message by Outlook Object Model with VC++&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using Outlook on desktop with C++ is almost as easy as using it from .NET. It’s straight forward thing. So far so good right!&lt;/p&gt;

&lt;p&gt;On mobile device things aren’t quite that easy since you need to use MAPI for sending the mail message. Here are few examples for that: 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/windowsmobile/archive/2007/03/21/getting-started-with-mapi.aspx" target="_blank"&gt;Getting Started with MAPI&lt;/a&gt; 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/windowsmobile/archive/2007/04/23/practical-use-of-mapi.aspx" target="_blank"&gt;Practical Use of MAPI&lt;/a&gt; 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/raffael/archive/2008/09/08/mapi-on-windows-mobile-6-programmatically-retrieve-mail-body-sample-code.aspx" target="_blank"&gt;MAPI on Windows Mobile 6: Programmatically retrieve mail BODY (sample code)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But as always things aren’t as easy as they first seem to be. Since even if I did register &lt;em&gt;my&lt;/em&gt; protocol at the mobile device it didn’t work as I expected. The problem was that Pocket Outlook always launched the URL to the default browser even if I had registration done to my own protocol. After some digging I found out that there are many security features that prevent that from happening. So in order to do it the &lt;em&gt;right way&lt;/em&gt; I should have to edit/configure some files to allow protocol to be launched correctly. But since this is more &lt;em&gt;concept&lt;/em&gt; than &lt;em&gt;production kind-of-application&lt;/em&gt; I took another route... I chose to &lt;strong&gt;*hijack*&lt;/strong&gt; MMS protocol for my custom application :-) I did that because it’s one of those protocols that are configured properly to the system. It normally launches Windows Media Player but I changed that to launch &lt;em&gt;My Chess&lt;/em&gt; instead. This is the reason why you see two links at the emails underneath. The URL structure is exactly the same... Only the protocol part is either &lt;em&gt;my&lt;/em&gt; or &lt;em&gt;mms&lt;/em&gt; depending on the link. I admit that this one was dirty hack...&lt;/p&gt;

&lt;p&gt;Now we have solved pretty much everything. But what about graphics then? Well I used images from Wikipedia at the &lt;a href="http://en.wikipedia.org/wiki/Chess_piece" target="_blank"&gt;Chess piece&lt;/a&gt; article (example &lt;a href="http://en.wikipedia.org/wiki/File:Chess_kdt45.svg" target="_blank"&gt;King&lt;/a&gt; where you can see the licenses as well). Graphics is another interesting difference between desktop application and mobile application since GDI+ headers and libraries aren’t available for the mobile environment :-( But I wanted to use GDI+ on my desktop application even if I was forced to use GDI at the mobile application. Yeah I know... someone else would have built them using the same codebase but not me.&lt;/p&gt;

&lt;p&gt;I used following functionalities from GDI+: Bitmap, Graphics (DrawImage, DrawCachedBitmap, DrawRectangle, FillRectangle), Graphics::FromImage, FontFamily, Font, SolidBrush, Pen, CachedBitmap etc.&lt;/p&gt;

&lt;p&gt;I used following functionalities from GDI: DeleteDC, DeleteObject, CreateCompatibleDC, CreateCompatibleBitmap, SelectObject, Rectangle, TransparentBlt, BitBlt etc.&lt;/p&gt;

&lt;p&gt;Are you already eager to see the final outcome? Well here it goes:&lt;/p&gt;

&lt;p&gt;Desktop version:&lt;/p&gt;

&lt;p&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="My Chess" border="0" alt="My Chess" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/My%20Chess_2.png" width="609" height="610" /&gt; &lt;/p&gt;

&lt;p&gt;Mobile version (screenshot from emulator. It looks better on real device):&lt;/p&gt;

&lt;p&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="My Chess (Mobile)" border="0" alt="My Chess (Mobile)" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/My%20Chess%20Mobile_3.png" width="373" height="570" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So how does it work in real life? Here is small example:&lt;/p&gt;

&lt;p&gt;First if start &lt;em&gt;My Chess&lt;/em&gt; without parameters so it creates automatically new game (in this example I play against myself): 

  &lt;br /&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="My Chess new game dialog" border="0" alt="My Chess new game dialog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Email0_1.png" width="502" height="204" /&gt;&lt;/p&gt;

&lt;p&gt;In order to update the registry correctly for the protocol &lt;em&gt;My Chess&lt;/em&gt; needs to be run for the first time in the “&lt;em&gt;Run as administrator”&lt;/em&gt; –mode:&lt;/p&gt;

&lt;p&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="Run as administrator in order to register the protocol" border="0" alt="Run as administrator in order to register the protocol" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/image_6.png" width="365" height="79" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So now you have new game and you can use mouse to make the move (see simple coloring to indicate the move): 
  &lt;br /&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="Coloring of the move" border="0" alt="Coloring of the move" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/image_9.png" width="145" height="318" /&gt; &lt;/p&gt;

&lt;p&gt;When you have done that you can press &lt;em&gt;Send&lt;/em&gt; menu which then creates email message for you where you can add your own comment to your move (everything else is generated.. you just need to add last line): 

  &lt;br /&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="My Chess created email message to Outlook" border="0" alt="My Chess created email message to Outlook" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Email_1.png" width="448" height="398" /&gt; 

  &lt;br /&gt;Now the game state is passed to the opponent as just normal email. When opponent receives it and presses the link following security prompt is displayed (Note: on mobile device application is launched directly without any dialogs): 

  &lt;br /&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="Outlook Security Notice on my protocol link" border="0" alt="Outlook Security Notice on my protocol link" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Email2_1.png" width="570" height="499" /&gt; 

  &lt;br /&gt;After that &lt;em&gt;My Chess&lt;/em&gt; is opened and it’s opens the current game state directly: 

  &lt;br /&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="Email3" border="0" alt="Email3" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Email3_1.png" width="630" height="628" /&gt;&amp;#160;&amp;#160; &lt;br /&gt;And now you’re ready to make your move and then send it to the opponent with some nasty comment of course. &lt;/p&gt;

&lt;p&gt;Current status of the &lt;em&gt;My Chess&lt;/em&gt; is pretty much &lt;em&gt;experimental&lt;/em&gt; / &lt;em&gt;concept state&lt;/em&gt; since I haven’t yet implemented all the necessary functions to make it &lt;em&gt;_real_&lt;/em&gt; chess application:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Move validation is currently missing and all special moves haven’t been implemented (promotion is only special move that has been implemented) &lt;/li&gt;

  &lt;li&gt;Currently there isn’t way to see previous move or move history (it’s stored behind the covers but it’s not visible). I’m going to implement animations so that when user opens &lt;em&gt;My Chess&lt;/em&gt; something like last 3 moves of the game would be animated. And user could browse the move history (with animations of course!) to see what has happened previously on the game. &lt;/li&gt;

  &lt;li&gt;I &lt;em&gt;could&lt;/em&gt; CC the email message to email box that could be read by machine. It then could insert the game state to database, create some statistics about the games, history of games etc. This brings more possibilities to extend the game in the future. But I probably leave this to someone else...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the way... you might have noticed that I used &lt;em&gt;chess&lt;/em&gt; as in my URL to define which game should be launched from the &lt;em&gt;my&lt;/em&gt; protocol. This indicates that something else might come in the future. That remains to be seen! &lt;/p&gt;

&lt;p&gt;How could you use information provided in this blog entry for your own needs? Well here’s one: I have many times heard that customers need to “Send shortcuts” from their existing applications to each other. This could be way to do that. Just add functionality to “copy shortcut” from applications current state and then allow user to send it. Then at the receiving end you could create “proxy application” that interprets received information and opens the application into same state that the other user had. It could be pretty good improvement in many cases. 
  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking! 

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9911395" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx">Fun</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/C_2F00_C_2B002B00_/default.aspx">C/C++</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Mobile/default.aspx">Mobile</category></item><item><title>My Notes (a small application between notepad and OneNote)</title><link>http://blogs.msdn.com/jannemattila/archive/2009/04/30/my-notes-a-small-application-between-notepad-and-onenote.aspx</link><pubDate>Thu, 30 Apr 2009 10:20:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9578916</guid><dc:creator>jannemattila</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/9578916.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=9578916</wfw:commentRss><description>&lt;p&gt;I have been using Windows 7 and&amp;#160; Windows Server 2008 R2 since the first beta. And I mean on my “&lt;em&gt;production&lt;/em&gt;” laptops. And I have to say that I haven’t had any major issues with them. In fact I’ve used to them so much that I don’t want to use older versions anymore &lt;strong&gt;:-) &lt;/strong&gt;And there are few improvements in them that I specially enjoy. Of course the biggest one is the new taskbar... But surprisingly I have also found new application that I have “always needed”: &lt;strong&gt;Sticky Notes&lt;/strong&gt;!&lt;/p&gt;  &lt;p&gt;Sticky Notes is small application where you can write small notes to yourself. I call it “&lt;em&gt;something between notepad and OneNote&lt;/em&gt;”. Reason for that is the fact that notepad is lightweight but it doesn’t contain &lt;u&gt;any&lt;/u&gt; features. OneNote is full-blown application with &lt;u&gt;tons&lt;/u&gt; of features. Sticky Notes lives between those too... It contains just &lt;u&gt;enough&lt;/u&gt; features that make it useful and it also looks nice! The only issue I’m having with the Sticky Notes is the fact that it comes with Windows 7 only &lt;strong&gt;:-(&lt;/strong&gt; So in my main “&lt;em&gt;production&lt;/em&gt;” laptop (which is R2) I don’t have sticky notes.&lt;/p&gt;  &lt;p&gt;For me it was a bit disappointing but I still understood the logic for that. Of course Sticky Notes isn’t “something that you would expect on the server” but since I really need this kind of application... I was forced to create one &lt;strong&gt;:-) &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Normally when I create application I’ll just create new .NET project and start writing the application. But now I don’t want to suffer this penalty (screenshot taken from “&lt;em&gt;File –&amp;gt; New Project: Windows Forms Application –&amp;gt; Run&lt;/em&gt;”):&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title=".NET Windows Forms application" border="0" alt=".NET Windows Forms application" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_12.png" width="463" height="218" /&gt;&amp;#160; &lt;br /&gt;Downside of .NET applications is the memory usage. Normally I don’t care about it but since now I’m going to create application that will be “always on” I just have to care about it. I don’t want to waste too much memory (I only have 8 GB of it :-). Therefore I decided to go with the native way (Win32, C/C++ or whatever you like to call it). It gives me possibility to be in control of all the used resources.&lt;/p&gt;  &lt;p&gt;And here is the result “&lt;em&gt;My Notes&lt;/em&gt;” application:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="My Notes - Example" border="0" alt="My Notes - Example" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_3.png" width="546" height="272" /&gt; &lt;/p&gt;  &lt;p&gt;I’ve hidden the menus and tried to make the borders as small as possible. I don’t want to waste space as much the normal Windows application does:    &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Standard windows application" border="0" alt="Standard windows application" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_9.png" width="380" height="233" /&gt;&amp;#160; &lt;br /&gt;“Standard” windows application doesn’t look that good either. So therefore I wanted to give it a bit more “fresh and appealing looks”. I used GDI+ and &lt;em&gt;LinearGradientBrush&lt;/em&gt; to make it fancier. In case your wondering how to add GDI+ to your native application then it’s just this simple:&lt;/p&gt;  &lt;table cellspacing="10"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" align="right"&gt;         &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top"&gt;
        &lt;pre&gt;GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;

GdiplusStartup(&amp;amp;gdiplusToken, &amp;amp;gdiplusStartupInput, NULL);
&lt;font color="#008000"&gt;// ...
&lt;/font&gt;GdiplusShutdown(gdiplusToken);&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;See more about GDI+ on MSDN if your &lt;a href="http://msdn.microsoft.com/en-us/library/ms534077(VS.85).aspx" target="_blank"&gt;interested&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Even if I wanted the application to small borders I didn’t want to completely remove the menus. I used same thing as in IE for example... pressing &lt;em&gt;Alt&lt;/em&gt; brings in the menu:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="My Notes - Menu visible" border="0" alt="My Notes - Menu visible" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_6.png" width="217" height="70" /&gt; &lt;/p&gt;

&lt;p&gt;I also wanted to give myself possibility to extend the application little bit more and I also added context menu to the edit surface. I don’t know yet what to put there but it’s nice to have if I need it someday &lt;strong&gt;:-)
    &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="My Notes - Content menu" border="0" alt="My Notes - Content menu" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_27.png" width="322" height="122" /&gt; &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I had to add “graphical menu” for basic operations like New and Close (just for fun):&lt;/p&gt;

&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="My Notes - Graphical menu" border="0" alt="My Notes - Graphical menu" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_15.png" width="545" height="40" /&gt; &lt;/p&gt;

&lt;p&gt;Graphical menu is only visible if mouse is on top of the so called caption bar (as in screenshot).&lt;/p&gt;

&lt;p&gt;And of course this should be in x64 since I’m running my R2 on x64:
  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VS Configuration Manager dialog" border="0" alt="VS Configuration Manager dialog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_18.png" width="717" height="451" /&gt; &lt;/p&gt;

&lt;p&gt;If your wondering why you don’t have the option to use &lt;em&gt;x64&lt;/em&gt; then you haven’t most likely checked the option in the Visual Studio setup. Just go to &lt;em&gt;Control Panel&lt;/em&gt; and locate VS and select option to change the setup:

  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Control panel - Visual Studio" border="0" alt="Control panel - Visual Studio" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_21.png" width="427" height="53" /&gt;&amp;#160; &lt;br /&gt;Then just check the &lt;em&gt;x64&lt;/em&gt; if that’s what you want:

  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VS setup" border="0" alt="VS setup" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_24.png" width="332" height="320" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;And last but not least... I’ve put my &lt;em&gt;My Notes&lt;/em&gt; to the &lt;a href="https://www.mesh.com/welcome/default.aspx" target="_blank"&gt;Live Mesh&lt;/a&gt; folder and synchronized my content to other devices. It’s simple and since I’m saving my note content to Rich Text Format (RTF) I can open up my notes even in my Windows Mobile. So now I have pretty good solution for my notes.

  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking!

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9578916" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx">Fun</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/C_2F00_C_2B002B00_/default.aspx">C/C++</category></item><item><title>Treasure hunting with Microsoft Tag</title><link>http://blogs.msdn.com/jannemattila/archive/2009/03/31/treasure-hunting-with-microsoft-tag.aspx</link><pubDate>Tue, 31 Mar 2009 22:58:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9523795</guid><dc:creator>jannemattila</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/9523795.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=9523795</wfw:commentRss><description>&lt;p&gt;Many people know &lt;a href="http://en.wikipedia.org/wiki/Geocaching" target="_blank"&gt;geocaching (Wikipedia)&lt;/a&gt; and think of it as one of the modern treasure hunting games. Few days ago I found myself playing around with &lt;a href="http://tag.microsoft.com/" target="_blank"&gt;Microsoft Tag&lt;/a&gt; and I thought that this could be another treasure hunting game! Therefore I thought that I’ll do a different post this time.&lt;/p&gt;  &lt;p&gt;First I’ll show how you can try out Microsoft Tag. First go to this page: &lt;a href="http://tag.microsoft.com/" target="_blank"&gt;http://tag.microsoft.com/&lt;/a&gt;. Click on the “Sign Up” –button (or “Sign In” if you have already done so). After sign in you have possibility to create categories, create tags and view reports about your tag usage. &lt;/p&gt;  &lt;p&gt;As an example I’ll create a new tag category:    &lt;br /&gt;&lt;a href="http://tag.microsoft.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Create tag category" border="0" alt="Create tag category" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_3.png" width="402" height="329" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And I’ll use “&lt;em&gt;Example tags”&lt;/em&gt; for the name:     &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Example tags category" border="0" alt="Example tags category" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_6.png" width="578" height="381" /&gt;&amp;#160; &lt;br /&gt;Then I’m going to create example tag that points to my blog:     &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Example link to my blog" border="0" alt="Example link to my blog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_9.png" width="607" height="746" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;After save has done it’s magic I can go and render my new fancy tag:    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_11.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Launch tag rendering" border="0" alt="Launch tag rendering" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_thumb_3.png" width="644" height="102" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then it asks me that what kind of rendering do I want:    &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Tag rendering options" border="0" alt="Tag rendering options" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_17.png" width="381" height="566" /&gt;&amp;#160;&amp;#160; &lt;br /&gt;I selected &lt;em&gt;Render Type&lt;/em&gt; as PDF and &lt;em&gt;Plain&lt;/em&gt; as the output format. Of course that result can be then printed out since it’s just image on the PDF. Here is the result:     &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Rendered tag" border="0" alt="Rendered tag" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_20.png" width="501" height="506" /&gt; &lt;/p&gt;  &lt;p&gt;Now you can go to &lt;a href="http://tags.microsoft.com"&gt;http://tags.microsoft.com&lt;/a&gt; with your mobile phone and download Microsoft Tag Reader for your phone. If you go there directly with your brower you can see list of supported platforms:     &lt;br /&gt;&lt;a href="http://tags.microsoft.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Supported phones" border="0" alt="Supported phones" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_23.png" width="298" height="550" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you now start Tag Reader in your phone it will automatically start you phones camera and starts displaying picture from the camera. If you now point it to tag (like the one in this post :-) it recognizes the image and launches the action that I have configured. And since I configured tag to go to this blog you probably ended up to my blog with your mobile browser &lt;strong&gt;:-)&lt;/strong&gt; And that’s cool right!&lt;/p&gt;  &lt;p&gt;And finally we have the tools to build our own treasure hunt game! So now you need to do some planning and then you just create tags to support you treasure hunt game. But I’ll leave you the planning part...&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;NOTE:&lt;/u&gt; &lt;/strong&gt;By the time of writing Microsoft Tag is in Beta phase which means creating of tags is free:     &lt;br /&gt;&lt;a href="http://tags.microsoft.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Beta statement" border="0" alt="Beta statement" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_26.png" width="463" height="104" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So now it’s your time to go and create few tags!    &lt;br /&gt;    &lt;br /&gt;Anyways... Happy hacking!     &lt;br /&gt;    &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9523795" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx">Fun</category></item><item><title>Creating Excel Game (or something similar for fun)</title><link>http://blogs.msdn.com/jannemattila/archive/2009/01/29/creating-excel-game-or-something-similar-for-fun.aspx</link><pubDate>Thu, 29 Jan 2009 22:47:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9383568</guid><dc:creator>jannemattila</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/9383568.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=9383568</wfw:commentRss><description>&lt;p&gt;Awhile back I saw really interesting article: &lt;a href=" http://www.gamasutra.com/view/feature/3563/microsoft_excel_revolutionary_3d_.php" target="_blank"&gt;Microsoft Excel: Revolutionary 3D Game Engine?&lt;/a&gt;     &lt;br /&gt;After that I was forced to do small test on that and that of course resulted to this post &lt;strong&gt;:-)&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I just grabbed the idea and made small “car game” (but in reality it just vaguely reminds of car game) on top of Excel. And here is the result: &lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_11.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Car Game example" border="0" alt="Car Game example" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_thumb_3.png" width="639" height="480" /&gt;&lt;/a&gt;     &lt;br /&gt;My car (or just blue box if you wish) can be controlled with mouse. If you press left mouse button it increases the speed of the car (a.k.a. gas pedal). I was too lazy to “invent” brake so car just slowly slows down if user isn’t pressing the left mouse button. User can control the “car” by moving mouse from left to right. Right mouse button quits the game.&lt;/p&gt;  &lt;h4&gt;Click here for the &lt;a href="http://cid-64286c13c6bd5d77.skydrive.live.com/self.aspx/Julkinen/Blog%20files/ExcelCarGame.wmv" target="_blank"&gt;video&lt;/a&gt;.&lt;/h4&gt; Since I just wanted to test basic input and drawing mechanisms I didn’t even bother to think of creating any physics. I’ll leave that to you! But here’s the source code for my example:   &lt;table cellspacing="10"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" align="right"&gt;         &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top"&gt;
        &lt;pre&gt;&lt;font color="#008000"&gt;' WinAPI stuff:
&lt;/font&gt;&lt;font color="#0000ff"&gt;Declare&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub&lt;/font&gt; Sleep &lt;font color="#0000ff"&gt;Lib&lt;/font&gt; &lt;font color="#a31515"&gt;&amp;quot;kernel32&amp;quot;&lt;/font&gt; (&lt;font color="#0000ff"&gt;ByVal&lt;/font&gt; dwMilliseconds &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long&lt;/font&gt;)
&lt;font color="#0000ff"&gt;Declare&lt;/font&gt; &lt;font color="#0000ff"&gt;Function&lt;/font&gt; GetAsyncKeyState &lt;font color="#0000ff"&gt;Lib&lt;/font&gt; &lt;font color="#a31515"&gt;&amp;quot;user32&amp;quot;&lt;/font&gt; (&lt;font color="#0000ff"&gt;ByVal&lt;/font&gt; vKey &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long&lt;/font&gt;) &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Integer
Declare&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub&lt;/font&gt; GetCursorPos &lt;font color="#0000ff"&gt;Lib&lt;/font&gt; &lt;font color="#a31515"&gt;&amp;quot;user32&amp;quot;&lt;/font&gt; (&lt;font color="#0000ff"&gt;ByRef&lt;/font&gt; lpoint &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI)
&lt;font color="#0000ff"&gt;Declare&lt;/font&gt; &lt;font color="#0000ff"&gt;Function&lt;/font&gt; ShowCursor &lt;font color="#0000ff"&gt;Lib&lt;/font&gt; &lt;font color="#a31515"&gt;&amp;quot;user32&amp;quot;&lt;/font&gt; (&lt;font color="#0000ff"&gt;ByVal&lt;/font&gt; bShow &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long&lt;/font&gt;) &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long

Type&lt;/font&gt; POINTAPI
  x &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long
&lt;/font&gt;  y &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long
End&lt;/font&gt; &lt;font color="#0000ff"&gt;Type&lt;/font&gt; 

&lt;font color="#0000ff"&gt;Sub&lt;/font&gt; GameLoop()

  &lt;font color="#008000"&gt;' Input related variables:
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; mouseLocation &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI
  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; mouseLocationPrevious &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI

  &lt;font color="#008000"&gt;' Get &amp;amp; Set original mouse position:
&lt;/font&gt;  GetCursorPos mouseLocation
  mouseLocationPrevious = mouseLocation

  &lt;font color="#008000"&gt;' Initialize the system:
&lt;/font&gt;  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Xdiff&amp;quot;&lt;/font&gt;).Value = 0
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Ydiff&amp;quot;&lt;/font&gt;).Value = 0
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SteeringWheel&amp;quot;&lt;/font&gt;).Value = 90
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = 0
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarX&amp;quot;&lt;/font&gt;).Value = 250
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarY&amp;quot;&lt;/font&gt;).Value = 250

  &lt;font color="#008000"&gt;' Hide mouse cursor:
&lt;/font&gt;  ShowCursor 0

  &lt;font color="#008000"&gt;' We're going to loop until mouse click:
&lt;/font&gt;  &lt;font color="#0000ff"&gt;While&lt;/font&gt; GetAsyncKeyState(vbKeyRButton) = 0

    &lt;font color="#008000"&gt;' Magic:
&lt;/font&gt;    Sheets(&lt;font color="#a31515"&gt;&amp;quot;GameBoard&amp;quot;&lt;/font&gt;).Range(&lt;font color="#a31515"&gt;&amp;quot;Z_SortArea&amp;quot;&lt;/font&gt;).Sort _
      Sheets(&lt;font color="#a31515"&gt;&amp;quot;GameBoard&amp;quot;&lt;/font&gt;).Range(&lt;font color="#a31515"&gt;&amp;quot;NormalZ&amp;quot;&lt;/font&gt;), xlAscending

    GetCursorPos mouseLocation
    DrawCar &lt;font color="#a31515"&gt;&amp;quot;car1&amp;quot;&lt;/font&gt;, mouseLocation, mouseLocationPrevious

    ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarX&amp;quot;&lt;/font&gt;).Value = _
      ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarX&amp;quot;&lt;/font&gt;).Value - ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SpeedY&amp;quot;&lt;/font&gt;).Value
    ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarY&amp;quot;&lt;/font&gt;).Value = _
      ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarY&amp;quot;&lt;/font&gt;).Value - ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SpeedX&amp;quot;&lt;/font&gt;).Value
    mouseLocationPrevious = mouseLocation

    &lt;font color="#008000"&gt;' Let’s take a nap:
&lt;/font&gt;    Sleep(10)

    &lt;font color="#0000ff"&gt;If&lt;/font&gt; GetAsyncKeyState(vbKeyLButton) &amp;lt;&amp;gt; 0 &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;      &lt;font color="#008000"&gt;' User is pressing the gas pedal =&amp;gt; More speed:
&lt;/font&gt;      ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = _
        ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value + ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Accelerate&amp;quot;&lt;/font&gt;).Value
      &lt;font color="#0000ff"&gt;If&lt;/font&gt; ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value &amp;gt; ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;MaxPedal&amp;quot;&lt;/font&gt;).Value &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;        ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;MaxPedal&amp;quot;&lt;/font&gt;).Value
      &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If
&lt;/font&gt;    &lt;font color="#0000ff"&gt;Else
&lt;/font&gt;      &lt;font color="#008000"&gt;' User isn't pressing the gas pedal =&amp;gt; Take of some speed (if moving):
&lt;/font&gt;      ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = _
        ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value - ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Brake&amp;quot;&lt;/font&gt;).Value
      &lt;font color="#0000ff"&gt;If&lt;/font&gt; ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value &amp;lt; 0 &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;        ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = 0
      &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If
&lt;/font&gt;    &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If
&lt;/font&gt;  &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;While

&lt;/font&gt;  &lt;font color="#008000"&gt;' Bring back the mouse cursor:
&lt;/font&gt;  ShowCursor 1
&lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub

Sub&lt;/font&gt; DrawCar(carID &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;String&lt;/font&gt;, _
  mouseLocation &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI, _
  mouseLocationPrevious &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI)

  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; diffX &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; diffY &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; Points(1 &lt;font color="#0000ff"&gt;To&lt;/font&gt; 5, 1 &lt;font color="#0000ff"&gt;To&lt;/font&gt; 2) &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Single

&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; carX &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; carY &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; carWidth &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; carHeight &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double

&lt;/font&gt;  carX = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarX&amp;quot;&lt;/font&gt;).Value
  carY = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarY&amp;quot;&lt;/font&gt;).Value
  carHeight = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarSize1&amp;quot;&lt;/font&gt;).Value
  carWidth = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarSize2&amp;quot;&lt;/font&gt;).Value

  &lt;font color="#008000"&gt;' Get input and store current values to sheet:
&lt;/font&gt;  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Xdiff&amp;quot;&lt;/font&gt;).Value = mouseLocationPrevious.x - mouseLocation.x
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Ydiff&amp;quot;&lt;/font&gt;).Value = mouseLocationPrevious.y - mouseLocation.y

  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SteeringWheel&amp;quot;&lt;/font&gt;).Value = _
    ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SteeringWheel&amp;quot;&lt;/font&gt;).Value + ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Xdiff2&amp;quot;&lt;/font&gt;).Value

  Points(1, 1) = carX - carWidth
  Points(1, 2) = carY + carHeight
  Points(2, 1) = carX + carWidth
  Points(2, 2) = carY + carHeight
  Points(3, 1) = carX + carWidth
  Points(3, 2) = carY - carHeight
  Points(4, 1) = carX - carWidth
  Points(4, 2) = carY - carHeight
  Points(5, 1) = Points(1, 1)
  Points(5, 2) = Points(1, 2)

  &lt;font color="#008000"&gt;' Draw this car:
&lt;/font&gt;  &lt;font color="#0000ff"&gt;On&lt;/font&gt; &lt;font color="#0000ff"&gt;Error&lt;/font&gt; &lt;font color="#0000ff"&gt;Resume&lt;/font&gt; &lt;font color="#0000ff"&gt;Next
&lt;/font&gt;  ActiveSheet.Shapes(carID).Delete
  Err.Clear &lt;font color="#008000"&gt;' Deleting Shape that doesn't exist =&amp;gt; Error
&lt;/font&gt;  ActiveSheet.Shapes.AddPolyline(Points).Name = carID
  ActiveSheet.Shapes(carID).Rotation = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SteeringWheel&amp;quot;&lt;/font&gt;).Value
&lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;I did my tests on Excel 2007 and I used &lt;em&gt;.xlsm&lt;/em&gt; format (Macro enabled). You can grab my file from &lt;a href="http://cid-64286c13c6bd5d77.skydrive.live.com/self.aspx/Julkinen/Blog%20files/Car%20Game.xlsm" target="_blank"&gt;here&lt;/a&gt;. 

  &lt;br /&gt;

  &lt;br /&gt;So if you want to open that example it gives you this security warning: 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Security warning" border="0" alt="Security warning" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_6.png" width="390" height="80" /&gt; 

  &lt;br /&gt;

  &lt;br /&gt;You need to click &lt;em&gt;Options...&lt;/em&gt; button just below ribbon. And then check &lt;em&gt;Enable this content&lt;/em&gt; and click &lt;em&gt;OK&lt;/em&gt;: 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Security Alert - Macro" border="0" alt="Security Alert - Macro" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_5.png" width="485" height="429" /&gt; 

  &lt;br /&gt;

  &lt;br /&gt;And if you want to run the game you can just press &lt;em&gt;Alt-F8&lt;/em&gt; and then hit enter (or click &lt;em&gt;Run&lt;/em&gt;): 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Macro" border="0" alt="Macro" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_9.png" width="375" height="358" /&gt;&lt;/p&gt;

&lt;p&gt;Well I have to say that I enjoyed playing with Excel. Maybe some day I’m going to use this for some serious thing or not &lt;strong&gt;:-)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Anyways... Happy hacking! 
  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9383568" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx">Fun</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Excel/default.aspx">Excel</category></item><item><title>Building Arcade Game Player (first step in long path)</title><link>http://blogs.msdn.com/jannemattila/archive/2008/01/29/building-arcade-game-player-first-step-in-long-path.aspx</link><pubDate>Tue, 29 Jan 2008 15:51:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7305266</guid><dc:creator>jannemattila</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/7305266.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=7305266</wfw:commentRss><description>&lt;p&gt;For few months I have been thinking of building arcade game player. I mean that I would create application that would then play some old classic arcade game (i.e. &lt;a href="http://en.wikipedia.org/wiki/The_Blues_Brothers_%28video_game%29" target="_blank"&gt;Blues Brothers&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Rick_Dangerous" target="_blank"&gt;Rick Dangerous&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Super_Mario_Bros." target="_blank"&gt;Super Mario Bros.&lt;/a&gt; etc.). Previously I have created applications that play puzzle games (i.e. &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/01/07/solving-small-puzzles-with-just-a-few-lines-of-code.aspx" target="_blank"&gt;Survo&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/10/29/minesweeper-goes-web.aspx" target="_blank"&gt;MineSweeper&lt;/a&gt;) and since puzzle games are fairly straightforward I thought I'll take a bit challenging task. And of course all actions between my "player application" and the actual game should be done through user interface and not by tweaking the process memory (this time :-). It's definitely challenging task. So I thought that I'll start with baby steps and try to first solve the graphical user interface challenge.&lt;/p&gt; &lt;p&gt;Currently I'm thinking following approach: I need to take "snapshots" out of the game and then find the differences between last snapshot and current snapshot. From that I could then analyze the differences and probably get location of the character and all the nasty enemies more easily than I could using other methods. But of course that's not enough... I need to do other image recognition things in order to sort out other issues. I'll worry those things later :-)&lt;/p&gt; &lt;p&gt;Okay let's create &lt;em&gt;Live Image Diff&lt;/em&gt; as I call it so that we can find the differences between frames. First step is to grab image from the foreground window. Here's code clip for that (I have this code in my &lt;em&gt;Win32Helper&lt;/em&gt; -class):&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;static&lt;/font&gt; &lt;font color="#0000ff"&gt;readonly&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; SRCCOPY = 0xCC0020;

[&lt;font color="#2b91af"&gt;StructLayout&lt;/font&gt;(&lt;font color="#2b91af"&gt;LayoutKind&lt;/font&gt;.Sequential)]
&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;struct&lt;/font&gt; &lt;font color="#2b91af"&gt;RECT
&lt;/font&gt;{
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; left;
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; top;
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; right;
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; bottom;
}

[&lt;font color="#2b91af"&gt;DllImport&lt;/font&gt;(&lt;font color="#a31515"&gt;"user32.dll"&lt;/font&gt;)]
&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;static&lt;/font&gt; &lt;font color="#0000ff"&gt;extern&lt;/font&gt; &lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; GetForegroundWindow();

[&lt;font color="#2b91af"&gt;DllImport&lt;/font&gt;(&lt;font color="#a31515"&gt;"user32.dll"&lt;/font&gt;)]
&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;static&lt;/font&gt; &lt;font color="#0000ff"&gt;extern&lt;/font&gt; &lt;font color="#0000ff"&gt;bool&lt;/font&gt; GetClientRect(&lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; hWnd, &lt;font color="#0000ff"&gt;ref&lt;/font&gt; &lt;font color="#2b91af"&gt;RECT&lt;/font&gt; lpRect);

[&lt;font color="#2b91af"&gt;DllImport&lt;/font&gt;(&lt;font color="#a31515"&gt;"gdi32.dll"&lt;/font&gt;)]
&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;static&lt;/font&gt; &lt;font color="#0000ff"&gt;extern&lt;/font&gt; &lt;font color="#0000ff"&gt;bool&lt;/font&gt; BitBlt(
  &lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; hdcDest, &lt;font color="#008000"&gt;// handle to destination DC
&lt;/font&gt;  &lt;font color="#0000ff"&gt;int&lt;/font&gt; nXDest,   &lt;font color="#008000"&gt;// x-coord of destination upper-left corner
&lt;/font&gt;  &lt;font color="#0000ff"&gt;int&lt;/font&gt; nYDest,   &lt;font color="#008000"&gt;// y-coord of destination upper-left corner
&lt;/font&gt;  &lt;font color="#0000ff"&gt;int&lt;/font&gt; nWidth,   &lt;font color="#008000"&gt;// width of destination rectangle
&lt;/font&gt;  &lt;font color="#0000ff"&gt;int&lt;/font&gt; nHeight,  &lt;font color="#008000"&gt;// height of destination rectangle
&lt;/font&gt;  &lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; hdcSrc, &lt;font color="#008000"&gt;// handle to source DC
&lt;/font&gt;  &lt;font color="#0000ff"&gt;int&lt;/font&gt; nXSrc,   &lt;font color="#008000"&gt;// x-coordinate of source upper-left corner
&lt;/font&gt;  &lt;font color="#0000ff"&gt;int&lt;/font&gt; nYSrc,   &lt;font color="#008000"&gt;// y-coordinate of source upper-left corner
&lt;/font&gt;  System.&lt;font color="#2b91af"&gt;Int32&lt;/font&gt; dwRop &lt;font color="#008000"&gt;// raster operation code
&lt;/font&gt;  );

&lt;font color="#0000ff"&gt;static&lt;/font&gt; &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#2b91af"&gt;Bitmap&lt;/font&gt; GetSnapShot()
{
  &lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; hWnd = GetForegroundWindow();
  &lt;font color="#2b91af"&gt;RECT&lt;/font&gt; rect = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;RECT&lt;/font&gt;();
  &lt;font color="#0000ff"&gt;if&lt;/font&gt; (GetClientRect(hWnd, &lt;font color="#0000ff"&gt;ref&lt;/font&gt; rect) == &lt;font color="#0000ff"&gt;true&lt;/font&gt;)
  {
    &lt;font color="#0000ff"&gt;int&lt;/font&gt; width = rect.right - rect.left;
    &lt;font color="#0000ff"&gt;int&lt;/font&gt; height = rect.bottom - rect.top;
    &lt;font color="#2b91af"&gt;Graphics&lt;/font&gt; graphWindow = &lt;font color="#2b91af"&gt;Graphics&lt;/font&gt;.FromHwnd(hWnd);
    &lt;font color="#2b91af"&gt;Bitmap&lt;/font&gt; bitmap = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;Bitmap&lt;/font&gt;(width, height, graphWindow);
    &lt;font color="#2b91af"&gt;Graphics&lt;/font&gt; graphFile = &lt;font color="#2b91af"&gt;Graphics&lt;/font&gt;.FromImage(bitmap);
    &lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; dcWindow = graphWindow.GetHdc();
    &lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; dcFile = graphFile.GetHdc();
    BitBlt(dcFile, 0, 0, width, height, dcWindow, 0, 0, SRCCOPY);
    graphWindow.ReleaseHdc(dcWindow);
    graphFile.ReleaseHdc(dcFile);

    &lt;font color="#0000ff"&gt;return&lt;/font&gt; bitmap;
  }

  &lt;font color="#0000ff"&gt;return&lt;/font&gt; &lt;font color="#0000ff"&gt;null&lt;/font&gt;;
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;So now we have image (=.NET Bitmap) of the foreground application. &lt;/p&gt;
&lt;p&gt;Now I want to compare previous image to the current snapshot and mark everything that has been changed with red color. Here's clip that does that:&lt;/p&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Drawing.Imaging;
&lt;font color="#008000"&gt;// ...

&lt;/font&gt;&lt;font color="#2b91af"&gt;Bitmap&lt;/font&gt; previousSnapshot;
&lt;font color="#2b91af"&gt;Bitmap&lt;/font&gt; currentSnapshot;
&lt;font color="#2b91af"&gt;BitmapData&lt;/font&gt; currentSnapshotCleanData;
&lt;font color="#2b91af"&gt;Rectangle&lt;/font&gt; rectangle;

 &lt;font color="#008000"&gt;//...
&lt;/font&gt;previousSnapshot = currentSnapshot;
currentSnapshot = &lt;font color="#2b91af"&gt;Win32Helper&lt;/font&gt;.GetSnapShot();
&lt;font color="#0000ff"&gt;if&lt;/font&gt; (currentSnapshot == &lt;font color="#0000ff"&gt;null&lt;/font&gt;)
{
  &lt;font color="#0000ff"&gt;return&lt;/font&gt;;
}
&lt;font color="#0000ff"&gt;if&lt;/font&gt; (previousSnapshot == &lt;font color="#0000ff"&gt;null&lt;/font&gt; || 
    previousSnapshot.Width != currentSnapshot.Width || 
    previousSnapshot.Height != currentSnapshot.Height)
{
  previousSnapshot = currentSnapshot.Clone() &lt;font color="#0000ff"&gt;as&lt;/font&gt; &lt;font color="#2b91af"&gt;Bitmap&lt;/font&gt;;
  rectangle = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;Rectangle&lt;/font&gt;(0, 0, currentSnapshot.Width, currentSnapshot.Height);
}
 &lt;font color="#008000"&gt;//...

&lt;/font&gt;&lt;font color="#2b91af"&gt;BitmapData&lt;/font&gt; previousSnapshotData = previousSnapshot.LockBits(
  rectangle, &lt;font color="#2b91af"&gt;ImageLockMode&lt;/font&gt;.ReadWrite, &lt;font color="#2b91af"&gt;PixelFormat&lt;/font&gt;.Format32bppArgb);
&lt;font color="#2b91af"&gt;BitmapData&lt;/font&gt; currentSnapshotData = currentSnapshot.LockBits(
  rectangle, &lt;font color="#2b91af"&gt;ImageLockMode&lt;/font&gt;.ReadOnly, &lt;font color="#2b91af"&gt;PixelFormat&lt;/font&gt;.Format32bppArgb);
currentSnapshotCleanData = currentSnapshotData;
&lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; ptrPreviousSnapshot = previousSnapshotData.Scan0;
&lt;font color="#2b91af"&gt;IntPtr&lt;/font&gt; ptrCurrentSnapshot = currentSnapshotData.Scan0;

&lt;font color="#0000ff"&gt;int&lt;/font&gt; bufferSize = previousSnapshotData.Stride * previousSnapshotData.Height - 1;
&lt;font color="#0000ff"&gt;byte&lt;/font&gt;[] previousSnapshotBuffer = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#0000ff"&gt;byte&lt;/font&gt;[bufferSize];
&lt;font color="#0000ff"&gt;byte&lt;/font&gt;[] currentSnapshotBuffer = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#0000ff"&gt;byte&lt;/font&gt;[bufferSize];

&lt;font color="#2b91af"&gt;Marshal&lt;/font&gt;.Copy(ptrPreviousSnapshot, previousSnapshotBuffer, 0, previousSnapshotBuffer.Length);
&lt;font color="#2b91af"&gt;Marshal&lt;/font&gt;.Copy(ptrCurrentSnapshot, currentSnapshotBuffer, 0, currentSnapshotBuffer.Length);

&lt;font color="#0000ff"&gt;for&lt;/font&gt; (&lt;font color="#0000ff"&gt;int&lt;/font&gt; x = 0; x &amp;lt; bufferSize - 4; x += 4)
{
  &lt;font color="#0000ff"&gt;if&lt;/font&gt; (previousSnapshotBuffer[x] != currentSnapshotBuffer[x] ||
      previousSnapshotBuffer[x + 1] != currentSnapshotBuffer[x + 1] ||
      previousSnapshotBuffer[x + 2] != currentSnapshotBuffer[x + 2] ||
      previousSnapshotBuffer[x + 3] != currentSnapshotBuffer[x + 3])
  {
    &lt;font color="#008000"&gt;// This has been changed! Let's make it red:
&lt;/font&gt;    previousSnapshotBuffer[x] = 0;
    previousSnapshotBuffer[x + 1] = 0;
    previousSnapshotBuffer[x + 2] = 0xff;
    previousSnapshotBuffer[x + 3] = 0xff;
  }
}
&lt;font color="#2b91af"&gt;Marshal&lt;/font&gt;.Copy(previousSnapshotBuffer, 0, ptrPreviousSnapshot, previousSnapshotBuffer.Length);

previousSnapshot.UnlockBits(previousSnapshotData);
currentSnapshot.UnlockBits(currentSnapshotData);

&lt;font color="#008000"&gt;// Now draw "previousSnapshot" to the screen:
&lt;/font&gt;pictureBoxAtTheForm.Image = previousSnapshot;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;On lines 10 to 22 I'll just grab current snapshot and try to make sure that my snapshots stay in sync. I need to do some checks since user actually could have changed the foreground window and my snapshots can be from different windows and therefore different sizes. If something goes wrong in this bad things will happen later.&lt;/p&gt;
&lt;p&gt;On lines 40 to 53 I'll just check that is pixel at the current snapshot different from the one in previous snapshot. And if that is the case then I'll just fill the value to the buffer so that it makes the pixel red. I don't even try to make this code portable to different pixelformats etc. It's okay if it just runs on my machine with my display settings :-)&lt;/p&gt;
&lt;p&gt;But the coolest thing is yet to come. I used method described in &lt;a href="http://blogs.msdn.com/lezamax/archive/2008/01/11/how-to-silverlight-streaming.aspx" target="_blank"&gt;here&lt;/a&gt; to create Silverlight screencast from my application. I used IE in my demonstration of &lt;em&gt;Live Image Diff&lt;/em&gt;. I browsed to my blog and then selected some text etc. in order to make changes to the screen. My application is running at the lower right corner and it displays differences in the user interface. Here is screenshot from that:&lt;/p&gt;&lt;a href="http://blogs.msdn.com/photos/jannemattila/images/7305180/original.aspx" target="_blank"&gt;&lt;img alt="" src="http://blogs.msdn.com/photos/jannemattila/images/7305180/640x403.aspx" border="0"&gt;&lt;/a&gt; 
&lt;p&gt;&lt;a title="Live Image Diff" href="http://silverlight.services.live.com/invoke/48523/LiveImageDiff/iframe.html" target="_blank"&gt;&lt;strong&gt;&lt;font size="4"&gt;Now you can see my application in action: Live Image Diff&lt;/font&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;font size="4"&gt;! &lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;What are next steps in this one? Well I don't know... so if you have ideas how to proceed on this challenge then drop me &lt;a href="http://blogs.msdn.com/jannemattila/contact.aspx" target="_blank"&gt;email&lt;/a&gt; or post comment to this post. I would like to here your ideas.&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7305266" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx">Fun</category></item><item><title>Minesweeper goes web</title><link>http://blogs.msdn.com/jannemattila/archive/2007/10/29/minesweeper-goes-web.aspx</link><pubDate>Mon, 29 Oct 2007 21:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5769164</guid><dc:creator>jannemattila</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/5769164.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=5769164</wfw:commentRss><description>&lt;p&gt;&lt;strong&gt;Disclaimer/Important notice:&lt;/strong&gt; I sometimes go crazy with my favorite programming tools. I use my imagination to do things and try to forget all the rules that I normally would keep in mind when developing applications. This post is one of those moments when I got loose. So you don't probably want to take any advices/ideas from this into your development. Consider it only as having fun with programming tools. Forget everything about security, scalability, sanity etc.&lt;/p&gt; &lt;p&gt;3,5 years ago I was bored and I &lt;a href="http://blogs.msdn.com/jannemattila/attachment/5769164.ashx" target="_blank"&gt;created Minesweeper solver&lt;/a&gt;. It was just Windows forms application that launched minesweeper and then started playing it. End result of that was game solved in 1 second in Expert level (but you needed to change the priority to get to that). Okay... now I got crazy idea again. I wanted to test if I could create browser playable minesweeper... but I wanted to use the minesweeper that comes with windows to do that. I didn't want to create minesweeper itself I just wanted to create "wrapper" that could make it possible to play it using browser. Sounds weird I know! Here's what I did... I start by telling the plan that I had in my head before starting:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Start Minesweeper.exe  &lt;li&gt;Grab picture of the UI  &lt;li&gt;Place picture in my web form (=imagebutton)  &lt;li&gt;When user clicks the image then those clicks will be transferred to the actual application  &lt;li&gt;Go back to phase 2. (and enjoy illusion of playing minesweeper in browser!)&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;And of course I needed some kind of automatic refresh too so that I could see the fancy explosion effects from minesweeper (since I used minesweeper from Windows Vista).&lt;/p&gt; &lt;p&gt;I started my journey by creating normal ASP.NET project and designed such a lovely user interface:&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:9e41c9b8-92d9-4a59-ac6f-966bdeed1d7d" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5766028/original.aspx" alt="" style="width:304px; height:262px;" /&gt;&lt;/div&gt; &lt;p&gt;As you can probably see I used AJAX controls so that my whole web page wouldn't refresh when I click the image. &lt;/p&gt; &lt;p&gt;Then I started creating logic to handle the minesweeper process, screen captures, clicks, keyboard presses etc. Since I have done few game solvers and other weird tools to play with processes... I was able to get minesweeper screen to my browser pretty easily:&lt;/p&gt;&lt;a href="http://blogs.msdn.com/photos/jannemattila/images/5766043/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5766043/395x480.aspx"&gt;&lt;/a&gt;  &lt;p&gt;But then I had some difficulties with passing the mouse clicks to the minesweeper. It seems that minesweeper has changed so much since from Windows XP that my old code turned out to be useless... but no worries... I just created a set of new code :-) Finally after a lot of tweaking I was able to pass user interface interactivity to the windows application as I wanted. I didn't make it as good as in my previous solver... I just made it good enough to proof my point. And I did proof my point since I'm able to play minesweeper from browser. Here is the updated windows application that has taken my activity from through browser:&lt;/p&gt;&lt;a href="http://blogs.msdn.com/photos/jannemattila/images/5768433/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5768433/447x480.aspx"&gt;&lt;/a&gt;  &lt;p&gt;Of course this kind of method could be used with other applications too... consider running Internet Explorer inside your Internet Explorer (or something similar)! That could be fun thing to do... but I'll leave that to you. &lt;/p&gt; &lt;p&gt;If you think that this story is now over... it's not :-)&amp;nbsp; But I'll continue this one in another post later. It's going to be fun too!&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5769164" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/jannemattila/attachment/5769164.ashx" length="152932" type="application/pdf" /><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx">Fun</category></item></channel></rss>