Sie sind auf Seite 1von 19

HP TouchSmart SDK Development Documentation –

WPF-based Hosted Application 3.0 Library


A User’s guide for developers
PLEASE READ CAREFULLY: USE OF TOUCHSMART SDK DEVELOPMENT
DOCUMENTATION AND SOFTWARE AVAILABLE AT THIS SITE IS SUBJECT TO THE
TERMS AND CONDITIONS THAT FOLLOW. IF YOU AGREE TO THESE TERMS, PLEASE
CHOOSE THE “I ACCEPT” OPTION LOCATED ADJACENT TO THE SCREEN WHERE THIS
AGREEMENT IS DISPLAYED. IF YOU DO NOT AGREE TO THESE LICENSE TERMS, PLEASE
CHOOSE THE “I DO NOT ACCEPT” OPTION AND DO NOT DOWNLOAD THE SDK
DEVELOPMENT DOCUMENTATION AND SOFTWARE FROM THIS SITE.

HP TOUCHSMART SDK DEVELOPMENT DOCUMENTATION AND SOFTWARE LICENSE AGREEMENT

This HP TouchSmart SDK Development Documentation and Software License Agreement (the
“Agreement”) is a legal agreement between (a) you, either as an individual or a single entity,
(“Licensee”) and Hewlett-Packard Company (“HP”) that governs your use of the SDK Development
Documentation and HP software (“Licensed Software”) made available by HP.
USE OF THIS TOUCHSMART SDK DEVELOPMENT DOCUMENTATION AND SOFTWARE IS
OFFERED ONLY ON THE CONDITION THAT YOU AGREE TO ALL TERMS AND
CONDITIONS OF THIS AGREEMENT. BY DOWNLOADING, COPYING, OR USING THE
TOUCHSMART SDK DEVELOPMENT DOCUMENTATIONAND\OR SOFTWARE YOU AGREE
TO BE BOUND BY THE TERMS OF THIS AGREEMENT. IF YOU DO NOT ACCEPT THIS
AGREEMENT, DO NOT USE THE TOUCHSMART SDK DEVELOPMENT DOCUMENTATION
AND SOFTWARE.

1. DEFINITIONS.

“HP TouchSmart Software Environment” means the software interface that runs on the HP TouchSmart line
of personal computer products, which enables the use of a Microsoft Windows operating system and
compatible application software by means of touching the display screen to launch and use such software.

“Licensed Software” means the software programs owned or distributed by HP and licensed to Licensee
under the Agreement.

“Licensee’s Programs” means those software applications developed by Licensee using or with reference to
the TouchSmart SDK Development Documentation and/or Licensed Software that are intended to operate
with HP TouchSmart line of personal computer products and designed to launch from within the HP
TouchSmart Software Environment.

2. LICENSED SOFTWARE. The Licensed Software contains a collection of source code and binary code that
permits Licensee to develop Licensee’s Programs that operate with HP’s TouchSmart line of personal
computer products, which enables the use of a Microsoft Windows operating system and compatible
application software by means of touching the display screen to launch and use such software. The
Licensed Software contains:

Two TouchSmart sample applications, including code for each of the two applications
A sample Windows Installer XML template for creating an MSI
A blank WPF application template for creating TouchSmart applications

3. LICENSE GRANT. HP grants Licensee a non-exclusive, non-transferable, revocable license to use the
TouchSmart SDK Development Documentation solely for development and testing of Licensee’s Programs
as defined herein. HP further grants Licensee a non-exclusive, non-transferable, revocable license in the
Licensed Software to (i) use one copy solely for development and testing of Licensee’s Programs as defined
herein and (ii) reproduce, modify, and distribute only those parts of the Licensed Software incorporated
into Licensee’s Programs, and only in binary form. Licensee shall not use the Licensed Programs for any
other purpose.

4. OWNERSHIP. The TouchSmart SDK Development Documentation are owned and copyrighted by HP. The
Licensed Software is owned and copyrighted by HP or its third party suppliers. This Agreement confers no
title or ownership in the TouchSmart SDK Development Documentation or the Licensed Software and is not
a sale of any rights in the TouchSmart SDK Development Documentation or the Licensed Software.
Licensee will own Licensee’s Program created solely for the purpose described above; provided however,
nothing herein shall prevent HP or its partners, resellers or customers from implementing the same
functionality or independently creating the same or similar derivative work and therefore you grant to HP a
perpetual, irrevocable, sub-licensable, world-wide license to the derivative work for the purpose of
permitting HP or its partners, resellers or customers to independently implement the same functionality or
create the same or similar derivative work. HP’s third party suppliers may protect their rights in the event
of any violation of these License Terms.
5. COPIES. Licensee may only make copies of the TouchSmart SDK Development Documentation for
archival purposes or, if you are a company, for use by your employees to develop or test Licensee’s
Programs as permitted in this Agreement. Licensee may only make copies or adaptations of the Licensed
Software for archival purposes or when copying or adaptation is an essential step in the authorized use of
the Licensed Software. You must reproduce all copyright notices in the TouchSmart SDK Development
Documentation and the Licensed Software and all copies and adaptations thereof. Licensee may not copy
the TouchSmart SDK Development Documentation or the Licensed Software onto any bulletin board, web
site, or other publicly available repository, or otherwise distribute them to third parties, unless otherwise
stated herein. You may not modify or make derivative works of the TouchSmart SDK Development
Documentation.

6. NO DISASSEMBLY OR DECRYPTION. You may not disassemble, decompile or decrypt any object code
portions of the Licensed Software unless it is an essential step in the authorized use of the Licensed
Software. In some jurisdictions, HP’s consent may not be required for disassembly or decompilation.

7. CONFIDENTIAL INFORMATION. The Licensed Software is the confidential information of HP and you will
treat it with the same degree of care, but no less than reasonable care, as you take to safeguard your own
confidential information of a like kind from unauthorized use or disclosure.

8. TRANSFER. You may not assign, rent, lease or otherwise transfer the TouchSmart SDK Development
Documentation or the Licensed Software.

9. TERMINATION. This Agreement is effective until terminated or rejected. HP may terminate your license
upon notice for failure to comply with any of the terms of this Agreement. Upon termination, you must
immediately destroy the TouchSmart SDK Development Documentation and the Licensed Software,
together with all copies in any form.

10. U.S. GOVERNMENT RESTRICTED RIGHTS. The TouchSmart SDK Development Documentation and the
Licensed Software have been developed entirely at private expense and are provided as “Commercial
Computer Software” or “restricted computer software”. Use, duplication or disclosure by the U.S.
Government or a U.S. Government subcontractor is subject to the restrictions set forth in subparagraph (c)
(1) (ii) of the Rights in Technical Data and Computer Software clauses in DFARS 252.227-7013 or as set forth
in subparagraph (c) (1) and (2) of the Commercial Computer Software – Restricted Rights clauses at FAR
52.227-19, as applicable. The Contractor is Hewlett-Packard Company, 3000 Hanover Street, Palo Alto,
California 94304.

11. GOVERNING LAW. The Agreement shall be construed and interpreted in accordance with the law of
the State of New York (except choice of law rules).

12. NO WARRANTY. THE TOUCHSMART SDK DEVELOPMENT DOCUMENTATION AND THE LICENSED
SOFTARE ARE PROVIDED “AS IS,” WITH ALL FAULTS, AND WITHOUT WARRANTY OF ANY KIND. HP HEREBY
DISCLAIMS ALL WARRANTIES AND CONDITIONS, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING,
BUT NOT LIMITED TO, WARRANTIES OF TITLE AND NON-INFRINGEMENT, ANY IMPLIED WARRANTIES,
DUTIES OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
COMPLETENESS. YOU ASSUME THE ENTIRE RISK RELATING TO THE USE OR PERFORMANCE OF THE
TOUCHSMART SDK DEVELOPMENT DOCUMENTATION AND THE LICENSED SOFTWARE.

13. NO SUPPORT. HP does not provide support for the TouchSmart SDK Development Documentation and
the Licensed Software or their uses. HP will not provide assistance for the development or testing of
Licensee’s Programs, or support for Licensee’s Programs to end users.

14. NO OTHER OBLIGATIONS. HP’s obligations with respect to its products and services are governed
solely by the agreements under which they are provided and nothing in this Agreement alters such
agreements. HP may make changes to the HP TouchSmart Development Environment, the TouchSmart SDK
Development Documentation, Licensed Software, or the products described in them, at any time without
notice. The TouchSmart SDK Development Documentation and the Licensed Software may be out of date,
and HP makes no commitment to update them.

15. LIMITATION OF LIABILITY. IN NO EVENT SHALL HP BE LIABLE FOR ANY DIRECT, INDIRECT, GENERAL,
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING BUT NOT LIMITED TO DAMAGES FOR
LOSS OF PROFITS OR CONFIDENTIAL OR OTHER INFORMATION, FOR BUSINESS INTERRUPTION, FOR
PERSONAL INJURY, FOR LOSS OF PRIVACY ARISING OUT OF OR IN ANY WAY RELATED TO THE USE OR
INABILITY TO USE THE TOUCHSMART SDK DEVELOPMENT DOCUMENTATION, HOSTED APPLICATIONS,
LICENSED SOFTWARE AND/OR LICENSEE’S PROGRAMS OR OTHERWISE, WHETHER BASED ON CONTRACT,
TORT OR ANY OTHER LEGAL THEORY EVEN IF HP HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES AND EVEN IF THE REMEDY FAILS OF ITS ESSENTIAL PURPOSE.

16. CAPACITY AND AUTHORITY TO CONTRACT. You represent that you are of the legal age of majority in
your state of residence and, if applicable, you are duly authorized by your employer to enter into this
Agreement.

17. ENTIRE AGREEMENT. This Agreement is the entire agreement between you and HP relating to the
TouchSmart SDK Development Documentation and the Licensed Software and supersedes all prior or
contemporaneous oral or written communications, proposals and representations with respect to the
TouchSmart SDK Development Documentation, Licensed Software, or any other subject matter covered by
this Agreement.

© 2009 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
The only warranties for HP products and services are set forth in the express warranty statements accompanying such
products and services. Nothing herein should be construed as constituting an additional warranty. HP shall not be liable for
technical or editorial errors or omissions contained herein.
1. Introduction
This document describes a Windows Presentation Foundation (WPF) library released by the HP
TouchSmart software core team to simplify the creation of applications written for the TouchSmart
software environment (SmartCenter.exe version 2.8 and later).

The library makes it easier for the application developer to focus on the functionality and features
specific to the hosted application by implementing many of the requirements that must be met when
writing a SmartCenter hosted application.

This document assumes that the reader is familiar with both WPF and C# and plans to write a hosted
WPF application in C#.

2. Functionality overview
The library helps to take care of the following hosted application requirements:

Definition of a single, chrome-less window to exist for the lifetime of the application
Support for the “chromeless” command-line argument meant to suppress accidental launch of
the application when not hosted by SmartCenter.exe
Initial off-screen launch
Events and WPF Application-level Resource Dictionary changes to help react to
o required layout changes (Small, Medium, Large, Minimized, Idle)
o theme changes (colors and background image)
o dual touch
Events to help react to registered window messages that SmartCenter uses to communicate
state information to the hosted application
Exclusion of the hosted application from Alt+Tab and Task Manager’s application list

The library also provides functionality for the following common hosted application needs:

Running in “debug” mode for testing layout changes using interactive window sizing with the
mouse/touch
Loading of localized string resource dictionaries based on CurrentUICulture or CurrentCulture
Turning on .NET trace functionality via trace switch “SC” in app.config
Disabling tablet gestures
Basic Restart Manager awareness
Creating messages for the SmartCenter notification area
Creating request files for SmartCenter

Things that are NOT provided by the library:


Styles for UI look and feel
Common/useful touch optimized controls

3. Library details
The library is installed in the Global Assembly Cache (GAC) as part of the factory software build starting
with version 2.8 of SmartCenter.exe. It is identified by the following Assembly string:

HP.TouchSmart.InfoviewWindow,Version=1.0.0.0,Culture=neutral,PublicKeyToken=436e80ff5a6fd94d

For SmartCenter.exe starting with version 3.0, the Assembly is identified by:

HP.TouchSmart.InfoviewWindow,Version=1.1.0.0,Culture=neutral,PublicKeyToken=436e80ff5a6fd94d

To use the library in your project, include a reference to it in your Visual Studio project and add a using
statement for convenience:

using HP.TouchSmart.Library;

You have to add the reference by unloading the project in Solution Explorer, manually editing the .csproj
file and adding the following line into an <ItemGroup> element (find the one that has the System and
System.Core includes already):

<Reference Include="HP.TouchSmart.InfoviewWindow" />

3.1. Creating a hosted application main window


After adding the necessary reference and using statement (as described above), creating a hosted
application main window is done by inheriting the InfoviewWindow class in the (single/only) window
the hosted application creates:

public partial class Window1 : InfoviewWindow


{
...
}

In the Window XAML file, you also need to map the library namespace like this:

xmlns:TS="clr-namespace:HP.TouchSmart.Library;assembly=HP.TouchSmart.InfoviewWindow"

Then change the root XAML element to this:

<TS:InfoviewWindow ... />

3.2. Layout change management


The application library provides two mechanisms that help with adjusting to the size and layout changes
that SmartCenter.exe initiates as the user manipulates the hosted application tile. The first mechanism
is a .NET event notification. The second is a set of resource elements in the application’s Application-
level Resource Dictionary.
To receive the event notification, subscribe and unsubscribe as appropriate to the
SmartCenterSupport.LayoutChanged event as follows:

SmartCenterSupport.LayoutChanged += new
EventHandler<HP.TouchSmart.Library.SCHelpers.LayoutChangedArgs>(SmartCenterSupport_LayoutChang
ed);

SmartCenterSupport.LayoutChanged -= new
EventHandler<HP.TouchSmart.Library.SCHelpers.LayoutChangedArgs>(SmartCenterSupport_La
youtChanged);

Then handle the event like this:

private void SmartCenterSupport_LayoutChanged(object sender,


HP.TouchSmart.Library.SCHelpers.LayoutChangedArgs e)
{
// This demonstrates accessing the Layout dependency property of the
// SmartCenterSupport object
Trace.WriteLine("New layout: " + this.SmartCenterSupport.Layout.ToString());
}

The event parameter LayoutChangedArgs provides the following enum values in the Layout member:

Idle, Minimum, Small, Medium, WideInteractive [3.0 only], Large

The Small, Medium, WideInteractive [3.0 only] and Large values can be used to show or hide UI
elements to produce the correct arrangement of displayed information for each layout. The Idle and
Minimum values can be used to adjust resource usage of the hosted application.

To use the Application-level Resource Dictionary elements for layout changes, reference the following
three Visibility resources in XAML:

LayoutVisibilitySmall
LayoutVisibilityMedium
LayoutVisibilityWideInteractive [3.0 only]
LayoutVisibilityLarge

For example:

<!-- This demonstrates how to use the Resources available through InfoviewWindow -->
<Grid x:Name="SmallLayout"
Visibility="{DynamicResource LayoutVisibilitySmall}">
<!-- This demonstrates how to use the XAML string resource loader in markup -->
<TextBlock Text="Small Layout"></TextBlock>
</Grid>

The values will be either Visible or Collapsed. Hidden is not used.

To use the Application-level Resource Dictionary elements for Idle and Minimum layout changes,
reference the following bool resources in XAML:
IdleMode
MinimumMode

The values will be true or false.

3.3. Theme change management (deprecated for 3.0)


SmartCenter theming consists of two potential entities: a “theme color” and a background picture. The
application library provides notification of theme change in the same manner as for layout change: by
.NET event and by resource dictionary element changes.

To receive the event notification, subscribe and unsubscribe as appropriate to the


SmartCenterSupport.ThemeChanged event as follows:

SmartCenterSupport.ThemeChanged += new
EventHandler<HP.TouchSmart.Library.SCHelpers.ThemeChangedArgs>(SmartCenterSupport_The
meChanged);

SmartCenterSupport.ThemeChanged -= new
EventHandler<HP.TouchSmart.Library.SCHelpers.ThemeChangedArgs>(SmartCenterSupport_The
meChanged);

Then handle the event like this:

private void SmartCenterSupport_ThemeChanged(object sender,


HP.TouchSmart.Library.SCHelpers.ThemeChangedArgs e)
{
Trace.WriteLine("Theme changed");
if (e.Theme.Valid)
{
Trace.WriteLine(e.Theme.BackgroundPicturePath);
Trace.WriteLine(e.Theme.PrimaryForegroundColor);
Trace.WriteLine(e.Theme.PrimaryBackgroundColor);
Trace.WriteLine(e.Theme.SecondaryForegroundColor);
Trace.WriteLine(e.Theme.SecondaryBackgroundColor);
}
}

The event parameter ThemeChangedArgs provides the following System.Windows.Media.Color fields


on the Theme member:

PrimaryForegroundColor, PrimaryBackgroundColor, SecondaryForegroundColor,


SecondaryBackgroundColor

In addition it also provides a string field on the Theme member:

BackgroundPicturePath

To use Application-level Resource Dictionary elements for theme changes, use the following resources in
XAML:
PrimaryForegroundColor
PrimaryBackgroundColor
SecondaryForegroundColor
SecondaryBackgroundColor

BackgroundPicture
BackgroundBrush

The four colors are of type System.Windows.Media.Color. The BackgroundPicture is of type string
and the BackgroundBrush is of type Brush.

For example:

<!-- This demonstrates how to bind against dependency properties in the


SmartCenterSupport object -->
<TextBlock>
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding ElementName=TheWindow,
Path=SmartCenterSupport.Theme.SecondaryForegroundColor}" />
</TextBlock.Foreground>
Text in SecondaryForegroundColor
</TextBlock>

Or

<!-- This demonstrates how to use color resources in markup -->


<TextBlock Text="Hello World!">
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource PrimaryForegroundColor}" />
</TextBlock.Foreground>
</TextBlock>

NOTE: SmartCenter positions the background picture with bottom left alignment and uses opacity fades
and gradient overlays to make the picture fade to black towards the top right. It is recommended to
mimic this approach in hosted applications for visual consistency.

The four theme colors make up two main color axes of the SmartCenter environment. In the current
implementation the PrimaryForegroundColor is white and the PrimaryBackgroundColor is black. While
these values are currently fixed, they may change in the future. The SecondaryBackgroundColor is
meant to define the “sheen” on themed elements like buttons. It is the “base” color for deriving
gradients for visually pleasing effects. Essentially, the base color defines the hue of the theme.
Saturation and lightness of this hue can be changed to arrive at gradient stop colors that make for a
good visual look.

Implementation details of deriving appropriate colors from the “base” color fall outside the scope of this
document, but sample code can be found in the HP TouchSmart Application Development Guidelines
previously published by HP (at the time of this writing available at
http://www.touchsmartcommunity.com/download/list). Please refer to the section in that document on
supporting the theme change event.
3.4. Dual touch (deprecated for 3.0)
Dual touch notifications also arrive by two mechanisms: .NET events and Application-level Resource
Dictionary element changes.

To receive the dual touch event, subscribe or unsubscribe as appropriate to the


SmartCenterSupport.TouchEvent event, as follows:

SmartCenterSupport.TouchEvent += new
EventHandler<HP.TouchSmart.Library.SCHelpers.TouchEventArgs>(SmartCenterSupport_Touch
Event);

SmartCenterSupport.TouchEvent -= new
EventHandler<HP.TouchSmart.Library.SCHelpers.TouchEventArgs>(SmartCenterSupport_Touch
Event);

Handle the event like this:

private void SmartCenterSupport_TouchEvent(object sender,


HP.TouchSmart.Library.SCHelpers.TouchEventArgs e)
{
Trace.WriteLine("Touch event: " + e.Touch.State.ToString() + " " +
e.Touch.FirstPoint.ToString() + " " + e.Touch.SecondPoint.ToString());
}

The event parameter TouchEventArgs delivers several points of information in the Touch member:

State: Up, Down, Move


FirstPoint
SecondPoint
Valid

State is a uint-based enum. FirstPoint and SecondPoint are System.Windows.Point structures.


Valid is a bool.

The Application level Resource Dictionary elements related to dual touch events are:

TouchVisibility
TouchPoint1
TouchPoint2

TouchVisibility is a System.Windows.Visibility enum, set to Visible when the State is Down or Move,
and set to Collapsed when the State is Up. TouchPoint1 and TouchPoint2 are
System.Windows.Point structures.
3.5. SmartCenter state change events (new for 3.0)
SmartCenter will communicate certain state changes to hosted applications via registered messages.
The library will handle these messages and turn them into .NET events, which are easier to subscribe to
than registered messages.

There are five notifications delivered by SmartCenter:

AppAttached: This lets the hosted application know that SmartCenter has attached to the
hosted application
MinimalResources: This lets the hosted application know that it should lower its use of
resources as low as possible
NormalResources: This lets the hosted application know that it should resume normal use of
resources to perform its design purpose
SmartCenterHomeView: This lets the hosted application know that SmartCenter is in the home
view, displaying tiles in medium or wide interactive sizes
SmartCenterLargeView: This lets the hosted application know that SmartCenter is showing a
hosted application in large view.
The large view hosted application window will be identified by the LargeWindow member of
AppEventArgs (see below). If the hosted application is the current application, the LargeMode
member of AppEventArgs will be true. If a different hosted application is in large view, the
LargeMode member of AppEventArgs will be false.

These notifications are part of an enum called AppNotification, an instance of which is called
Notification in the AppEventArgs class. The AppEventArgs class is the EventArgs-derived class
that the .NET event handler receives.

To receive notifications, subscribe or unsubscribe as appropriate to the


SmartCenterSupport.AppEvent event, using code like the following:

SmartCenterSupport.AppEvent += new
EventHandler<HP.TouchSmart.Library.SCHelpers.AppEventArgs>(SmartCenterSupport
_AppEvent);

SmartCenterSupport.AppEvent -= new
EventHandler<HP.TouchSmart.Library.SCHelpers.AppEventArgs>(SmartCenterSupport
_AppEvent);

Handle the event using code like this:

void SmartCenterSupport_AppEvent(object sender,


HP.TouchSmart.Library.SCHelpers.AppEventArgs e)
{

Trace.WriteLine("App event: " + e.Notification.ToString());

}
3.6. Loading localized string resources
The application library contains methods that help make localization of hosted applications a matter of
including appropriately named string resource dictionaries as part of the application binary. In addition
resources can also be loaded from loose files installed alongside the application.

To include localized strings, put all User Interface strings in a XAML file according to this example:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:mc="http://schemas.openxmlformats.org/markup-
compatibility/2006"
xmlns:localizationComment=
"http://schemas.hp.com/cpc/localization-comment"
mc:Ignorable="localizationComment"
>
<sys:String x:Key="strHelloWorld"
xml:space="preserve"
localizationComment:Comment=
"A localization comment for the translator"
localizationComment:MaxCharacters=
"Character limit comment"
>Hello World!</sys:String>
</ResourceDictionary>

Name this file according to the language identifier standards that WPF follows in the
System.Globalization.CultureInfo class (TwoLetterISOLanguageName and Name), for example
en.xaml for English, de.xaml for German or fr.xaml for French. You can also create language-country
specific files by using names such as en-gb.xaml or fr-fr.xaml.

The localized string loading mechanism will look for included resource files first. They must be placed in
the following folder structure in your project: /Resources/Strings/*.xaml.

If no included file is found in the hosted application binary at runtime, the loading mechanism will look
in a subfolder on the hard drive where the application is installed. This subfolder must be named “res”.

Language-country specific files will be loaded first, language-only files second, and as a fallback language
en.xaml will be loaded.

The method to call for loading resources according to the above is:

hp.SmartCenter.Lib.StringResourceLoader.LoadStringDictionaries(bool loadGarbledFile,
bool useUICulture);

The first parameter enables loading a specific file called “garbled.xaml”. This is useful for testing
localization omissions. The second parameter enables testing of localization by basing the loading on the
.NET CurrentCulture instead of CurrentUICulture. CurrentCulture is easier to change, since it
doesn’t require installing MUI language packs (which can only be done on Vista Ultimate SKUs.)
Passing in the appropriate value for useUICulture can be done based on command-line arguments, for
example along the lines of this:

private bool useUICulture = true;

string[] commandLineArgs = Environment.GetCommandLineArgs();


if (commandLineArgs.GetLength(0) > 3)
{
if (commandLineArgs[3].Equals("region",
StringComparison.InvariantCultureIgnoreCase))
{
this.useUICulture = false;
}
}

hp.SmartCenter.Lib.StringResourceLoader.LoadStringDictionaries(false,
this.useUICulture);

The following screenshot of a Visual Studio project illustrates the correct placement of included xaml
string dictionaries:

The files included as above must have a build action of “Page”.

In addition, the reader may wish to define the font family used for displaying strings based on locale by
defining appropriate resources within the locale-dependent XAML files. For example, double-byte
character sets should be displayed using a font that contains properly rendered glyphs for those
languages. The zh-cn culture might use SimSun, whereas zh-hk might use MingLiU, ko might use Malgun
and ja might use Meiryo. Such font changes can be made by defining a resource along the following:

<FontFamily x:Key="UIFontFamily">Meiryo</FontFamily>

This resource can then be used to define the font used in all text elements throughout the application.

To use strings from the loaded resource dictionary in XAML, use markup similar to this:

<TextBlock Text="{DynamicResource strHelloWorld}"></TextBlock>

To use strings from the loaded resource dictionary in code-behind, do something similar to this:
string helloWorldString = Application.Current.Resources["strHelloWorld"] as string;

3.7. Trace functionality


The application library includes functionality that lets developers output trace information to a log file
during execution of the hosted application. This functionality is turned on via standard .NET Framework
configuration files and uses .NET Framework features from the System.Diagnostics namespace. The
following app.config file snippet illustrates how to turn on the file tracing and how to select the level
of information that the library produces:

<?xml version="1.0" encoding="utf-8" ?>


<configuration>
<system.diagnostics>
<switches>

<!-- To enable generation of trace log file, set TraceFileEnabled value="1"-->


<add name="TraceFileEnabled" value="1"/>

<!-- Levels: 0=off, 1=error, 2=warning, 3=info, 4=verbose -->


<add name="SC" value="3"/>

</switches>
</system.diagnostics>
</configuration>

A hosted application can add its own <switches> sub-elements and use the .NET tracing facilities with
code like this:

private static TraceSwitch traceSwitch = new TraceSwitch("HostedApp", "HostedApp


tracing", "0");

if (traceSwitch.TraceInfo)
{
Trace.WriteLine(String.Format("A sample trace line."));
}

The tracing for the above code can be turned on using the following app.config snippet:

<add name="HostedApp" value="3"/>

The trace file will be placed in %ProgramData%\Hewlett-Packard\TouchSmart\SmartCenter 2.0 and


will have a name patterned according to this:

HP.TouchSmart.InfoviewWindow_[Time Application Started]_[User].log.txt

3.8. Notification Area messages


SmartCenter contains an area for notifying the user of events that happen in a hosted application. The
application library contains code that makes creation of these notifications simple.
The InfoviewWindow class contains a public property, SmartCenterSupport, which in turn contains a
function called Message(). When this function is invoked, a new notification will be created using the
MessageEventArgs.Message fields. The following fields exist on the Message member:

Text
Title
Valid
Expiration
Icon

The following shows an example implementation of a method body that creates a notification in
SmartCenter:

HP.TouchSmart.Library.SCHelpers.MessageEventArgs msgEventArgs = new


HP.TouchSmart.Library.SCHelpers.MessageEventArgs();

msgEventArgs.Message = new HP.TouchSmart.Library.SCHelpers.MessageClass();


msgEventArgs.Message.Text = "Message Text";
msgEventArgs.Message.Title = "A hosted application alert";
msgEventArgs.Message.Valid = true;

// Make sure the message doesn't expire right away


DateTime messageExpiration = (DateTime.Now + new TimeSpan(0, 30,
0)).ToUniversalTime();

msgEventArgs.Message.Expiration = messageExpiration.ToString();

// Icon can be: "Asterisk", "Error", "Exclamation", "Hand" or string.Empty


msgEventArgs.Message.Icon = "Asterisk";

this.SmartCenterSupport.Message(this, msgEventArgs);

The icons used in the SmartCenter notification area look like this:

Asterisk (deprecated in 3.0) / CircleCheck in 3.0

Error (deprecated in 3.0) / CircleX in 3.0

Exclamation
Hand (deprecated in 3.0) / Clock in 3.0

3.9. Requesting actions from SmartCenter


In addition to notifications, SmartCenter also makes it possible to request the launch of Internet
Explorer with a specific URL and to navigate to the “home” view of SmartCenter . The mechanism for
this is called a “request”. The application library makes creation of requests simple.

On the InfoviewWindow class there is a public property, SmartCenterSupport, which contains a


function called Request(). When this function is called, a new request will be created using the
RequestEventArgs.Message fields. The following fields exist on the Message member:

Action
Valid

The following shows an example implementation of a method that creates a request in SmartCenter,
causing the launch of Internet Explorer with the URL specified in the Action member:

HP.TouchSmart.Library.SCHelpers.RequestEventArgs reqArgs = new


HP.TouchSmart.Library.SCHelpers.RequestEventArgs();
reqArgs.Message = new HP.TouchSmart.Library.SCHelpers.RequestClass();
reqArgs.Message.Action = "http://www.hp.com";
reqArgs.Message.Valid = true;

this.SmartCenterSupport.Request(this, reqArgs);

If the Action member is set to the ID of the “home” view instead of a URL, SmartCenter will navigate to
the “home” view.

TouchSmart “Home” ACDB32C4-824E-496b-8954-8153065B18B9

reqArgs.Message.Action = "ACDB32C4-824E-496b-8954-8153065B18B9";

The Action member can also be set to the AppID / GUID of a hosted application that is registered with
SmartCenter. When a request with an AppID / GUID is made, SmartCenter will attempt to navigate to
the hosted application identified by this GUID. There is no programmatic mechanism to retrieve a list of
registered hosted applications.

4. Other functionality
The application library suppresses Tablet PC messages such as flick and gesture messages. This is done
intentionally to prevent the Vista “ghost mouse” from appearing while using SmartCenter.
The application library is Restart Manager aware and responds appropriately to basic Windows Restart
Manager messages to shut down properly. There is no support for restarting with Restart Manager
startup parameters.

When a hosted application is started with the command-line arguments “chromeless debug”, the
behavior of the application’s main window is modified such that it is possible to interactively change the
size of the window to verify layout switching behavior.

5. Document history

Version Comment
1.0 Initial version
1.1 Incorporated review comments
1.2 Added 3.0 assembly string info
Added section on handling of app events / registered messages in 3.0
1.3 Added information about WideInteractive layout for 3.0
Updated icon names usable for notification area in 3.0.
Added information about themes being deprecated in 3.0
Added information about dual-touch being deprecated in 3.0
Added information about AppID navigation (using requests) in 3.0
1.4 Added License Agreement

Das könnte Ihnen auch gefallen