Oct 29

image

You can add an application shortcut to the menu in the sample home screen in Windows Embedded Compact. Then, a user can click the shortcut to start your application. The application must be based on Silverlight for Windows Embedded.

After you add an application shortcut using these instructions, users can view and select your application in the main menu of the sample home screen.

To build a run-time image that uses the sample home screen

  1. Include the Silverlight for Embedded based Sample Home Screen catalog item (SYSGEN_XRSHELL) in your Windows Embedded Compact OS design.
  2. Create an OS design by using the Embedded Device with Silverlight XAML design template.

Next we add an application shortcut to the sample home screen:

To add an application shortcut to the sample home screen

Open  NotePad, and paste the following XML code into the text editor:

<?xml version="1.0" encoding="utf-8"?>
 <!--
 Copyright (c) Microsoft Corporation. All rights reserved.
 -->
 <!--
 Use of this sample source code is subject to the terms of the Microsoft
 license agreement under which you licensed this sample source code. If
 you did not accept the terms of the license agreement, you are not
 authorized to use this sample source code. For the terms of the license,
 please see the license agreement between you and Microsoft or, if applicable,
 see the LICENSE.RTF on your install media or the root of your tools installation.
 THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
 -->
 
<XRShellShortcut>
 
<Name _locId="IDName">Shortcut_Name</Name>
 <Description _locId="IDDescription">Shortcut_Description</Description>
 <Target>\Windows\application.exe</Target>
 <Args></Args>
 <Icon>
 <![CDATA[
 <Path xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation 
Data="F1M168.556,119.535L168.804,120.336C169.268,122.352,169.536,124.303,169.571,
1
26.264L169.519,127.503 167.379,131.946C164.669,136.934,161.492,141.63,157.905,145.976L153,
151.373 153,148.227 153,145.433 154.819,143.432C159.954,137.209,164.211,130.234,167.399,
122.697z M153,101.029C153,101.029,163.571,105.171,166.857,114.028L167.569,116.336 165.53,
121.907C162.419,129.262,158.265,136.069,153.254,142.142L153,142.421 153,130.948C153,115.406,
153,101.029,153,101.029z M90,77.5C83.096,77.5 77.5,83.096 77.5,90 77.5,96.904 83.096,102.5 90,
102.5 96.904,102.5 102.5,96.904 102.5,90 102.5,83.096 96.904,77.5 90,77.5z M90,76C97.732,76 104,
82.268 104,90 104,97.732 97.732,104 90,104 82.268,104 76,97.732 76,90 76,82.268 82.268,76 90,
76z M90,73.996C81.161,73.996 73.996,81.161 73.996,90 73.996,98.839 81.161,106.004 90,
106.004 98.839,106.004 106.004,98.839 106.004,90 106.004,81.161 98.839,73.996 90,73.996z M145.118,
63.013C145.118,63.013 148.096,63.013 148.096,63.013 148.929,68.966 149.048,76.47 155.241,
83.973 160.004,89.689 165.364,94.809 169.056,99.453 173.938,105.528 177.391,113.15 177.391,
120.891 177.391,133.277 171.438,145.541 167.387,152.33 167.387,152.33 165.482,152.33 165.482,
152.33 168.341,145.9 174.057,135.3 173.579,123.988 173.342,117.676 170.96,110.887 166.912,
105.886 162.386,100.05 154.763,95.405 148.096,94.93 148.096,94.93 148.096,162.453 148.096,
162.453 148.096,167.813 144.88,172.695 140.236,176.268 135.71,179.84 129.754,181.984 124.516,
181.984 121.18,181.984 118.083,180.913 115.941,179.125 113.678,177.339 112.368,174.72 112.368,
171.624 112.368,166.742 115.702,161.857 120.228,158.286 124.754,154.593 130.469,152.212 135.233,
152.212 139.402,152.212 142.974,152.808 145.118,154.831 145.118,154.831 145.118,63.013 145.118,
63.013z M90,61.988C105.47,61.988 118.012,74.53 118.012,90 118.012,105.47 105.47,118.012 90,
118.012 74.53,118.012 61.988,105.47 61.988,90 61.988,74.53 74.53,61.988 90,61.988z M90,
60C73.431,60 60,73.431 60,90 60,106.569 73.431,120 90,120 106.569,120 120,106.569 120,90 120,
73.431 106.569,60 90,60z M90,8.028C135.272,8.028,171.972,44.728,171.972,90L171.671,
95.963 167.342,91.008C163.169,86.436 159.143,82.186 157,78.686 154.091,73.934 151.429,5
9 151.429,59 151.429,59 140.964,59 140.964,59 140.964,59 140.964,148.714 140.964,148.714 140.964,
148.714 133.286,146.571 125.714,150 118.143,153.429 110.398,158.075 108.429,167.857L108.183,
169.879 106.52,170.307C101.184,171.399 95.659,171.972 90,171.972 50.387,171.972 17.337,
143.874 9.693,106.52L9.461,105 10.226,105C16.781,105 43,105 43,105 51.284,105 58,98.284 58,
90 58,81.716 51.284,75 43,75 43,75 16.781,75 10.226,75L9.461,75 9.693,73.48C17.337,36.126,
50.387,8.028,90,8.028z M90,2C138.601,2 178,41.399 178,90 178,93.038 177.846,96.039 177.546,
98.997L176.97,102.772 176.25,101.655 173.587,98.171 174,90C174,43.608 136.392,6 90,6 43.608,
6 6,43.608 6,90 6,136.392 43.608,174 90,174 95.799,174 101.461,173.412 106.929,172.293L108.084,
171.996 108.171,174.076 108.593,175.991 107.735,176.212C102.006,177.384 96.075,178 90,178 41.399,
178 2,138.601 2,90 2,41.399 41.399,2 90,2z"
UseLayoutRounding="False" Stretch="Fill" Margin="4,0" > <Path.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#4CFFFFFF" Offset="1"/> </LinearGradientBrush> </Path.Fill> </Path> ]]> </Icon> </XRShellShortcut>
 

In the <Icon> element of the XML code, the CDATA section contains a Silverlight XAML Path element that represents the icon to use for the application shortcut.

In the <Name> element, change Shortcut_Name to the name of the shortcut for your application.

In the <Description> element, change Shortcut_Description to the description of your application.

In the <Target> element, change application.exe to the name of the .exe for your application.

Save the file as an .xrsl file.  name the file with the conventions Custom_Application.xrsl.

Open main_default.xml, located in %_WINCEROOT%\PUBLIC\SHELL\OAK\XRSHELL\SRC. Add the following code to main_default.xml

<!--
 ; @CESYSGEN IF IE7_MODULES_IEEXR_MEDSCR
 -->
 <Item Widget="Main_Item">
 <File>Custom_Application.xrsl</File>
 </Item>
 <!--
 ; @CESYSGEN ENDIF
 -->

In the FILES list of the shell.bib file, add an entry for the .xrsl file. If the shortcut should only appear if a specific SYSGEN or component is included in the run-time image, put the entry inside a Cesysgen conditional statement.

; @CESYSGEN IF MEDIAAPPS_MODULES_MMPLAYER
 Custom_Application.xrsl $(_FLATRELEASEDIR)\Custom_Application.xrsl NK SH
 ; @CESYSGEN ENDIF

 

  • Open shell.dat, located in %_WINCEROOT%\PUBLIC\SHELL\OAK\FILES.
  • In the shell.dat file, locate the section titled: “Shortcuts for binaries built before shell in _DEPTREES, should be added here.”
  • Add an entry for the shortcut under that section. If the shortcut should only appear if a specific SYSGEN or component is included in the run-time image, put the entry inside a Cesysgen conditional statement.
; @CESYSGEN IF MEDIAAPPS_MODULES_MMPLAYER
 Directory("\XRShell\__Storage\Main"):-File("Custom_Application.xrsl", 
"\windows\Custom_Application.xrsl") ; @CESYSGEN ENDIF

Rebuild the run-time image. The next time you download the run-time image to your hardware board or Virtual CEPC, the application shortcut will be included in the menu in the sample home screen.

Customizing Menu Appearance (Main or Settings)

You can configure the menu to display only the icon for each item, without a menu item name or description text. However, if you don't provide a text string for the Name or Description element in the .xrsl file, the menu item will display the default text from the source XAML file.

to create menu items that are icons without showing default text, you must set a Text attribute for the Description and Name elements. The Text attribute must be set to an empty string with a single space. 

<Description_locId="IDName"Text=" "/>

To change the order of menu items in the sample home screen, re-order the menu items in the following files:

For the menu items in the main page, re-order elements in %_WINCEROOT%\PUBLIC\SHELL\OAK\XRSHELL\SRC\Main_Default.xml.

For the menu items in the settings page, re-order elements in %_WINCEROOT%\PUBLIC\SHELL\OAK\XRSHELL\SRC\Setting_Default.xml.

Elements that are defined closer to the beginning of the XAML file appear first in the menu, and elements that are defined toward the end of the XAML file appear last in the menu.

Widgets

A widget is an icon that appears in the notification area on the home screen which the user clicks to view or adjust settings for the device. The sample home screen provides five widgets: clock, Wi-Fi status, Bluetooth status, power (battery) status, Bluetooth wireless technology status, and volume status.

Attaching a custom settings application to the power (battery) status widget

For the power (battery) status widget, you must create a power management settings application that reflects the power states and battery power solution that you implemented. Then, you must attach it to the power (battery) status widget so that it appears when the user clicks the power (battery) status widget. Windows Embedded Compact 7 does not include a default power (battery) XAML control panel.

After you create a power management control panel application that is based on Silverlight XAML, you must modify the call to the LaunchApplication function in the source code for the widget’s OnClick event handler in

%_WINCEROOT\public\shell\oak\xrshell\controls\power
\status_itempower.cpp.

To launch your application when the user clicks the power (battery) widget, set the second parameter of LaunchApplication to a string that contains the GUID for your control panel application.

An event handler to do this would look something like this:

HRESULT Status_ItemPower::OnClick(__in IXRDependencyObject* pSender, 
__in XRMouseButtonEventArgs* pArgs) { MFUNCENTRY(ZONE_XRS_FUNCENTRY, (L"")); HRESULT hr = E_FAIL; HANDLE AppHandle = NULL; DWORD AppID = 0; CPR(pSender); CPR(pArgs); CHR( m_pShell->LaunchApplication(L"\\windows\\CtlPnl2.exe", L"", &AppHandle, &AppID) ); hr = S_OK; Error: return hr; }

Making A Custom Widget

Writing a custom status widget

To write a custom  widget that launches a settings application, see the volume status widget source code at:

%_WINCEROOT%\PUBLIC\SHELL\OAK\XRSHELL\CONTROLS\VOLUTME\Status_item_volume.cpp

The important APIs for implementing custom status widgets are as follows:

  • OnClick() function

This handles the Click event, which occurs when the user clicks the status widget. In the event handler implementation, you can launch additional functionality for configuring settings or details of the status widget

  • Start() function– Starts the widget. In the function implementation, you can add code to start activity to monitor status of a setting. For example, you can use status monitoring information to update the UI of the status widget to communicate status of its setting.
  • Stop() function – Stops the widget. In the function implementation, you can add code to stop activity to monitor status of a setting, because the shell is being closed and you should minimize memory and CPU usage.
  • Status widgets on the sample home screen are controlled by three functions:
  • InitializeFromXmlReader() – Creates the object and initializes it by using the XML Reader. Source can be found inside
    %_WINCEROOT\PUBLIC\SHELL\OAK\XRSHELL\INC\launch_item.cpp.
  • OnLoaded() – You can add custom code in the function implementation for a custom widget that indicates how you want the control to respond to user interaction, for example if it is a button, you can add an OnClick event handler. Each status widget in the sample home screen implements OnLoaded.
  • Setup() – Initializes each widget. 
      see shellwidgetmanager.cpp in

%_WINCEROOT\public\shell\oak\xrshell\src\shellwidgetmanager.cpp.

If the user wants to implement a custom setup solution for a widget, you must initialize the widget object similarly to the code in the ShellWidgetManager::InitAll function.

Oct 29

image

Is there a  version of Silverlight that works with embedded  systems and works with C++ native code ? Survey says yes..

Silverlight for Windows Embedded is a native (C++ based) user interface (UI) development framework for Windows Embedded Compact powered devices and is based on Microsoft Silverlight 3.

Silverlight for Windows Embedded offers a comprehensive C++ API that is fully-compatible with XML-based declarative markup and has no dependency on the .NET Framework.
With Silverlight for Windows Embedded, embedded OEMs can either completely predefine the visual appearance, effects, and behavior in source XAML, or use the C++ programming model to create or customize the UI appearance and functionality for the shell and applications.

 

Developers can use the Silverlight C++ API to load and display an existing XAML UI, implement event handling for the XAML elements, or customize the UI at run-time by adding new elements or changing the visual appearance to respond to factors present at run-time.

To enable interaction with the XAML UI at run-time, Silverlight for Windows Embedded provides Win32 support for hosting the Silverlight visual tree. It also uses the same visual tree to store new objects added by C++ application code at run time.

Silverlight for Windows Embedded is interoperable with Microsoft Expression Blend 3 and provides tools to generate template application code based on Expression Blend 3 XAML projects.

image

Silverlight for Windows Embedded provides helper template methods that automate safe implicit-type conversion of generic object types. The Silverlight for Windows Embedded programming model provides a visual host that hosts a Silverlight visual tree in a Win32 window. To handle UI events, you can attach C++ delegates to UI objects through methods available on various classes in the C++ API.

With Silverlight for Windows Embedded, you can create a Silverlight application for an embedded device, create and add custom user controls to your application, add Win32 controls to your application, and support hardware-accelerated graphics in the OS.

Capabilities of Silverlight for Windows Embedded

  • Define visual UI for applications in XAML.
  • Collaborate with designers by using XAML projects.
  • Separate programming logic and UI design.
  • Add, modify, and customize the UI at run time.
  • Create interactive multimedia UI.

Silverlight is compatible with Silverlight 3 XAML and provides a set of equivalent classes for supported XAML elements.

Silverlight and C++

Silverlight for Windows Embedded, allows you to create a UI that provides advanced visual effects, for your Windows Embedded Compact device shell and applications. Silverlight makes this possible by supporting a subset of Silverlight 3 XAML elements and by supplying a set of C++ classes that provide access to these elements.
Silverlight for Windows Embedded parses XAML UI and loads it into a C++ object tree. Then, it integrates the C++ objects with the Graphics, Windowing, and Events (GWES) subsystem to provide UI for Windows Embedded Compact devices.

Benefits

  • Silverlight C++ API and programming model that integrates with the Windows Embedded Compact operating system. This helps shorten the learning curve for developers familiar with programming in C++ for Windows Embedded Compact.
  • C++ classes that developers can use to create or customize visual appearance and behavior of UI elements.
  • Support for advanced UI features including gradients, transformations, and animations, so that developers can create interactive Silverlight-based controls in UI for embedded applications.

Supported Silverlight UI Features

Advanced Graphics

Graphics capabilities include brushes that produce gradient multicolor blend effects, image brushes that can paint the interior of UI elements, and also transforms, which are used to rotate, scale, translate, or skew UI elements. Three-dimensional (3-D) graphics capabilities include 3-D transforms, which transform UI elements in three-dimensional space.

Layout System

The layout system handles the tasks of drawing, resizing, and positioning UI elements on the graphical window. This removes the responsibility of the developer to draw and size elements on-screen using C++ code. Silverlight supports layout container objects that work with the layout system to intelligently manage the arrangement of UI elements on-screen at run time.

Animation, Timers, and Storyboards
With animation storyboards, UI elements can appear to dynamically change or move on the screen. This is achieved by quickly cycling through a series of images, or key frames, each slightly different from the previous one, over a specified duration of time. This visual effect can be achieved by defining each key-frame C++ object and implementing an animation storyboard.

Pixel Effects
Pixel effects modify the appearance of UI element, for example, by blurring the appearance of an element or adding a drop shadow. Pixel effects usually require hardware acceleration to make the graphics processing done by effects as fast as possible.

Text and Typography

Text controls and typography can both be used to display text in a Silverlight–based application. You can customize the display of text and provide unique customizations by changing visual properties, layout, or applying transforms to the text. With built-in support for the XML Paper Specification (XPS), you can also use predefined glyphs in the Silverlight UI. A glyph is a rendered image that is a visual representation of a character in a font.

New Controls
Silverlight for Windows Embedded introduces new Silverlight controls to Windows Embedded Compact developers, such as user controls, content controls, grids, canvas, paths, rectangles, and password boxes, which each inherit from the intermediate base class IXRFrameworkElement. Silverlight also provides intermediate base classes specifically intended for creating custom controls.

XAML DESIGNER WORKFLOW

Silverlight for Windows Embedded provides embedded developers and XAML designers with the API and tools for creating advanced UI. With Silverlight, OEMs can use the C++ Silverlight programming model to create UI element, graphics, and animations that leverage blend effects, weights, shadows, and gradients.

OEMs can work closely with XAML designers who use Expression Blend 3 to develop customized device UI for both the shell and applications.

XAML designers can design UI with XAML by using Expression Blend 3, and embedded developers can develop UI functionality in C++ by using Platform Builder.
.

image

Win32 Control Compatibility

Silverlight for Windows Embedded is compatible with Win32 controls developed in previous versions of Windows CE.

With Win32 control compatibility, you can add window controls, such as the ComboBox, Button, or ListBox, to the Silverlight object tree at run time, without having to rewrite or change the source code for your window controls.

Visual Hosts and Visual Trees

A visual host represents a Silverlight visual tree in a Win32 window. The concept of a visual host is unique to Silverlight for Windows Embedded. Silverlight for Windows Embedded is a framework which uses Win32 and C++ programming, unlike Silverlight 3 which is based on the .NET Framework and uses managed code. All visual elements parsed from XAML are stored in a visual tree, and only one visual tree can belong to one visual host. By loading XAML markup into a visual tree that belongs to a visual host, you can populate the on-screen content for the UI of a Silverlight for Windows Embedded application. Then a Silverlight for Windows Embedded application can search, modify, and add to the XAML elements in the visual tree with C++ code. For more information about visual trees, see Silverlight Object Trees at MSDN.

http://msdn.microsoft.com/en-us/library/cc189034(VS.95).aspx

Host Windows

To access the host Win32 window, first call IXRVisualHost::GetContainerHWND to retrieve an HWND, and then call Windows Embedded Compact Win32 functions that take an HWND as a parameter, such as UpdateWindow, IsChild, or SetParent. Having access to the host's window handle allows you to call Win32 functions directly in Silverlight for Windows Embedded, which is a feature that is not available in Silverlight 3. The visual host provides event handling at run time for objects stored in the Silverlight visual tree.

Handling Events

The way that you use events and delegates in Silverlight for Windows Embedded is different from Silverlight 3 for web applications. In Silverlight for Windows Embedded, you can attach C++ delegates to UI objects through Add*EventHandler methods, in order to handle events.

In contrast, in Silverlight 3 you attach event handlers in XAML attributes or by using the common language runtime (CLR) event model in C#.

Creating Event Handlers

To create an event handler in Silverlight for Windows Embedded, you first define a class that contains all the event handlers for your application, and then define event handlers for the events you want to handle.  Once you have implemented an event handler, you can create a delegate, and then attach the delegate to an event of a UI object.

Sample Event Handler in Native C++
(note there is no security or signing in this example that are required):

HRESULT OnMouseEnter(IXRDependencyObject* pSender, XRMouseEventArgs* pArgs)
{
IXRUIElementPtr pUIElement;
bool Captured = false;
if((NULL == pSender) || (NULL == pArgs))
{
hr = E_INVALIDARG;
}
else
{
// Get XRMouseEventArgs.Position from the event data and
// add code for additional position processing
XRPoint Position = pArgs->Position;
// Get the object sender and call IXRUIElement::CaptureMouse
pSender->QueryInterface(IID_IXRUIElement, &pUIElement);
pUIElement->CaptureMouse(&Captured);
hr = S_OK;
}
return hr;
}

Retrieving event data

An event handler must accept an XREventArgs derived structure that contains event data. Silverlight for Windows Embedded provides a variety of such event structures that contain data for specific types of events. As long as it reflects the appropriate event type, you can use any XREventArgs-derived structure in the method signature for your custom event handler. Then, you can extract data from the structure to determine information about the event. For example, XRMouseEventArgs provides a Position member that describes the x-coordinate and y-coordinate for the position on the screen where the mouse event occurred.

Modifying Other UI Elements in Event Handling Code

An event handler takes two input parameters: the object sender and an event data structure. To access or modify an object in the visual tree other than the object sender, you need a pointer to the visual host. To access the visual host in event-handling code, you can create a SetHost custom method in your event class that sets the pointer to the visual host to a variable in the event class. Then, you can use that variable to access the visual host in any event handlers in your class.

Add an Event Handler to Parsed XAML Elements

In Silverlight for Windows Embedded, you cannot add names of C# event handlers to XAML elements by using event handler syntax for an attribute of the element.

Instead, you must find each named element at run time and add event handlers to them by using the Add*EventHandler methods. To do this, you must retrieve an object pointer to each named element from the visual tree. For more information about the visual tree, see "Working with Visual Hosts and Visual Trees in Silverlight for Windows Embedded" earlier in this cookbook.

For a list of Add*EventHandler methods available in each object, see the Silverlight for Windows Embedded reference documentation for that object.

X:NAME
You must know the x:Name values for each element that raises events to add an event handler to a parsed element. The x:Name values are defined in the source XAML file.

Recommended Device Specifications for Silverlight for Windows Embedded

image

Hardware Guidelines

    • ARM V6 with Vector Floating Point Unit (VFPU)
    • 550 megahertz (MHz) processor
    • 256 MB RAM
    • 2-D or 3-D Graphics Processing Unit (GPU) with a DirectDraw or an OpenGL interface

For DirectDraw

    • a GPU or video hardware
    • Per-pixel and constant alpha blits
    • Premultiplied alpha blits
    • Hardware-accelerated alpha blits
    • Hardware-accelerated blits on raster operations that use raster-operation code SRCCOPY between system-video and video memory
    • Hardware-accelerated stretch blits for raster operations that use raster-operation code SRCCOPY
    • Hardware-accelerated color fill
    • 20 MB video memory (or system memory that a GPU can directly operate)

For OpenGL

    • you have an OpenGL driver that supports the OpenGL Embedded Systems (ES) 2.0 specification
    • It should pass the Khronos conformance tests. For more information, see the Khronos Group Web site.
    • Additionally it should support a simple vertex and fragment shader that matches the platform's GPU and is linked to a file named Shaders.dll.
    • Support run-time compilation of the default shader source code in Windows Embedded Compact.

More to follow in Future Posts..