Solved

How can I create a "hello world" touchscreen ap for Windows 7?

Posted on 2011-09-29
8
707 Views
Last Modified: 2012-06-27
My friend has an HP Touchsmart, and I'm curious how I could develop apps for it.

I read the MSDN article on how to get started but I'm not very advanced with WPF. I think I did everything right but I'm getting build errors like the below. It tells me to copy some XAML into the MainWindow XAML, then add some methods to the MainWindow class.
 
The InitializeComponent(); I had to comment out, because it had an error. I read up on that, and I have no idea how to follow the solution.

Error      1      'BasicManipulation.MainWindow' does not contain a definition for 'Window_ManipulationStarting' and no extension method 'Window_ManipulationStarting' accepting a first argument of type 'BasicManipulation.MainWindow' could be found (are you missing a using directive or an assembly reference?)      F:\Users\Casey\Documents\Visual Studio 2010\Projects\WpfTouch\WpfTouch\MainWindow.xaml      6      159      WpfTouch

Here is the XAML:
<Window x:Class="BasicManipulation.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Move, Size, and Rotate the Square"
        WindowState="Maximized"
        ManipulationStarting="Window_ManipulationStarting"
        ManipulationDelta="Window_ManipulationDelta"
        ManipulationInertiaStarting="Window_InertiaStarting">
    <Window.Resources>

        <!--The movement, rotation, and size of the Rectangle is
        specified by its RenderTransform.-->
        <MatrixTransform x:Key="InitialMatrixTransform">
            <MatrixTransform.Matrix>
                <Matrix OffsetX="200" OffsetY="200"/>
            </MatrixTransform.Matrix>
        </MatrixTransform>

    </Window.Resources>

    <Canvas>
        <Rectangle Fill="Red" Name="manRect"
                 Width="200" Height="200"
                 RenderTransform="{StaticResource InitialMatrixTransform}"
                 IsManipulationEnabled="true" />
    </Canvas>
</Window>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            //InitializeComponent();
        }
        void Window_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
        {
            e.ManipulationContainer = this;
            e.Handled = true;
        }
        void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {

            // Get the Rectangle and its RenderTransform matrix.
            Rectangle rectToMove = e.OriginalSource as Rectangle;
            Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;

            // Rotate the Rectangle.
            rectsMatrix.RotateAt(e.DeltaManipulation.Rotation,
                                 e.ManipulationOrigin.X,
                                 e.ManipulationOrigin.Y);

            // Resize the Rectangle.  Keep it square 
            // so use only the X value of Scale.
            rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
                                e.DeltaManipulation.Scale.X,
                                e.ManipulationOrigin.X,
                                e.ManipulationOrigin.Y);

            // Move the Rectangle.
            rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                                  e.DeltaManipulation.Translation.Y);

            // Apply the changes to the Rectangle.
            rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);

            Rect containingRect =
                new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

            Rect shapeBounds =
                rectToMove.RenderTransform.TransformBounds(
                    new Rect(rectToMove.RenderSize));

            // Check if the rectangle is completely in the window.
            // If it is not and intertia is occuring, stop the manipulation.
            if (e.IsInertial && !containingRect.Contains(shapeBounds))
            {
                e.Complete();
            }


            e.Handled = true;
        }
        void Window_InertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
        {

            // Decrease the velocity of the Rectangle's movement by 
            // 10 inches per second every second.
            // (10 inches * 96 pixels per inch / 1000ms^2)
            e.TranslationBehavior.DesiredDeceleration = 10.0 * 96.0 / (1000.0 * 1000.0);

            // Decrease the velocity of the Rectangle's resizing by 
            // 0.1 inches per second every second.
            // (0.1 inches * 96 pixels per inch / (1000ms^2)
            e.ExpansionBehavior.DesiredDeceleration = 0.1 * 96 / (1000.0 * 1000.0);

            // Decrease the velocity of the Rectangle's rotation rate by 
            // 2 rotations per second every second.
            // (2 * 360 degrees / (1000ms^2)
            e.RotationBehavior.DesiredDeceleration = 720 / (1000.0 * 1000.0);

            e.Handled = true;
        }


    }
}

Open in new window

0
Comment
Question by:harmono
8 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 36890256
you can Try Microsoft Surface SDK for Touch Screen Development.

Surface SDK Link
0
 
LVL 16

Assisted Solution

by:Kalpesh Chhatrala
Kalpesh Chhatrala earned 25 total points
ID: 36890259
Surface Sample available from below link

http://nsquaredsolutions.com/surfacebook/
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 36890715
I would say that it depends on the kind of application you want to build. Any regular application (good old WinForms) will work if the buttons are big enough to be used with the fingers!
0
 
LVL 1

Author Comment

by:harmono
ID: 36894246
emoreau,

Actually I have tried to create a simple two button test app in both Windows Forms and WPF and they didn't work properly. Apparently the touchscreen does not send regular mouse events. I have not tried different mouse events, I was mainly trying the MouseDown, and MouseUp events and the preview click events, because I'm trying to avoid the delay caused by double-clicking since this is a music app.
So the above code was my third try at this using WPF and some event handlers. I'm not sure if the Touchsmart works differently than Windows touch, but the dev sites I checked seemed to indicate you could develop a regular app. Maybe this weekend I'll try using the click, and double-click events to see if the touch sends that event. It may be that I'm in some kind of "mode" I'm not familiar with. I haven't messed with the Touchsmart PC much at all, so I have no idea what you can do with it.
It looks like I should work with the Touchsmart SDK (reading a tutorial right now) experiment with that, then maybe with what I've learned try to make it more universal, or just complete the prototype for the touchsmart environment, there may be some benefits that I don't know about.

I don't put much demands on the graphics, or things like that, it's mainly just latentcy and real time that is my usual technical challenge, although it would be nice to have some good graphics later on.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:harmono
ID: 36894253
kalpesh,

will that work with the HP Touchsmart? It has to work with that computer unless I decide to buy this Gateway that's on clearance.
0
 
LVL 1

Author Comment

by:harmono
ID: 36894444
I found this article on the touchsmartdevzone website. It covers the basics.

http://www.touchsmartdevzone.com/article/95/An-HP-TouchSmart-Application-Development-Guidelines-Primer/?textpage=2
0
 
LVL 7

Accepted Solution

by:
vbigham earned 225 total points
ID: 36894716
You should find that the wpf controls have at least some of the following events:
PreviewTouchDown
PreviewTouchMove
PreviewTouchUp
TouchDown
TouchEnter
TouchLeave
TouchMove
TouchUp

I have definitely used the TouchDown event on the TouchSmart.  I had the most success when I started using Commanding and attaching commands to buttons.  After that they seemed to work for touches and for the mouse.

For a full description about commanding:
http://msdn.microsoft.com/en-us/library/ms752308.aspx
(Check the very bottom of the article about creating custom commands implementing ICommand)

I don't know anything yet about using multitouch.. sorry.

Best of luck.
0
 
LVL 1

Author Closing Comment

by:harmono
ID: 36894997
Why this is not mentioned in so many articles I did not know, but this is exactly what I was looking for. This is a major breakthrough.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now