<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Windows Embedded Cookbook</title>
        <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/Default.aspx</link>
        <description>Valter Minute's blog</description>
        <language>en-US</language>
        <copyright>Valter Minute</copyright>
        <managingEditor>valter.minute@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Windows Embedded Cookbook</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Silverlight for Windows Embedded tutorial (step 3)</title>
            <category>Windows CE</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/18/silverlight-for-windows-embedded-tutorial-step-3.aspx</link>
            <description>&lt;p&gt;After the first two tutorial steps were published on this blog I received many requests about using images inside a Silverlight for Windows Embedded application. This is the topic of this post.&lt;br /&gt;
To be able to load and use image files (jpegs,bmps,gifs) inside your application you should include the imaging library components in your OSDesign.&lt;br /&gt;
Those component are not included automatically when you add the XAML runtime (the runtime can run also without the imaging components, it will simply not load your images!).&lt;br /&gt;
To display an image inside your application user interface you have to use the image control of Silverlight.&lt;br /&gt;
This is a very simple XAML file that includes just an Image object and a button:&lt;/p&gt;
&lt;pre&gt;

&lt;span style="background-color: rgb(192, 192, 192);"&gt;&amp;lt;UserControl&lt;br /&gt;    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;br /&gt;    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&lt;br /&gt;    x:Class="ImgTest.Page"&lt;br /&gt;    Width="640" Height="480" x:Name="ImagePage"&amp;gt; &lt;br /&gt;    &amp;lt;Grid x:Name="LayoutRoot" Background="White"&amp;gt;&lt;br /&gt;        &amp;lt;Image Margin="17,25,25,103" x:Name="MyImage" Source="\Windows\img01.JPG"/&amp;gt;&lt;br /&gt;        &amp;lt;Button Height="49" Margin="259,0,253,28" VerticalAlignment="Bottom" Content="Button" x:Name="MyButton" Click="OnClick"/&amp;gt;&lt;br /&gt;    &amp;lt;/Grid&amp;gt;&lt;br /&gt;&amp;lt;/UserControl&amp;gt;&lt;/span&gt;


&lt;/pre&gt;
&lt;p&gt;The image object is named "MyImage" and the button is named "MyButton".&lt;/p&gt;
&lt;p&gt;We also have an OnClick event handler for the Click event of the button.&lt;/p&gt;
&lt;p&gt;We can create a new Win32 application inside platform builder.&lt;/p&gt;
&lt;p&gt;Using the XAML2CPP we can generate some code for us.&lt;/p&gt;
&lt;p&gt;We will just have to include "XAML2CPP.h" inside your main C++ source file to use the code that XAML2CPP created for us:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "XAML2CPP.h" &lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;We also have to include "XAML2CPP.rc" inside the rc file of our application to include the XAML code as a resource inside our application.&lt;/p&gt;
&lt;p&gt;XAML2CPP has created a base class that we can use to implement our own class and handle the OnClick event:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;class ImagePage : public TImagePage&amp;lt;ImagePage&amp;gt;  {  ...  }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;&lt;br /&gt;
&lt;/span&gt;In this sample we will just swap two images inside the image control each time you click on the button.&lt;br /&gt;
We have to declare a state flag (to be able to swap images) and two IXRBitmapImagePtr objects to store our bitmaps.&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    bool state;          IXRBitmapImagePtr    img01;     IXRBitmapImagePtr    img02; &lt;/span&gt;  
&lt;/pre&gt;
&lt;p&gt;A very simple constructor will reset the state:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    ImagePage()     {          state=false;          }  &lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;The main initialization will be performed inside our Init method (it's not a good idea to put this kind of initialization code inside the constructor because some API calls may fail and you don't have a way to return an error code from a C++ constructor).&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    virtual HRESULT Init(HINSTANCE hinstance,IXRApplication* app)          {             ...     } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Inside our Init method we have to call the Init method of our base class (declared by XAML2CPP), and check its return code for errors:&lt;/p&gt;
&lt;pre&gt;
 &lt;span style="background-color: rgb(192, 192, 192);"&gt;       HRESULT retcode;                    if (FAILED(retcode=TImagePage&amp;lt;ImagePage&amp;gt;::Init(hinstance,app)))              return retcode;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;We declared two IXRBitmapImagePtr objects but we still haven't initialized them.&lt;br /&gt;
To create a Silverlight for Windows Embedded object we should use the CreateObject method of the IXRApplication object:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        if (FAILED(retcode=app-&amp;gt;CreateObject(IID_IXRBitmapImage,&amp;amp;img01)))              return retcode;         if (FAILED(retcode=app-&amp;gt;CreateObject(IID_IXRBitmapImage,&amp;amp;img02)))              return retcode;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;The we can load the bitmaps and store them inside the IXRBitmapImagePtr objects:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        if (FAILED(retcode=img01-&amp;gt;SetUriSource(TEXT("\\Windows\\img01.jpg"))))                           return retcode;         if (FAILED(retcode=img02-&amp;gt;SetUriSource(TEXT("\\Windows\\img02.jpg"))))              return retcode;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;In the OnClick event handler we just have to swap the image displayed by the MyImage object and change the state flag:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)      {                    HRESULT retcode;                    if (FAILED(retcode=MyImage-&amp;gt;SetSource(state?img01:img02)))                          return retcode;                   state=state?false:true;                  return S_OK;           }&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;The main function of this sample is quite simple and it's not much different for the WinMain functions of the previous samples (just the class name changes):&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;int WINAPI WinMain(HINSTANCE hInstance,                       HINSTANCE hPrevInstance,                       LPTSTR     lpCmdLine,                       int       nCmdShow)  {      if (!XamlRuntimeInitialize())              return -1;          HRESULT retcode;            IXRApplicationPtr app;          if (FAILED(retcode=GetXRApplicationInstance(&amp;amp;app)))          return -1;        ImagePage imagepage;        if (FAILED(imagepage.Init(hInstance,app)))          return -1;        UINT exitcode;        if (FAILED(imagepage.GetVisualHost()-&amp;gt;StartDialog(&amp;amp;exitcode)))          return -1;        return 0;   }&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;You can download the full source code of this sample here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/ImageTest.zip"&gt;http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/ImageTest.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136401"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136401" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/136401.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/18/silverlight-for-windows-embedded-tutorial-step-3.aspx</guid>
            <pubDate>Wed, 18 Nov 2009 21:54:47 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/136401.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/18/silverlight-for-windows-embedded-tutorial-step-3.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/136401.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/136401.aspx</trackback:ping>
        </item>
        <item>
            <title>XAML2CPP ver. 1.0.0.1</title>
            <category>Windows CE</category>
            <category>XAML2CPP</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/18/xaml2cpp-ver.-1.0.0.1.aspx</link>
            <description>&lt;p&gt;I just found (and fixed) some bugs inside the XAML2CPP tool.&lt;/p&gt;
&lt;p&gt;You can download the new release from here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/XAML2CPP.zip"&gt;http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/XAML2CPP.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Changes history:&lt;/p&gt;
&lt;p&gt;ver 1.0.0.1&lt;/p&gt;
&lt;p&gt;- the application version is inserted in the generate files and written on the console&lt;/p&gt;
&lt;p&gt;- the x:Name tag of the user control is used as class name instead of the XAML file name. If no x:Name attribute is specified the XAML file name will be used.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136399"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136399" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/136399.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/18/xaml2cpp-ver.-1.0.0.1.aspx</guid>
            <pubDate>Wed, 18 Nov 2009 21:37:02 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/136399.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/18/xaml2cpp-ver.-1.0.0.1.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/136399.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/136399.aspx</trackback:ping>
        </item>
        <item>
            <title>XAML2CPP</title>
            <category>Windows CE</category>
            <category>XAML2CPP</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/11/xaml2cpp.aspx</link>
            <description>&lt;p&gt;&lt;img height="402" width="640" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/pictures/DSC00091 (Small).JPG" alt="" /&gt;&lt;br /&gt;
Before I start to explain the topic of this post I should confess one of my many defects: I'm very lazy.&lt;br /&gt;
Someone may have noticed that from the update rate of this blog, but I really like to avoid as much work as I can.&lt;br /&gt;
I also really like to experiment new technologies and embedded devices, and that's bad for a lazy guy because that means having to write some code...&lt;br /&gt;
While experimenting with Silverlight for Windows Embedded I found myself trying to write some more complex samples to continue my own tutorial (it's idle, but I told you that I'm lazy...) but I hate to write all the "boilerplate" code required to connect C++ objects to XAML code and register event handlers on those objects.&lt;br /&gt;
Being as lazy as I am I decided that writing a simple tool once it's better than re-writing more or less the same code over and over again, so I wrote a small tool that without much fantasy (I'm lazy also about coming out with fancy names for tools!) I called XAML2CPP.&lt;br /&gt;
XAML2CPP is a very simple command line utility that parses a XAML file and generates some C++ code for you.&lt;br /&gt;
It generate a class for each XAML file (I suppose that you have one user control per file so that makes sense) with all the code needed to access the objects inside your XAML and to invoke event handlers when an event is generated by the runtime.&lt;br /&gt;
It also generates a "cumulative" include file (to avoid to include each class file in my sources, you know...I'm lazy) and resource definitions (to avoid to define your own XAML resources).&lt;br /&gt;
It generates code only for objects and event handlers that have a name (memory is not an infinite resource, as our colleagues programming desktop application may believe, and declaring objects and event handler for everything looks like a waste to me).&lt;br /&gt;
Let's start with an easy sample (I'm too lazy to write a complex one!):&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
&amp;lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SimpleApp.Page" &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
Width="640" Height="480"&amp;gt;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &amp;lt;Grid x:Name="LayoutRoot" Background="White"&amp;gt;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        &amp;lt;Button Height="87" Margin="189,106,209,0" VerticalAlignment="Top" Content="Button" 
x:Name="MyButton" Click="OnClick"/&amp;gt;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &amp;lt;/Grid&amp;gt;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
&amp;lt;/UserControl&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
As you can see this is more or less the same XAML code we used in the first tutorial step (being lazy it's easier to modify an existing sample than creating a new one!), I just specified "OnClick" as name for the Click event handler of the MyButton object.&lt;br /&gt;
If we run XAML2CPP using this command line syntax:&lt;br /&gt;
XAML2CPP Page.XAML&lt;br /&gt;
It will generate five source files:&lt;br /&gt;
XAML2CPP.rc&lt;br /&gt;
XAML2CPP.h&lt;br /&gt;
XAML2CPPBase.h&lt;br /&gt;
XAML2CPP_res.h&lt;br /&gt;
T_Page.h&lt;br /&gt;
I'm lazy, but my tools aren't: five files out of a single one!&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Never change the code inside those files, if your run XAML2CPP again it will overwrite them and your modifications will be lost forever (and even if you are not lazy like me, rewriting the same code over and over again after it has been overwritten don't look so smart).&lt;/span&gt;&lt;br /&gt;
I know that modifications are not lost forever because you are a good programmer and you have multiple backups of all your sources... but that doesn't change the concept: &lt;span style="font-weight: bold;"&gt;never modify XAML2CPP generated code&lt;/span&gt;!&lt;br /&gt;
And also never use for your own files the same file names that may be generated by XAML2CPP, of course.&lt;br /&gt;
Let's see what those files contains and how you can integrate them in your Silverlight for Windows Embedded  application.&lt;br /&gt;
XAML2CPP.rc includes all the resource definitions that we need to include our XAML inside the executable file resources.&lt;br /&gt;
In this case it will include only our Page.XAML file (you can run XAML2CPP with multiple input file names or with wildcards to generate multiple XAML resources).&lt;br /&gt;
Those are the contents of XAML2CPP.rc:&lt;br /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;XAML_RESOURCE_Page   XAML ".\Page.xaml"&lt;/span&gt;&lt;br /&gt;
Pretty minimal, isn't it? But this has saved writing at least one row of code. Since I had to write "xaml2cpp page.xaml" on the command line this hasn't saved too much time... let's see what's inside other files.&lt;br /&gt;
XAML2CPP_res.h includes the definitions of the resources that XAML2CPP brought inside your executable.&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
/*&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
This file has been generated by XAML2CPP tool.&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
Modifications to this source code may be overwritten without warning when the XAML2CPP tool is executed.&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
XAML2CPP (c) 2009 by Valter Minute (valter.minute@gmail.com)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
This code is provided as is and it's generated automatically. It's up to the developer to check that it works as expected.&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
*/&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
/*&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
This file includes all the resource identifiers of the XAML files embedded inside the application resources&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
*/&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
#ifndef XAML2CPP_RES_H&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
#define XAML2CPP_RES_H&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
#define IDR_XAML_Page TEXT("XAML_RESOURCE_Page")&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
#endif //XAML2CPP_RES_H&lt;/pre&gt;
&lt;p&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
Four rows of code, not including the copyright. Not bad!&lt;br /&gt;
XAML2CPPBase.h will have always the same content, it's the definition of a class (XAML2CPPBase) that is used as base class for all the XAML2CPP generated classes. Even if that's not strictly necessary, the file is generated by XAML2CPP each time it's run. In this way some modifications of the base classes introduced by a new release of the tool will not require re-distribution of a new header and udating it inside all the project using it (sometimes being lazy may prevent some maintenance nightmare).&lt;br /&gt;
This will allow a single declaration of some members and methods that are common between all those objects.&lt;br /&gt;
After the copyright you'll find the base class declaration:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
class XAML2CPPBase&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
{&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
...&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
}&lt;/pre&gt;
&lt;p&gt;In this class we will find some XAML runtime objects:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // Pointer to the visual host&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRVisualHostPtr vhost;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // Pointer to the root of the XAML visual tree&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRFrameworkElementPtr root;&lt;/pre&gt;
&lt;p&gt;and some methods to access them (they are declared as protected inside our base class):&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // returns the visual host&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRVisualHost* GetVisualHost() { return vhost; }&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // returns the visual tree root&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRFrameworkElement* GetRoot() { return root; }&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
We also find two string pointers and a constructor to inizialize them:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // Pointer to the page title&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    TCHAR* windowtitle;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // Pointer to the resource name&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    TCHAR* xamlresourceid;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
public:&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    XAML2CPPBase(TCHAR* windowtitle,TCHAR* xamlresourceid)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    {&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
      this-&amp;gt;windowtitle=windowtitle;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
      this-&amp;gt;xamlresourceid=xamlresourceid;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    }&lt;/pre&gt;
&lt;p&gt;Those pointers will be used to set the window title for our visual host (you may not need to set a title if your window has no title bar) and the resource id of the XAML associated with a specific instance of a XAML2CPPBase derived class.&lt;br /&gt;
Those field are used in the two function that setup window creation parameters and XAML loading method:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    // Initializes Windows parameters, can be overridden in the user class to change its appearance&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    virtual void InitWindowParms(XRWindowCreateParams* wp)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    {&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;            wp-&amp;amp;gt;Style       = WS_OVERLAPPED;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;            wp-&amp;amp;gt;pTitle      = windowtitle;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;            wp-&amp;amp;gt;Left        = 0;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;            wp-&amp;amp;gt;Top         = 0;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    }&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;

&lt;span style="background-color: rgb(192, 192, 192);"&gt;    // Set the XAML source path. By default loads the XAML that is included in the resources script&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    virtual void SetXAMLSource(HINSTANCE hInstance,XRXamlSource* xamlsrc)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    {&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        xamlsrc-&amp;gt;SetResource(hInstance,TEXT("XAML"),xamlresourceid);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre&gt;
 &lt;/pre&gt;
&lt;p&gt;In this way we will create an overlapped (top level) window with the title we passed to the constructor and we will load our XAML from the resource specified by the other constructor parameter.&lt;br /&gt;
If we want to change this behavior we may override InitWindowParms or SetXAMLSource method in our derived class. Lazy people love C++ inheritance!&lt;br /&gt;
&lt;br /&gt;
Those method are called by the CreateHost method, the method that initializes our visual host and loads our XAML:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // create the visual host and loads the XAML&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    virtual HRESULT CreateHost(HINSTANCE hInstance,IXRApplication* app)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    {&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        HRESULT retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        XRWindowCreateParams wp;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        ZeroMemory(&amp;amp;amp;wp, sizeof(XRWindowCreateParams));&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        InitWindowParms(&amp;amp;amp;wp);&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        XRXamlSource xamlsrc;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        SetXAMLSource(hInstance,&amp;amp;amp;xamlsrc);&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        if (FAILED(retcode=app-&amp;amp;gt;CreateHostFromXaml(&amp;amp;amp;xamlsrc, &amp;amp;amp;wp, &amp;amp;amp;vhost)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            return retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        if (FAILED(retcode=vhost-&amp;amp;gt;GetRootElement(&amp;amp;amp;root)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            return retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return S_OK;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    } &lt;/pre&gt;
&lt;p&gt;This method is also marked as virtual so you may override it if you need to perform some particular initialization steps inside your own class. Usually overriding InitWindowParms and SetXAMLSource should be enough but a virtual function call during initialization won't impact performances so much, so I preferred to leave more room for customization in this case.&lt;br /&gt;
If you override CreateHost remember that the rest of the code expects root and vhost smart pointers to be initialized after this method has been called.&lt;br /&gt;
&lt;br /&gt;
Now let's see what's inside XAML2CPP.h.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;/*&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;This file has been generated by XAML2CPP tool.&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;Modifications to this source code may be overwritten without warning when the XAML2CPP tool is executed.&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;XAML2CPP (c) 2009 by Valter Minute (valter.minute@gmail.com)&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;This code is provided as is and it's generated automatically. It's up to the developer to check that it works as expected.&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;*/&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;/*&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;This header includes all the classes generated by XAML2CPP the last time it was executed.&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;*/&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;#ifndef XAML2CPP_H&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;#define XAML2CPP_H&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "T_Page.h"&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;#endif //XAML2CPP_H&lt;/span&gt;&lt;br style="background-color: rgb(192, 192, 192);" /&gt;
&lt;br /&gt;
In this file you'll find an #include directive for each class that has been generated by XAML2CPP from the XAML files it processed. This will allow you to simply include "XAML2CPP.h" in each source file where you need to access one of the classes generated by the tool. Including it in your pre-compiled header file (usually stdafx.h) could save some build time.&lt;br /&gt;
Now let's see in detail what's inside T_Page.h.&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#ifndef Page_TEMPLATE_HEADER_FILE_H&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#define Page_TEMPLATE_HEADER_FILE_H&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "windows.h"&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "pwinuser.h"&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "xamlruntime.h"&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "xrdelegate.h"&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "xrptr.h"&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "XAML2CPP_res.h"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;After an #ifdef used to avoid multiple inclusion of this file you'll find a list of includes for all the header  files needed to build a Silverlight for Windows Embedded  application. This will save some time and some time spent understanding build errors.&lt;br /&gt;
&lt;br /&gt;
Then we find a template declaration:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;/*&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;class generated by XAML2CPP from .\Page.xaml&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;*/&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: monospace;"&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;template &amp;lt;class X&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: monospace;"&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt; class TPage : public XAML2CPPBase&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: monospace;"&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt; {&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: monospace;"&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt; ...&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: monospace;"&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;
 &lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;I used templates to be able to link event handlers directly to your own code and not to some code generated by the tool. &lt;br /&gt;
I may have used a function invoking a pure virtual method inside my class and let you implement your own method in a derived class but that may have a (small) impact on performances.&lt;br /&gt;
We will see how we can derive our own class from the one generated by XAML2CPP in a short time. Right now, let's focus on the TPage class code.&lt;br /&gt;
We have a constructor that takes two (optional) parameters and passes them to the XAML2CPPBase constructor. In this way you can change the title of your window and XAML resource id or use the default ones generated by the tool.&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;public:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    TPage(TCHAR* title=TEXT("Page"),TCHAR* xamlid=IDR_XAML_Page) : XAML2CPPBase(title,xamlid)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    {&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The we have two smart pointers:&lt;br /&gt;
&lt;br /&gt;
protected:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // XAML defined objects (declared as smart pointers)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRGridPtr LayoutRoot;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRButtonPtr MyButton;&lt;/pre&gt;
&lt;p&gt;The tool generates them using the names you specified in the x:Name attribute of your XAML code (or that you set in the properties window inside Expression Blend, of course).&lt;br /&gt;
For each object with an x:Name attribute in your XAML you'll have an object, no need to declare them! Great for lazy people and also great to avoid that a designer changes the name of an object without informing you. In this way you can re-generate code and then you'll have to replace the old name with the new one but you'll discover that at build time, not when you run you application.&lt;br /&gt;
Those smart pointer need to be bound to XAML objects and that's done inside the BindObjects method:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    // binds objects smart pointers to objects created by the runtime&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    virtual HRESULT BindObjects()&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    {    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        HRESULT retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        if (FAILED(retcode=root-&amp;gt;FindName(L"LayoutRoot",&amp;amp;LayoutRoot))) &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            return retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
                       &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        if (FAILED(retcode=root-&amp;gt;FindName(L"MyButton",&amp;amp;MyButton))) &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            return retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
                       &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return S_OK;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    }&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
The code of this method looks boring and repetitive... but you don't have to write it, XAML2CPP has generated it for you. And no chances to type the wrong name or forget something during cut&amp;amp;paste (I know that you write this kind of code using cut&amp;amp;paste, like I do!).&lt;br /&gt;
Now we have to bind our event handlers to the objects, and that's exactly what the BindEventHandlers method does:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;// binds event handlers to template class member functions   &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    // should be called after BindObjects&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    virtual HRESULT BindEventHandlers()&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    {&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        HRESULT retcode;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        //declare your own event handler as &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        // HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        IXRDelegate&amp;lt;XRMouseButtonEventArgs&amp;gt;* OnClickDelegate;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;

&lt;span style="background-color: rgb(192, 192, 192);"&gt;        retcode=CreateDelegate&amp;lt;X,XRMouseButtonEventArgs&amp;gt;((X*)this,&amp;amp;X::OnClick,&amp;amp;OnClickDelegate);&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        if (FAILED(retcode))        &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;          return retcode;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;            &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        if (FAILED(retcode=MyButton-&amp;gt;AddClickEventHandler(OnClickDelegate)))&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;            return retcode;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        OnClickDelegate-&amp;gt;Release();&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        return S_OK;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As you can see a delegate is created using the OnClick method of the class parameter passed to the template and this is your own class. You'll have to declare the OnClick method inside your class. If you don't you'll get a build error on the CreateDelegate call. Just  above that line you'll find a prototype of that method ready to be cut and pasted inside your code!&lt;/p&gt;
&lt;p&gt;Now we have seen how to run XAML2CPP and the code it has generated. We still have to see how we can integrate it in our own code.&lt;/p&gt;
&lt;p&gt;You can start by creating an empty Win32 application subproject inside Platform Builder.&lt;/p&gt;
&lt;p&gt;You can repeat the steps we did in the first Silverlight for Windows Embedded  tutorial here:&lt;/p&gt;
&lt;p&gt;&lt;a href="javascript:void(0);/*1258119601405*/"&gt;http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/01/silverlight-for-embedded-tutorial.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then move your XAML file inside the subproject directory and run XAML2CPP on it. You'll have all the files we described above inside your subproject directory.&lt;/p&gt;
&lt;p&gt;Add a resource (.rc) script to your project, as described in the tutorial but don't add the XAML resource to it.&lt;/p&gt;
&lt;p&gt;Simply include the .rc script that XAML2CPP has generated for you.&lt;/p&gt;
&lt;p&gt;Move to the "resource view" tab, right click on your project .rc file and select "Resource includes...".&lt;/p&gt;
&lt;p&gt;Add:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "XAML2CPP.rc"&lt;/span&gt;

&lt;/pre&gt;
&lt;p&gt;and close the dialog.&lt;/p&gt;
&lt;p&gt;In this way you'll include all the resources generated by XAML2CPP, you don't need to add them by hand (and discover that you forgot that when you run your application!).&lt;/p&gt;
&lt;p&gt;Now you can edit our main .cpp source file.&lt;/p&gt;
&lt;p&gt;Fist of all you can include "XAML2CPP.h" :&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "XAML2CPP.h"&lt;/span&gt;

&lt;/pre&gt;
&lt;p&gt;Then you can declare a class to implement the code that XAML2CPP hasn't (and could not have) generated for you:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;class Page : public TPage&amp;lt;Page&amp;gt;&lt;/span&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;{&lt;/span&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;public:&lt;/span&gt;

&lt;span style="background-color: rgb(192, 192, 192);"&gt;    HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)&lt;/span&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;    {&lt;/span&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;        MessageBox(NULL,TEXT("Click!"),TEXT("Click!"),MB_OK);&lt;/span&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;        return S_OK;&lt;/span&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;    }&lt;/span&gt;
&lt;span style="background-color: rgb(192, 192, 192);"&gt;};&lt;/span&gt;

&lt;/pre&gt;
&lt;p&gt;As you can see the class is quite simple. You'll have to write only your own even hander code (and you may copy its prototype from the comment inside TPage.h, a dream for a lazy programmer like me!). No initialization code, no event binding code.&lt;/p&gt;
&lt;p&gt;Sounds great?&lt;/p&gt;
&lt;p&gt;Let's see what you have to add to your WinMain function to create your own XAML UI.&lt;/p&gt;
&lt;p&gt;You should still add the runtime initialization code (you can copy it from our previous sample, so don't be too lazy!):&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
int WINAPI WinMain(HINSTANCE hInstance,&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
                     HINSTANCE hPrevInstance,&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
                     LPTSTR     lpCmdLine,&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
                     int       nCmdShow)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
{&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    if (!XamlRuntimeInitialize())&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            return -1;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    HRESULT retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    IXRApplicationPtr app;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    if (FAILED(retcode=GetXRApplicationInstance(&amp;amp;app)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;Now you can create and display your XAML page:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    Page page;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    if (FAILED(page.Init(hInstance,app)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    UINT exitcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    if (FAILED(page.GetVisualHost()-&amp;gt;StartDialog(&amp;amp;exitcode)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    return 0;&lt;/pre&gt;
&lt;p&gt;You should declare an istance of your class, call Init on it (passing the application HINSTANCE and a pointer to the XAML runtime application object) and then you can show it accessing its visual host methods.&lt;/p&gt;
&lt;p&gt;As you can see XAML2CPP has generated only the "boilerplate" code and just a simple wrapper around some features (initialization, mostly). It's not a big framework, I don't like them and I'm too lazy to build one!&lt;/p&gt;
&lt;p&gt;You can download XAML2CPP from here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/XAML2CPP.zip"&gt;http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/XAML2CPP.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It's still an alpha release, so use it carefully (read that as backup everything you can backup and don't blame me for problems) and let me know if you experience problems or have ideas about ways to improve it.&lt;/p&gt;
&lt;p&gt;As I told you, I'm a lazy guy... so don't hold your breath waiting for updateas and bugfixes. But I promise that I'll try to improve this tool and when the code is stable and readable enough, maybe publish it on codeplex or other open-source repositories.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136198"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136198" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/136198.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/11/xaml2cpp.aspx</guid>
            <pubDate>Wed, 11 Nov 2009 12:59:10 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/136198.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/11/xaml2cpp.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/136198.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/136198.aspx</trackback:ping>
        </item>
        <item>
            <title>Silverlight for Windows Embedded  tutorial (step 2)</title>
            <category>Windows CE</category>
            <category>API</category>
            <category>Tutorial</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/11/silverlight-for-embedded-tutorial-step-2.aspx</link>
            <description>&lt;p&gt;In our first tutorial &lt;br /&gt;
&lt;a href="http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/01/silverlight-for-embedded-tutorial.aspx"&gt;http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/01/silverlight-for-embedded-tutorial.aspx&lt;/a&gt;&lt;br /&gt;
we learnt how to load a XAML-based user interface inside your own application and intercept the events that it generates.&lt;br /&gt;
In this second tutorial we will learn how to use storyboards to create animations inside our user interface and how we can control them from code.&lt;br /&gt;
We can reopen our silverlight2 application project in Expression Blend 2 SP1 and add a new element to our UI: a TextBlock.&lt;br /&gt;
&lt;img height="651" width="872" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/step2/screenshot00.PNG" alt="" /&gt;&lt;br /&gt;
We can place it just under our button.&lt;br /&gt;
&lt;img height="651" width="872" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/step2/screenshot01.PNG" alt="" /&gt;&lt;br /&gt;
Then we can create a new storyboard, using the "+" button that we can find just under the "Objects and Timeline" toolbox header.&lt;br /&gt;
&lt;img height="56" width="257" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/step2/screenshot02.PNG" alt="" /&gt;&lt;br /&gt;
We should assign a name to our new Storyboard, as we did with the button control.&lt;br /&gt;
&lt;img height="154" width="386" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/step2/screenshot03.PNG" alt="" /&gt;&lt;br /&gt;
Now we can move our storyboard time cursor to the 1 second mark and change our page to the end point of our animation.&lt;br /&gt;
&lt;img height="651" width="872" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/step2/screenshot04.PNG" alt="" /&gt;&lt;br /&gt;
We can rotate our TextBlock, for example.&lt;br /&gt;
&lt;img height="651" width="872" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/step2/screenshot05.PNG" alt="" /&gt;&lt;br /&gt;
Expression Blend create for us the animation and transformation objects required to perform the desired visual effect.&lt;br /&gt;
We want to have our TextBlock performing a full rotation, so we can edit the parameters of the rotation transform and set the angle to 360 degrees.&lt;br /&gt;
&lt;img src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/step2/screenshot06.PNG" alt="" /&gt;&lt;br /&gt;
By right clicking on the tranform item we can also set the number of iteration that this animation performs. We set it to infinite to have a continous rotation of our poor TextBlock.&lt;br /&gt;
&lt;img src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/step2/screenshot07.PNG" alt="" /&gt;&lt;br /&gt;
Now we save the changes we did to our project in Expression Blend and go back to Platform Builder to change our code.&lt;br /&gt;
First of all we have to get a pointer to our Storyboard. We can retrieve it using the FindName method of our visual root, like we did to retrieve a pointer to the button object in the first step of this tutorial.&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRStoryboardPtr sboard;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    if (FAILED(retcode=root-&amp;gt;FindName(TEXT("SpinText"), &amp;amp;sboard)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
We will need to use the storyboard and button object inside your event handler class, so we need to change it to store those two smart pointers:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
class BtnEventHandler&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
{&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
protected:&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    IXRButtonBasePtr    btn;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRStoryboardPtr     sboard;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

public:&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    BtnEventHandler(IXRButtonBasePtr&amp;amp; button, IXRStoryboardPtr&amp;amp; storyboard) : btn(button),sboard(storyboard)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    {    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    }&lt;/pre&gt;
&lt;p&gt;    &lt;br /&gt;
We also need to change its declaration inside the WinMain function:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    BtnEventHandler handler(btn,sboard);&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Now we can edit our OnClick event handler to use our button to start and stop spinning animation.&lt;br /&gt;
First of all we should know if the animation is running. To do that we can retrieve the state of our storyboard object:&lt;/p&gt;
&lt;pre&gt;
 &lt;span style="background-color: rgb(192, 192, 192);"&gt;       HRESULT        retcode;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        XRClockState ckstate;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        if (FAILED(retcode=sboard-&amp;gt;GetCurrentState(&amp;amp;ckstate)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            return retcode;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
if ckstate is XRClockState_Stopped, our animation is stopped, so we will need to start it, using the Begin method of our Storyboard object.&lt;br /&gt;
If the animation is running we should stop it using the Stop method.&lt;br /&gt;
At the same time we want to change the text on the button object to reflect the action it performs. The IXRButton object (COM interface) derives from the IXRContentControl object that defines methods to access a control "content".&lt;br /&gt;
What is "content" for a Silverlight for Windows Embedded  object? It's an instance of the XRValue class. This class can contain different kinds of data: strings, numbers, coordinates etc. It's current content type is defined by the vType field and may be one of the VALUE_TYPE enumeration values:&lt;br /&gt;
VTYPE_NONE = 0,&lt;br /&gt;
VTYPE_FLOAT = 1,&lt;br /&gt;
VTYPE_INT = 2,&lt;br /&gt;
VTYPE_BOOL = 3,&lt;br /&gt;
VTYPE_UINT = 4,&lt;br /&gt;
VTYPE_COLOR = 5,&lt;br /&gt;
VTYPE_READONLY_STRING = 6,&lt;br /&gt;
VTYPE_BSTR = 7&lt;br /&gt;
VTYPE_POINT = 8,&lt;br /&gt;
VTYPE_RECT = 9,&lt;br /&gt;
VTYPE_THICKNESS = 10,&lt;br /&gt;
VTYPE_SIZE = 11,&lt;br /&gt;
VTYPE_GRIDLENGTH = 12,&lt;br /&gt;
VTYPE_CORNER_RADIUS = 13,&lt;br /&gt;
VTYPE_OBJECT = 14&lt;br /&gt;
Depending on the type you set, you can use one of the fields of the object (defined as an unnamed union) to set the actual value of your XRValue objects.&lt;br /&gt;
If you worked on COM (Component Object Model) applications in the past (or you are working on this kind of technology right now, of course!) the XRValue object will remind you the VARIANT object that is used in COM to define "generic" data.&lt;br /&gt;
To change the content of our button we need to declare an XRValue object of type "read only string":&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;        XRValue btnvalue;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;

&lt;span style="background-color: rgb(192, 192, 192);"&gt;        btnvalue.vType=VTYPE_READONLY_STRING; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
We can assign its value trough the pReadOnlyStringVal field and set it to "Spin!" or "Stop!" depending on our animation current state.&lt;br /&gt;
The full code of our event handler will be:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    {&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        HRESULT        retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        XRClockState ckstate;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        if (FAILED(retcode=sboard-&amp;gt;GetCurrentState(&amp;amp;ckstate)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            return retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        XRValue btnvalue;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        btnvalue.vType=VTYPE_READONLY_STRING; &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        if (ckstate==XRClockState_Stopped)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        {&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            btnvalue.pReadOnlyStringVal=L"Stop!";&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            if (FAILED(retcode=sboard-&amp;gt;Begin()))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
                return retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        }&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        else&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        {&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            btnvalue.pReadOnlyStringVal=L"Spin!";&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            if (FAILED(retcode=sboard-&amp;gt;Stop()))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
                return retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        }&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        if (FAILED(retcode=btn-&amp;gt;SetContent(&amp;amp;btnvalue)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
            return retcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

        return S_OK;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    }&lt;/pre&gt;
&lt;p&gt;    &lt;br /&gt;
A little more complicated than the event handler of our previous tutorial step, but not so much. And in this function we used two very useful features of Silverligh for Embedded: animations and control content access.&lt;br /&gt;
You can download the full source code here:&lt;br /&gt;
&lt;a href="http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/SilverlightSample2.zip"&gt;http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/SilverlightSample2.zip&lt;/a&gt;&lt;br /&gt;
Please use the comments to let me know if you find this kind of tutorial useful, to report mistakes and to suggest the arguments that you would like to see discussed in the next steps.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135400"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135400" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/135400.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/11/silverlight-for-embedded-tutorial-step-2.aspx</guid>
            <pubDate>Sun, 11 Oct 2009 15:49:01 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/135400.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/11/silverlight-for-embedded-tutorial-step-2.aspx#feedback</comments>
            <slash:comments>9</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/135400.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/135400.aspx</trackback:ping>
        </item>
        <item>
            <title>Interfaccia uomo macchina</title>
            <category>Windows CE</category>
            <category>italian</category>
            <category>events</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/05/interfaccia-uomo-macchina.aspx</link>
            <description>&lt;img height="644" width="640" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/pictures/DSC02005_small.JPG" alt="Sevilla (Spain) - The alcazar" /&gt;&lt;br /&gt;
If you want to discover something more about Windows Embedded CE 6.0 R3 and you live close to Padua, Milan or Bologna (or you want to travel to those cities, of course!), you can register for those Arrow, Microsoft and Freescale sponsored events:&lt;br /&gt;
&lt;a href="http://www.silverstar-celdis.it/index.php?id=834&amp;amp;tx_ttnews%5Btt_news%5D=253&amp;amp;tx_ttnews%5BbackPid%5D=831&amp;amp;cHash=6a2c437777"&gt;http://www.silverstar-celdis.it/index.php?id=834&amp;amp;tx_ttnews%5Btt_news%5D=253&amp;amp;tx_ttnews%5BbackPid%5D=831&amp;amp;cHash=6a2c437777&lt;/a&gt;&lt;br /&gt;
If you read my blog and come to those events, let me know that!&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135303"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135303" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/135303.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/05/interfaccia-uomo-macchina.aspx</guid>
            <pubDate>Mon, 05 Oct 2009 14:47:23 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/135303.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/05/interfaccia-uomo-macchina.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/135303.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/135303.aspx</trackback:ping>
        </item>
        <item>
            <title>Silverlight for Windows Embedded tutorial</title>
            <category>Windows CE</category>
            <category>Tutorial</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/01/silverlight-for-embedded-tutorial.aspx</link>
            <description>&lt;p&gt;Windows Embedded CE 6.0 R3 has been released yesterday, you can download it from here:&lt;br /&gt;
&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=bc247d88-ddb6-4d4a-a595-8eee3556fe46"&gt;http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=bc247d88-ddb6-4d4a-a595-8eee3556fe46&lt;/a&gt;&lt;br /&gt;
One of the most exciting new features of R3 is Silverlight for Windows Embedded.&lt;br /&gt;
With this technology the UI of an application can be described using XAML, an XML-based language, and can be designed using visual tools like Expression Blend. &lt;br /&gt;
This will allow UI designers to work on embedded devices using the same tools they use on the desktop and it will let embedded developers concentrate on the core application features and not on the design of the UI.&lt;br /&gt;
I hope that this will lead to visually pleasing but also more user friendly interfaces on any kind of embedded device. Using visual tools for UI design should also improve development time and allow minor fixes to the UI without code modifications. This will improve device development times and reduce maintenance costs.&lt;br /&gt;
This simple tutorial will show how you can design a very basic UI in Expression Blend 2, load it inside an application and interact with it.&lt;br /&gt;
The first step you need to perform is include the components needed to support Silverlight for Windows Embedded  inside your OS Image and rebuild it.&lt;span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 153, 153); font-family: Verdana,sans-serif; font-size: 11px; line-height: 15px; text-align: left;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;Jochen Dieckfoß provided a good description of that process on his blog here:&lt;br /&gt;
&lt;a href="http://discovertheexperience.blogspot.com/2009/09/windows-embedded-ce-60-r3-using.html"&gt;http://discovertheexperience.blogspot.com/2009/09/windows-embedded-ce-60-r3-using.html&lt;/a&gt;&lt;br /&gt;
Now that you have an OS image supporting Silverlight for Windows Embedded  you can start to design your UI.&lt;br /&gt;
Start Expression Blend and create a new Silverlight application.&lt;br /&gt;
&lt;img height="323" width="498" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot1.PNG" /&gt;&lt;br /&gt;
You'll have to use Expression Blend 2 SP1 (thanks Shai for the useful advice!) because this is the release that support Silverlight 2, the version that is currently supported on embedded devices.&lt;br /&gt;
This will create a Visual Studio solution (that we don't need for this tutorial).&lt;br /&gt;
As you can see the wizard allows you to choose a language between C# and Visual Basic. Silverlight for Windows Embedded  supports only C++ programming and it's currently not integrated with Expression Blend, so you'll not use the source code generated by this tool.&lt;br /&gt;
Remember to disable Visual Studio integration inside Expression Blend or it will generate C# or VB.NET code for event handlers etc.&lt;br /&gt;
&lt;img height="373" width="502" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot2.PNG" /&gt;&lt;br /&gt;
After you created a new project, Expression Blend will present you with an empty XAML document (named page.xaml by default).&lt;br /&gt;
&lt;img height="663" width="1104" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot3.PNG" /&gt;&lt;br /&gt;
We can draw a simple button inside it picking it from the rich collection of controls provided by Silverlight.&lt;br /&gt;
&lt;img height="663" width="1104" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot4.PNG" /&gt;&lt;br /&gt;
Using the properties window we can assign a name to our new button.&lt;br /&gt;
&lt;img height="325" width="295" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot5.PNG" /&gt;&lt;br /&gt;
The properties toolbox allows you to customize many aspects of your button: it's colors, it's rotation (yes you can have a vertical button or a button turned at 45 degrees!), it's opacity etc.&lt;br /&gt;
We will experiment with all these features in the next tutorials, for now we will keep the button as is and save our XAML.&lt;br /&gt;
If you open the XAML file using a text editor or view it using the XAML view inside Expression Blend you'll see that it's quite simple:&lt;/p&gt;
&lt;pre style="color: rgb(0, 51, 102); background-color: rgb(192, 192, 192);"&gt;
&amp;lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SimpleApp.Page" 
Width="640" Height="480"&amp;gt;
    &amp;lt;Grid x:Name="LayoutRoot" Background="White"&amp;gt;
        &amp;lt;Button Height="87" Margin="189,106,209,0" VerticalAlignment="Top" Content="Button" 
x:Name="MyButton"/&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/UserControl&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
We have a top level container (UserControl) that uses a Grid layout (objects are organized in rows and columns) and contains our button.&lt;br /&gt;
The button has attributes for placement inside its own grid cell (the only one we have), alignment, content (the text "Button") and its name ("MyButton"). &lt;br /&gt;
Now we can start Platform Builder and add a new subproject to our OS Design. &lt;br /&gt;
You may develop your Silverlight for Windows Embedded  application also using Visual Studio 2005 or 2008 Smart Device application if you generate an SDK from your R3 OS design and install it on your development PC, but for this tutorial we will keep things simple...&lt;br /&gt;
Move to the solution tab, right click on the subprojects node and select "add new...".&lt;br /&gt;
Create a Win32 application.&lt;br /&gt;
&lt;img height="487" width="534" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot6.PNG" /&gt;&lt;br /&gt;
And choose the simple Win32 application template.&lt;br /&gt;
&lt;img height="487" width="534" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot7.PNG" /&gt;&lt;br /&gt;
This will create an application containing only WinMain, it's enough to start experimenting with our first Silverlight for Embedded UI.&lt;br /&gt;
The first thing we should do is add the Silverlight for Windows Embedded  includes to our source code:&lt;/p&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "pwinuser.h"&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "xamlruntime.h"&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "xrdelegate.h"&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="background-color: rgb(192, 192, 192);"&gt;#include "xrptr.h"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
We will add the XAML that we generate with expression blend to our application resources. In this way we will not need to distibute the XAML file with it. On the other side changes to the XAML will require a rebuild of the application, you may choose the best method to integrate XAML and C++ source code in your application.&lt;br /&gt;
To include resources inside your executable file you need to add a resource script (rc file) to your subproject. &lt;br /&gt;
Right click on the subproject in solution view, select "add\new item" and then select resource file from the dialog box and assign a name to it (usually you have only one resource file per application so using the application name for that file sounds like a good idea).&lt;br /&gt;
&lt;img height="419" width="681" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot8.PNG" /&gt;&lt;br /&gt;
Now that you have your resource file you can add the XAML data to it by creating a new resource.&lt;br /&gt;
Go to the "resource view" tab, right click on your resource file and select "add resource..."&lt;br /&gt;
&lt;img height="261" width="366" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot9.PNG" /&gt;&lt;br /&gt;
Now you can import your XAML file data inside your executable. It will be stored inside it (at the end of the file) as binary data.&lt;br /&gt;
&lt;img height="393" width="601" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot10.PNG" /&gt;&lt;br /&gt;
Type "XAML" as resource type.&lt;br /&gt;
&lt;img height="230" width="264" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot11.PNG" /&gt;&lt;br /&gt;
For the tutorial you can leave the default ID (IDR_XAML1) for that resource, but it's a good idea to give meaningful names to your XAML components in a real project.&lt;br /&gt;
&lt;img height="137" width="240" alt="" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/screenshots/screenshot12.PNG" /&gt;&lt;br /&gt;
To use our resource IDs we need to include "resource.h" inside our .cpp file:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
#include "resource.h"&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Then, inside our application main function (WinMain) we can start to interact with the XAML runtime.&lt;br /&gt;
First of all we need to initialize it:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    if (!XamlRuntimeInitialize())&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
If &lt;span style="font-weight: bold;"&gt;XamlRuntimeInitialize &lt;/span&gt;succeeded, the Silverlight for Windows Embedded  runtime is loaded inside your application and it's ready to handle the UI.&lt;br /&gt;
Each Silverlight for Windows Embedded  application has a singleton "Application" object that allows us to access global application properties and features.&lt;br /&gt;
To access it we should use the &lt;span style="font-weight: bold;"&gt;GetXRApplicationInstance &lt;/span&gt;API.&lt;/p&gt;
&lt;pre&gt;
 &lt;span style="background-color: rgb(192, 192, 192);"&gt;   HRESULT retcode;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    IXRApplicationPtr app;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    if (FAILED(retcode=GetXRApplicationInstance(&amp;amp;app)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
&lt;br /&gt;
Someone will notice that we are using HRESULTs and classes that use the "I" prefix and the "Ptr" suffix and understand that this new technlogy is based on COM (Component Object Model) that may sound like an ancient tool in those .NET and managed code days but it's still the foundation of many technlogies on both CE and desktop Windows releases. All Silverlight for Windows Embedded  objects are implemented as COM objects that export specific interfaces (COM interfaces have names beginning with "I"). Since using interfaces directly requires handling of their reference count and this may lead to memory leaks or premature object deletions, COM programmers prefer to use "smart pointers" that are wrappers around the interfaces and manage reference counting internally, destroying the COM object when the smart pointer object goes out of scope inside your C++ application (function return if it's allocated on the stack, object destruction if it's declared as a class member etc.). Smart point classes add the "Ptr" suffix to the interface name.&lt;br /&gt;
After this 30 seconds introduction to COM, we can return to our application.&lt;br /&gt;
The first thing we have to do with our application object is tell it where it can find its resources (XAML, images etc.).&lt;br /&gt;
We included them inside the executable using the resource file and so we can pass our HINSTANCE handle to it:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    if (FAILED(retcode=app-&amp;gt;AddResourceModule(hInstance)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Now that we have initialized our application object we can create our main window and let Silverlight for Windows Embedded  manage its contents:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    XRWindowCreateParams wp;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    ZeroMemory(&amp;amp;wp, sizeof(XRWindowCreateParams));&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    wp.Style       = WS_OVERLAPPED;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    wp.pTitle      = L"S4E Test";&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    wp.Left        = 0;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    wp.Top         = 0;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    XRXamlSource xamlsrc;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    xamlsrc.SetResource(hInstance,TEXT("XAML"),MAKEINTRESOURCE(IDR_XAML1));&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    IXRVisualHostPtr vhost;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    if (FAILED(retcode=app-&amp;gt;CreateHostFromXaml(&amp;amp;xamlsrc, &amp;amp;wp, &amp;amp;vhost)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
The VisualHost object "hosts" the runtime and allows us to access its contents and load our XAML from resources (using the XRXamlSource object).&lt;br /&gt;
Now our XA&lt;br /&gt;
The object inside our Silverlight for Windows Embedded  application are organized in a objects tree. To access the object inside it we need a pointer to its root:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRFrameworkElementPtr root;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    if (FAILED(retcode=vhost-&amp;gt;GetRootElement(&amp;amp;root)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
From the root object we can access our button using the name we assigned to it inside Expression Blend:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    IXRButtonBasePtr btn;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    &lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    if (FAILED(retcode=root-&amp;gt;FindName(TEXT("MyButton"), &amp;amp;btn)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
To receive a notification when the user clicks our button we need to provide a delegate. A delegate is a pointer to a member of an istance of a C++ class that should have a specific prototype.&lt;br /&gt;
We can declare a simple C++ class inside our .cpp source and implement our button click event delegate inside it:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
class BtnEventHandler&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
{&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
public:&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    {&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        MessageBox(NULL,TEXT("Click!"),TEXT("Silverlight for Windows Embedded test"),MB_OK);&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return S_OK;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    }&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
};&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Our event handler will simply display a message box when the button is clicked.&lt;br /&gt;
As you can see the event handler takes two parameters. A pointer to the object that generates the event (our button) and a pointer to a structure that contains the event parameters.&lt;br /&gt;
&lt;br /&gt;
To connect our event handler to the button we have to create a delegate object:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    BtnEventHandler handler;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    IXRDelegate&amp;lt;XRMouseButtonEventArgs&amp;gt;* clickdelegate;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    if (FAILED(retcode=CreateDelegate(&amp;amp;handler,&amp;amp;BtnEventHandler::OnClick,&amp;amp;clickdelegate)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    if (FAILED(retcode=btn-&amp;gt;AddClickEventHandler(clickdelegate)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Our event handler has been connected to the button, now we can show our UI and wait that the user presses our wonderful button:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    UINT exitcode;&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

    if (FAILED(retcode=vhost-&amp;gt;StartDialog(&amp;amp;exitcode)))&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
        return -1;&lt;/pre&gt;
&lt;pre&gt;

&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Our clickdelegate object is not a smart pointer, so we will have to release it explicitly:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    clickdelegate-&amp;gt;Release();&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Before we can build our subproject we need to add the include directories and the libraries needed to support Silverlight for Windows Embedded  inside our application.&lt;br /&gt;
Open the subproject sources script by right clicking on the subproject and choosing "open".&lt;br /&gt;
Add includes:&lt;/p&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
INCLUDES=$(_OEMINCPATH)&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

and libraries:&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;

TARGETLIBS= \&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    $(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\coredll.lib \&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    $(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\xamlruntime.lib \&lt;/pre&gt;
&lt;pre style="background-color: rgb(192, 192, 192);"&gt;
    $(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\uuid.lib \&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
(you should already have the TARGETLIBS directive inside your sources script)&lt;br /&gt;
Now you can run the application on your device and push that button!&lt;br /&gt;
&lt;br /&gt;
You, like me, are too lazy to type sample code, you can download a zip containing our demo application here:&lt;br /&gt;
&lt;a href="http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/SilverlightSample.zip"&gt;http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/SilverlightSample.zip&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
You can find the next step here:&lt;br /&gt;
&lt;a href="http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/11/silverlight-for-embedded-tutorial-step-2.aspx"&gt;http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/11/silverlight-for-embedded-tutorial-step-2.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135223"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135223" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/135223.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/01/silverlight-for-embedded-tutorial.aspx</guid>
            <pubDate>Fri, 02 Oct 2009 02:35:11 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/135223.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/10/01/silverlight-for-embedded-tutorial.aspx#feedback</comments>
            <slash:comments>44</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/135223.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/135223.aspx</trackback:ping>
        </item>
        <item>
            <title>Windows Embedded support the Italian way</title>
            <category>Windows CE</category>
            <category>general</category>
            <category>italian</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/22/windows-embedded-support-the-italian-way.aspx</link>
            <description>&lt;img height="426" width="640" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/pictures/DSC05896 (Small).JPG" alt="" /&gt;&lt;br /&gt;
The new Italian Windows Embedded support forum is now active:&lt;br /&gt;
&lt;a href="javascript:void(0);/*1253656782957*/"&gt;http://social.microsoft.com/Forums/it-IT/windowsembeddedit/threads&lt;/a&gt;&lt;br /&gt;
Here Italian speaking users of the different Windows Embedded platforms can discuss, post their questions and, hopefully, receive good answers in their own mother tongue (and also my own mother tongue, as you can understand from the poor english of this blog!).&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135018"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135018" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/135018.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/22/windows-embedded-support-the-italian-way.aspx</guid>
            <pubDate>Wed, 23 Sep 2009 05:08:08 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/135018.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/22/windows-embedded-support-the-italian-way.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/135018.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/135018.aspx</trackback:ping>
        </item>
        <item>
            <title>Windows Embedded CE SR3</title>
            <category>Windows CE</category>
            <category>general</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/22/windows-embedded-ce-sr3.aspx</link>
            <description>&lt;img height="426" width="640" src="/images/geekswithblogs_net/WindowsEmbeddedCookbook/pictures/DSC05889 (Small).JPG" alt="Dutch cheese in Alkmaar" /&gt;&lt;br /&gt;
Windows CE SR3 has been announced today at ESC in Boston:&lt;br /&gt;
&lt;a href="http://www.microsoft.com/windowsembedded/en-us/news/pressreleases/cer3_release.mspx"&gt;http://www.microsoft.com/windowsembedded/en-us/news/pressreleases/cer3_release.mspx&lt;/a&gt;&lt;br /&gt;
This new "service release" will include many new features, mostly focused around the user experience, providing more applications and better tools to develop them.&lt;br /&gt;
One of the most exciting new features is Silverlight for Windows Embedded:&lt;br /&gt;
&lt;a href="http://www.microsoft.com/windowsembedded/en-us/products/windowsce/silverlightforwe.mspx"&gt;http://www.microsoft.com/windowsembedded/en-us/products/windowsce/silverlightforwe.mspx&lt;/a&gt;&lt;br /&gt;
it's an implementation of Silverlight on embedded devices.&lt;br /&gt;
Now I'll be able to understand the cool Silverlight blogs of Corrado (http://blogs.ugidotnet.org/corrado/Default.aspx) and Andrea (http://blog.boschin.it/) and, maybe, learn from them how to use the new tools to provide a great UI on embedded devices. I hope to be able to show some cool samples of this technology soon.&lt;br /&gt;
I'll discuss about the other new features of R3 in the next days, now I'm going to finish my demos for tomorrow conference:&lt;br /&gt;
http://www.silverstar-celdis.it/index.php?id=949&lt;br /&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135017"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=135017" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/135017.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/22/windows-embedded-ce-sr3.aspx</guid>
            <pubDate>Wed, 23 Sep 2009 04:57:53 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/135017.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/22/windows-embedded-ce-sr3.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/135017.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/135017.aspx</trackback:ping>
        </item>
        <item>
            <title>Salmone svuotafrigo</title>
            <category>recipe</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/07/salmone-svuotafrigo.aspx</link>
            <description>This is a recipe that I carefully planned and designed after checking the contents of my fridge after a three weeks holiday in California. &lt;br /&gt;
I found some salmon at the local supermarket and I had to decide how to cook it. Olives and leeks seems the only things still edible inside my fridge.&lt;br /&gt;
The result tasted quite good, but my perception could have been impacted by the jet-lag... so handle this recipe carefully!&lt;br /&gt;
&lt;br /&gt;
Ingredients:&lt;br /&gt;
- salmon (one large filet serves two people)&lt;br /&gt;
- leeks (200 g)&lt;br /&gt;
- olive oil (three table spoons)&lt;br /&gt;
- green olives (100 g)&lt;br /&gt;
- apple cider (one glass)&lt;br /&gt;
&lt;br /&gt;
Drop the olive oil in a pan and heat it. &lt;br /&gt;
When the oil is hot, add the leeks cutted in small pieces and the olives cutted in slices.&lt;br /&gt;
Let them cook in the oil for a couple of minutes and then add the cider.&lt;br /&gt;
Reduce the heat and add the salmon cut in 2cm thick pieces and with no skin.&lt;br /&gt;
Cover the pan with its own cover and let the salmon cook slowly, turning it after 5 minutes and let it cook for another 10 minutes at least. Open the pan and rise the fire under it to reduce the sauce. Serve the salmon pieces covered with leeks  and olives and enjoy.&lt;br /&gt;
If you don't like the taste... try it again after some serious jet-lagging!&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134533"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134533" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/134533.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/07/salmone-svuotafrigo.aspx</guid>
            <pubDate>Mon, 07 Sep 2009 18:30:26 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/134533.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/07/salmone-svuotafrigo.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/134533.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/134533.aspx</trackback:ping>
        </item>
        <item>
            <title>Design with Freescale event</title>
            <category>Windows CE</category>
            <category>events</category>
            <link>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/07/design-with-freescale-event.aspx</link>
            <description>If you want to meet me in person an, maybe, learn something new about Windows Embedded CE 6.0, you can attend the "Design with Freescale" event in Milan on the 23rd of semptember.&lt;br /&gt;
You can discover all Freescale's solutions for embedded devices, see some cool hardware running Windows CE and other embedded operating systems and find many experts to discuss your new designs.&lt;br /&gt;
&lt;br /&gt;
You can find more information about the event here: &lt;a href="http://www.silverstar-celdis.it/index.php?id=949"&gt;http://www.silverstar-celdis.it/index.php?id=949&lt;/a&gt; (italian)&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134532"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134532" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/WindowsEmbeddedCookbook/aggbug/134532.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Valter Minute</dc:creator>
            <guid>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/07/design-with-freescale-event.aspx</guid>
            <pubDate>Mon, 07 Sep 2009 18:23:16 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/134532.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/09/07/design-with-freescale-event.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedCookbook/comments/commentRss/134532.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedCookbook/services/trackbacks/134532.aspx</trackback:ping>
        </item>
    </channel>
</rss>