<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Peter Foot - Desktop Code</title>
    <link>http://peterfoot.net/</link>
    <description>Microsoft Device Application Development MVP</description>
    <image>
      <url>http://peterfoot.net/images/mugshot.jpg</url>
      <title>Peter Foot - Desktop Code</title>
      <link>http://peterfoot.net/</link>
    </image>
    <copyright>Peter Foot</copyright>
    <lastBuildDate>Tue, 14 Aug 2007 12:30:08 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>peter.foot@appamundi.com</managingEditor>
    <webMaster>peter.foot@appamundi.com</webMaster>
    <item>
      <trackback:ping>http://peterfoot.net/Trackback.aspx?guid=21d2db2e-bcdd-4848-8cc6-1f88d745939d</trackback:ping>
      <pingback:server>http://peterfoot.net/pingback.aspx</pingback:server>
      <pingback:target>http://peterfoot.net/PermaLink,guid,21d2db2e-bcdd-4848-8cc6-1f88d745939d.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In March I showed <a href="http://peterfoot.net/DetermineVersionOfConnectedDevice.aspx">how
to get the version of a connected device from the desktop</a>. This post documents
the rest of the registry settings used to store device information. There are two
registry locations, the first at <font face="Courier New">HKEY_CURRENT_USER\Software\Microsoft\Windows
CE Services</font> contains information about the currently connected device. The
second, <font face="Courier New">HKEY_CURRENT_USER\Software\Microsoft\Windows
CE Services\Partners</font> contains information for each of the partnerships established
on the desktop PC.
</p>
        <p>
When the device is docked, regardless of whether a partnership is established, the
following keys are populated in <font face="Courier New">HKEY_CURRENT_USER\Software\Microsoft\Windows
CE Services</font>:-
</p>
        <ul>
          <li>
DeviceHardwareId -String containing a unique Guid for the device</li>
          <li>
DeviceOemInfo - OEM specific string (as returned by SystemParametersInfo using SPI_GETOEMINFO)
e.g. WIZA200 (HTC Wizard)</li>
          <li>
DeviceProcessorType - DWORD value - 2577 (ARM) for all Windows Mobile devices</li>
          <li>
DeviceType - string containing platform type (as returned by SystemParamtersInfo using
SPI_GETPLATFORMTYPE) e.g. PocketPC or SmartPhone</li>
          <li>
DeviceVersion - DWORD value - see <a href="http://peterfoot.net/DetermineVersionOfConnectedDevice.aspx">my
previous post</a>.</li>
        </ul>
        <p>
The partnerships are stored with a unique DWORD partnership id e.g. 
</p>
        <p>
          <font face="Courier New">HKEY_CURRENT_USER\Software\Microsoft\Windows CE Services\Partners\12345678\</font>
        </p>
        <p>
There are additional values to describe sync behaviour and some Windows Mobile Device
Center specific values e.g. to specify the display icon for a device. Otherwise all
of the above values are duplicated here for the partner device, except with some naming
differences:-
</p>
        <ul>
          <li>
DeviceHardwareId</li>
          <li>
OemInfo</li>
          <li>
ProcessorType</li>
          <li>
DeviceType</li>
          <li>
Version</li>
        </ul>
        <p>
Each partnership has a directory containing any resources used, this includes the
icon etc. The path is retrieved from the <em>DataFolder</em> value. This is a path
beneath the users roaming application data folder which you would get using <font face="Courier New">System.Environment.GetFolder(System.Environment.SpecialFolder.ApplicationData)</font></p>
        <p>
The icon is specified in <em>DeviceIconFile</em> and if you append this to the path
you'll have the full filename of the icon.
</p>
        <img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=21d2db2e-bcdd-4848-8cc6-1f88d745939d" />
      </body>
      <title>Desktop ActiveSync Registry Settings</title>
      <guid isPermaLink="false">http://peterfoot.net/PermaLink,guid,21d2db2e-bcdd-4848-8cc6-1f88d745939d.aspx</guid>
      <link>http://peterfoot.net/DesktopActiveSyncRegistrySettings.aspx</link>
      <pubDate>Tue, 14 Aug 2007 12:30:08 GMT</pubDate>
      <description>&lt;p&gt;
In March I showed &lt;a href="http://peterfoot.net/DetermineVersionOfConnectedDevice.aspx"&gt;how
to get the version of a connected device from the desktop&lt;/a&gt;. This post documents
the rest of the registry settings used to store device information. There are two
registry locations, the first at &lt;font face="Courier New"&gt;HKEY_CURRENT_USER\Software\Microsoft\Windows
CE Services&lt;/font&gt; contains information about the currently connected device. The
second,&amp;nbsp;&lt;font face="Courier New"&gt;HKEY_CURRENT_USER\Software\Microsoft\Windows
CE Services\Partners&lt;/font&gt; contains information for each of the partnerships established
on the desktop PC.
&lt;/p&gt;
&lt;p&gt;
When the device is docked, regardless of whether a partnership is established, the
following keys are populated in &lt;font face="Courier New"&gt;HKEY_CURRENT_USER\Software\Microsoft\Windows
CE Services&lt;/font&gt;:-
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
DeviceHardwareId -String containing a unique Guid for the device&lt;/li&gt;
&lt;li&gt;
DeviceOemInfo - OEM specific string (as returned by SystemParametersInfo using SPI_GETOEMINFO)
e.g. WIZA200 (HTC Wizard)&lt;/li&gt;
&lt;li&gt;
DeviceProcessorType - DWORD value - 2577 (ARM) for all Windows Mobile devices&lt;/li&gt;
&lt;li&gt;
DeviceType - string containing platform type (as returned by SystemParamtersInfo using
SPI_GETPLATFORMTYPE) e.g. PocketPC or SmartPhone&lt;/li&gt;
&lt;li&gt;
DeviceVersion - DWORD value - see &lt;a href="http://peterfoot.net/DetermineVersionOfConnectedDevice.aspx"&gt;my
previous post&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The partnerships are stored with a unique&amp;nbsp;DWORD partnership id e.g. 
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;HKEY_CURRENT_USER\Software\Microsoft\Windows CE Services\Partners\12345678\&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
There are additional values to describe sync behaviour and some Windows Mobile Device
Center specific values e.g. to specify the display icon for a device. Otherwise all
of the above values are duplicated here for the partner device, except with some naming
differences:-
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
DeviceHardwareId&lt;/li&gt;
&lt;li&gt;
OemInfo&lt;/li&gt;
&lt;li&gt;
ProcessorType&lt;/li&gt;
&lt;li&gt;
DeviceType&lt;/li&gt;
&lt;li&gt;
Version&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Each partnership has a directory containing any resources used, this includes the
icon etc. The path is retrieved from the &lt;em&gt;DataFolder&lt;/em&gt; value. This is a path
beneath the users roaming application data folder which you would get using &lt;font face="Courier New"&gt;System.Environment.GetFolder(System.Environment.SpecialFolder.ApplicationData)&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The icon is specified in &lt;em&gt;DeviceIconFile&lt;/em&gt; and if you append this to the path
you'll have the full filename of the icon.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=21d2db2e-bcdd-4848-8cc6-1f88d745939d" /&gt;</description>
      <category>Desktop Code</category>
      <category>Windows Mobile</category>
    </item>
    <item>
      <trackback:ping>http://peterfoot.net/Trackback.aspx?guid=ebac8fdd-a659-418f-833c-5f9b31fa707c</trackback:ping>
      <pingback:server>http://peterfoot.net/pingback.aspx</pingback:server>
      <pingback:target>http://peterfoot.net/PermaLink,guid,ebac8fdd-a659-418f-833c-5f9b31fa707c.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://blogs.msdn.com/mikehall">Mike Hall</a> posted a link on his blog to <a href="http://channel9.msdn.com/ShowPost.aspx?PostID=42234">a
channel9 interview with Anil Dhawan</a> from the Windows Mobile team discussing
Bluetooth programming, which I recommend you check out. Anil gave a demo of a native
code application to remote control PowerPoint on a desktop PC. This inspired me to
put some finishing touches to a test application I built for the Bluetooth .NETCF
library - It is by no means finished but it works (with the wind blowing in the right
direction!).
</p>
        <p>
There are two components, on the Smartphone an application which you first select
Search from the menu and it will do a lookup of local discoverable devices, then select
one and select the Connect menu option. Once connected any d-pad or number keys are
captured and sent over bluetooth. As I said it was an unfinished project, key items
missing are:-
</p>
        <ul>
          <li>
Store desktop address in the registry so we only have to search once</li>
          <li>
More intuitive interface :-)</li>
          <li>
Support for key mapping - map the device keys to application specific commands e.g.
for media player etc</li>
        </ul>
        <p>
On the desktop a simple listener which listens on a custom service, incoming data
is received as keycodes which are broadcast on the system using the SendKeys.Send
method.
</p>
        <p>
On an unrelated note, thanks to <a href="http://www.sergeybogdanov.com/">Sergey Bogdanov</a> who
has contributed an implementation of the SendKeys class to be included in the upcoming
SDF v1.3 release.
</p>
        <p>
With the listener application running and the Smartphone client connected you can
automate (within reason) whatever app has the focus. It works great for Powerpoint
browsing between slides using the d-pad on the phone. The usual disclaimer applies
- this works only with the Microsoft Bluetooth stack on both device and desktop, I
tested with an Orange SPV C500.
</p>
        <p>
The two projects are available to <a href="http://www.peterfoot.net/files/BluetoothRemote.zip">download
here</a>.
</p>
        <img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=ebac8fdd-a659-418f-833c-5f9b31fa707c" />
      </body>
      <title>Bluetooth Remote Control</title>
      <guid isPermaLink="false">http://peterfoot.net/PermaLink,guid,ebac8fdd-a659-418f-833c-5f9b31fa707c.aspx</guid>
      <link>http://peterfoot.net/BluetoothRemoteControl.aspx</link>
      <pubDate>Fri, 18 Feb 2005 20:52:58 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://blogs.msdn.com/mikehall"&gt;Mike Hall&lt;/a&gt; posted a link on his blog to &lt;a href="http://channel9.msdn.com/ShowPost.aspx?PostID=42234"&gt;a
channel9&amp;nbsp;interview with Anil Dhawan&lt;/a&gt; from the Windows Mobile team discussing
Bluetooth programming, which I recommend you check out. Anil gave a demo of a native
code application to remote control PowerPoint on a desktop PC. This inspired me to
put some finishing touches to a test application I built for the Bluetooth .NETCF
library - It is by no means finished but it works (with the wind blowing in the right
direction!).
&lt;/p&gt;
&lt;p&gt;
There are two components, on the Smartphone an application which you first select
Search from the menu and it will do a lookup of local discoverable devices, then select
one and select the Connect menu option. Once connected any d-pad or number keys are
captured and sent over bluetooth. As I said it was an unfinished project, key items
missing are:-
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Store desktop address in the registry so we only have to search once&lt;/li&gt;
&lt;li&gt;
More intuitive interface :-)&lt;/li&gt;
&lt;li&gt;
Support for key mapping - map the device keys to application specific commands e.g.
for media player etc&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
On the desktop a simple listener which listens on a custom service, incoming data
is received as keycodes which are broadcast on the system using the SendKeys.Send
method.
&lt;/p&gt;
&lt;p&gt;
On an unrelated note, thanks to &lt;a href="http://www.sergeybogdanov.com/"&gt;Sergey Bogdanov&lt;/a&gt; who
has contributed an implementation of the SendKeys class to be included in the upcoming
SDF v1.3 release.
&lt;/p&gt;
&lt;p&gt;
With the listener application running and the Smartphone client connected you can
automate (within reason) whatever app has the focus. It works great for Powerpoint
browsing between slides using the d-pad on the phone. The usual disclaimer applies
- this works only with the Microsoft Bluetooth stack on both device and desktop, I
tested with an Orange SPV C500.
&lt;/p&gt;
&lt;p&gt;
The two projects are available to &lt;a href="http://www.peterfoot.net/files/BluetoothRemote.zip"&gt;download
here&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=ebac8fdd-a659-418f-833c-5f9b31fa707c" /&gt;</description>
      <category>Bluetooth</category>
      <category>Desktop Code</category>
      <category>NETCF</category>
    </item>
    <item>
      <trackback:ping>http://peterfoot.net/Trackback.aspx?guid=5a7b64d9-42ec-47b7-b25e-110c69a72218</trackback:ping>
      <pingback:server>http://peterfoot.net/pingback.aspx</pingback:server>
      <pingback:target>http://peterfoot.net/PermaLink,guid,5a7b64d9-42ec-47b7-b25e-110c69a72218.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Following my <a href="/pfoot/PermaLink.aspx?guid=2f2c77ce-7724-4fa5-b69d-8de4180e5765">previous
post</a>, I did some further development to the code to make it fully match the .NETCF
assembly (yes, in my haste I'd missed a few properties and cut a couple of corners).
So now I have compiled a System.Net.IrDA.dll assembly which has exactly the same classes
and methods as is available in device projects. So you can easily move device code
over to Tablet and laptop PCs.
</p>
        <p>
          <strike>Download the DLL here</strike> (zip 7kb)
</p>
        <p>
The package includes just the dll and xml documentation. The next task for the project
is to build an installer for both the source and binaries...
</p>
        <p>
This was a useful learning experience since I've based the Bluetooth code on the existing
model of the IrDA library, so it was useful to spend some time studying this
particular library and the classes it contains.
</p>
        <p>
The functionality is now part of 32feet.NET a library for personal area networking
for .NET. The downloads are here:-
</p>
        <p>
          <a href="http://inthehand.com/files/folders/releases/default.aspx">http://inthehand.com/files/folders/releases/default.aspx</a>
        </p>
        <img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=5a7b64d9-42ec-47b7-b25e-110c69a72218" />
      </body>
      <title>System.Net.IrDA for the desktop (Part 2)</title>
      <guid isPermaLink="false">http://peterfoot.net/PermaLink,guid,5a7b64d9-42ec-47b7-b25e-110c69a72218.aspx</guid>
      <link>http://peterfoot.net/SystemNetIrDAForTheDesktopPart2.aspx</link>
      <pubDate>Mon, 13 Dec 2004 22:08:45 GMT</pubDate>
      <description>&lt;p&gt;
Following my &lt;a href="/pfoot/PermaLink.aspx?guid=2f2c77ce-7724-4fa5-b69d-8de4180e5765"&gt;previous
post&lt;/a&gt;, I did some further development to the code to make it fully match the .NETCF
assembly (yes, in my haste I'd missed a few properties and cut a couple of corners).
So now I have compiled a System.Net.IrDA.dll assembly which has exactly the same classes
and methods as is available in device projects. So you can easily move device code
over to Tablet and laptop PCs.
&lt;/p&gt;
&lt;p&gt;
&lt;strike&gt;Download the DLL here&lt;/strike&gt;&amp;nbsp;(zip 7kb)
&lt;/p&gt;
&lt;p&gt;
The package includes just the dll and xml documentation. The next task for the project
is to build an installer for both the source and binaries...
&lt;/p&gt;
&lt;p&gt;
This was a useful learning experience since I've based the Bluetooth code on the existing
model of the IrDA library, so it was useful to spend some time studying&amp;nbsp;this
particular library and the classes it contains.
&lt;/p&gt;
&lt;p&gt;
The functionality is now part of 32feet.NET a library for personal area networking
for .NET. The downloads are here:-
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://inthehand.com/files/folders/releases/default.aspx"&gt;http://inthehand.com/files/folders/releases/default.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=5a7b64d9-42ec-47b7-b25e-110c69a72218" /&gt;</description>
      <category>Desktop Code</category>
    </item>
    <item>
      <trackback:ping>http://peterfoot.net/Trackback.aspx?guid=2f2c77ce-7724-4fa5-b69d-8de4180e5765</trackback:ping>
      <pingback:server>http://peterfoot.net/pingback.aspx</pingback:server>
      <pingback:target>http://peterfoot.net/PermaLink,guid,2f2c77ce-7724-4fa5-b69d-8de4180e5765.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Following on from a question which cropped up on today's MVP chat. I did some investigation
into IrDA support on the desktop framework. Turns out you can't use System.Net.IrDA.dll
from .NETCF on the desktop as I had read on some blog, but since the basic Socket
class supports the IrDA address family, it is necessary to build a couple of helper
classes for the IrDAEndPoint and IrDAClient and IrDAListener to match the .NETCF implementation.
I built these rather hastily and therefore have omitted a few overrides and non critical
items. I intend to flesh this out later to fully match the .NETCF class. However the
code zipped up below will give you the classes necessary to migrate your .NETCF IrDA
code to the desktop. It was tested using the sample code in the .NETCF Quickstart
on the subject to Discover my Pocket PC and send it a file. When I get the chance
I'll compile it into a System.Net.IrDA.dll, for now you'll have to make do with C#
source, and I didn't really stop to write comments this evening - sorry :)
</p>
        <p>
          <a href="http://www.inthehand.com/downloads/DesktopIrDA.zip">Download Source</a>
        </p>
        <img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=2f2c77ce-7724-4fa5-b69d-8de4180e5765" />
      </body>
      <title>System.Net.IrDA for the desktop</title>
      <guid isPermaLink="false">http://peterfoot.net/PermaLink,guid,2f2c77ce-7724-4fa5-b69d-8de4180e5765.aspx</guid>
      <link>http://peterfoot.net/SystemNetIrDAForTheDesktop.aspx</link>
      <pubDate>Thu, 09 Dec 2004 23:32:05 GMT</pubDate>
      <description>&lt;p&gt;
Following on from a question which cropped up on today's MVP chat. I did some investigation
into IrDA support on the desktop framework. Turns out you can't use System.Net.IrDA.dll
from .NETCF on the desktop as I had read on some blog, but since the basic Socket
class supports the IrDA address family, it is necessary to build a couple of helper
classes for the IrDAEndPoint and IrDAClient and IrDAListener to match the .NETCF implementation.
I built these rather hastily and therefore have omitted a few overrides and non critical
items. I intend to flesh this out later to fully match the .NETCF class. However the
code zipped up below will give you the classes necessary to migrate your .NETCF IrDA
code to the desktop. It was tested using the sample code in the .NETCF Quickstart
on the subject to Discover my Pocket PC and send it a file. When I get the chance
I'll compile it into a System.Net.IrDA.dll, for now you'll have to make do with C#
source, and I didn't really stop to write comments this evening - sorry :)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.inthehand.com/downloads/DesktopIrDA.zip"&gt;Download Source&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=2f2c77ce-7724-4fa5-b69d-8de4180e5765" /&gt;</description>
      <category>Desktop Code</category>
    </item>
    <item>
      <trackback:ping>http://peterfoot.net/Trackback.aspx?guid=5f8e31f9-139f-4d69-9aa0-b6d943a68208</trackback:ping>
      <pingback:server>http://peterfoot.net/pingback.aspx</pingback:server>
      <pingback:target>http://peterfoot.net/PermaLink,guid,5f8e31f9-139f-4d69-9aa0-b6d943a68208.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Following Neil's <a href="/ncowburn/PermaLink,guid,daae016b-ff5e-4e09-8782-d436492b83c7.aspx">recent
post </a>on my <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/HostingANativeWindowsControl.asp">control
hosting article</a>, I realised that the article had not gone into detail on the differences
between the Control class in the full framework and Compact Framework. The
Control class in the full .NET framework is incredibly powerful, and when I built
the ControlEx class to enable hosting I tried to work to the same model where possible.
Generally the Compact Framework follows the design of it's larger cousin and therefore
if the functionality of the Control class is enhanced in future revisions of
the Compact Framework it will likely follow a subset of the desktop functionality.
</p>
        <p>
There is a key difference with the Control class on the desktop, than any custom Control
derived class on the Compact Framework. On the desktop you can override the protected
CreateParams property to force the control to create any window class (remember that
in Win32 terms any control is considered a window with it's own unique handle and
based on a specific window class). It's possible to create an intrinsic windows control
like the SysAnimate32 with almost no need to resort to Platform Invoke. If you view
the running program with a tool like Spy++ you'll see the SysAnimate32 window is a
direct child of the form it sits on. We can pass it messages entirely in managed code
by simply calling it's WndProc method. The Handle property for the control is the
handle for the SysAnimate itself.
</p>
        <p>
On the Compact Framework this behaviour is only true for the standard set of Controls
in System.Windows.Forms. For all other controls a standard window class is created
(and this we have no control over), any native window class we wish to use must be
added as a child to this window. However the next main hurdle with the .NETCF Control
class is that there is no WndProc method we can override, so if we create a window
as a child of this control, we have no way of capturing it's window messages
(Unless we capture them in the application message loop itself using ApplicationEx).
Therefore to implement a WndProc for the control we use an additional layer.
</p>
        <p>
The MessageWindow class is specific to the Compact Framework and serves only one purpose,
it allows us to receive messages within managed code. By default the MessageWindow
is a hidden 0x0 pixel window. With some P/Invoke magic it is possible to alter the
size and position of the MessageWindow to make it a visible control - this is our
empty canvas. We now create the native window as a child of this window and we
have a native control, housed within a managed control with the ability to both send
messages to the control and, most importantly, receive notification messages and process
them.
</p>
        <p>
There are a few house-keeping chores required to keep this three-layer solution working.
Whenever the control is resized we must resize both the child (MessageWindow) and
grandchild (native control) to fit. In order to hide as much of this plumbing as possible,
and to avoid re-inventing the wheel, the ControlEx class was built to do all this
work for you. Like the Control class on the desktop it exposes a CreateParams property
which you can override with your class type. Notification messages received from the
native control by the MessageWindow are passed to the OnNotifyMessage method of the
ControlEx. It's not quite as powerful as the full WndProc of the desktop but it allows
us to receive events such as item selections within the native control. The WebBrowser
sample within the article download uses these to expose events when the user taps
a link.
</p>
        <p>
The HtmlViewer, MonthCalendar and InkX controls within SDF v1.2 are all built using
this technique, however they use a less transparent approach to the new ControlEx
class. I'll be upgrading these to use the ControlEx class, and of course you can use
the class yourself to wrap other native windows controls of your choice.
</p>
        <p>
You can <a href="http://www.inthehand.com/downloads/DesktopHosting.zip">download a
sample "Trash It!" project </a>here which is a desktop .NET project which wraps
the SysAnimate32 control to display a delete animation. The only P/Invoke required
is LoadLibrary / FreeLibrary to load the dll containing the AVI animation resource.
This should provide some contrast with the WebBrowser class in the article.
</p>
        <img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=5f8e31f9-139f-4d69-9aa0-b6d943a68208" />
      </body>
      <title>Hosting a Native Windows Control - The desktop approach</title>
      <guid isPermaLink="false">http://peterfoot.net/PermaLink,guid,5f8e31f9-139f-4d69-9aa0-b6d943a68208.aspx</guid>
      <link>http://peterfoot.net/HostingANativeWindowsControlTheDesktopApproach.aspx</link>
      <pubDate>Sat, 13 Nov 2004 21:11:42 GMT</pubDate>
      <description>&lt;p&gt;
Following Neil's &lt;a href="/ncowburn/PermaLink,guid,daae016b-ff5e-4e09-8782-d436492b83c7.aspx"&gt;recent
post &lt;/a&gt;on my &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/HostingANativeWindowsControl.asp"&gt;control
hosting article&lt;/a&gt;, I realised that the article had not gone into detail on the differences
between the Control class in the&amp;nbsp;full framework&amp;nbsp;and Compact Framework. The
Control class in the full .NET framework is incredibly powerful, and when I built
the ControlEx class to enable hosting I tried to work to the same model where possible.
Generally the Compact Framework follows the design of it's larger cousin and therefore
if the functionality of the Control class is&amp;nbsp;enhanced in future revisions of
the Compact Framework it will likely follow a subset of the desktop functionality.
&lt;/p&gt;
&lt;p&gt;
There is a key difference with the Control class on the desktop, than any custom Control
derived class on the Compact Framework. On the desktop you can override the protected
CreateParams property to force the control to create any window class (remember that
in Win32 terms any control is considered a window with it's own unique handle and
based on a specific window class). It's possible to create an intrinsic windows control
like the SysAnimate32 with almost no need to resort to Platform Invoke. If you view
the running program with a tool like Spy++ you'll see the SysAnimate32 window is a
direct child of the form it sits on. We can pass it messages entirely in managed code
by simply calling it's WndProc method. The Handle property for the control is the
handle for the SysAnimate itself.
&lt;/p&gt;
&lt;p&gt;
On the Compact Framework this behaviour is only true for the standard set of Controls
in System.Windows.Forms. For all other controls a standard window class is created
(and this we have no control over), any native window class we wish to use must be
added as a child to this window. However the next main hurdle with the .NETCF Control
class is that&amp;nbsp;there is no WndProc method we can override, so if we create a window
as a child&amp;nbsp;of this control, we have no way of capturing it's window messages
(Unless we capture them in the application message loop itself using ApplicationEx).
Therefore to implement a WndProc for the control we use an additional layer.
&lt;/p&gt;
&lt;p&gt;
The MessageWindow class is specific to the Compact Framework and serves only one purpose,
it allows us to receive messages within managed code. By default the MessageWindow
is a hidden 0x0 pixel window. With some P/Invoke magic it is possible to alter the
size and position of the MessageWindow to make it a visible control - this is our
empty canvas. We now create the native window as a child of this window&amp;nbsp;and we
have a native control, housed within a managed control with the ability to both send
messages to the control and, most importantly, receive notification messages and process
them.
&lt;/p&gt;
&lt;p&gt;
There are a few house-keeping chores required to keep this three-layer solution working.
Whenever the control is resized we must resize both the child (MessageWindow) and
grandchild (native control) to fit. In order to hide as much of this plumbing as possible,
and to avoid re-inventing the wheel, the ControlEx class was built to do all this
work for you. Like the Control class on the desktop it exposes a CreateParams property
which you can override with your class type. Notification messages received from the
native control by the MessageWindow are passed to the OnNotifyMessage method of the
ControlEx. It's not quite as powerful as the full WndProc of the desktop but it allows
us to receive events such as item selections within the native control. The WebBrowser
sample within the article download uses these to expose events when the user taps
a link.
&lt;/p&gt;
&lt;p&gt;
The HtmlViewer, MonthCalendar and InkX controls within SDF v1.2 are all built using
this technique, however they use a less transparent approach&amp;nbsp;to the new ControlEx
class. I'll be upgrading these to use the ControlEx class, and of course you can use
the class yourself to wrap other native windows controls of your choice.
&lt;/p&gt;
&lt;p&gt;
You can &lt;a href="http://www.inthehand.com/downloads/DesktopHosting.zip"&gt;download a
sample "Trash It!"&amp;nbsp;project &lt;/a&gt;here which is a desktop .NET project which wraps
the SysAnimate32 control to display a delete animation. The only P/Invoke required
is LoadLibrary / FreeLibrary to load the dll containing the AVI animation resource.
This should provide some contrast with the WebBrowser class in the article.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://peterfoot.net/aggbug.ashx?id=5f8e31f9-139f-4d69-9aa0-b6d943a68208" /&gt;</description>
      <category>NETCF</category>
      <category>Desktop Code</category>
    </item>
  </channel>
</rss>