Categorized | Code

How to use the MSDN managed code gesture wrapper in a Windows Mobile 6.5 device project

Here´s a short how-to for getting started with gestures in your Windows Mobile applications. First how you set up your device project, and then i explain how it works using the managed gesture wrapper from MSDN.

First of all you need to consider if you would like to do it the “hardcore” way? by doing all the P/Invoke native calls yourself (then this documentation on MSDN is really useful) or if you just want to get gestures working and use the managed wrapper available in the MSDN code library, - You can also find the source code for the  wrapper there if you later need to find out how it really works. I haven´t  investigated the wrapper library yet, so I am not sure if it  encapsulates all the native functionality that is available.

First of all; Start Visual Studio 2008 and create a new device application solution. There is no specific Windows Mobile 6.5 application template so you just choose a Windows Mobile 6 project. Next you need to do is to add a reference to Microsoft.WindowsMobile.Gestures.dll (assuming now that you have downloaded the dll file) in your WYSIWYG in VS08.

  1. Visual Studio 2008 toolboxRight click on the General tab in the toolbox and select “choose items…”
  2. In the “Choose toolbox items” dialog select the browse button in the “.NET Framework Components” tab
  3. Browse to where you extracted the Gestures dll file and select it.
  4. A component called “GestureRecognizer” has it´s checkbox checked and selected.  Click the OK button.

If you look at your toolbox now you see that you have two new components. GestureRecognizer and PhysicEngine. These are non-visual components that you use in your application to interact with the native api’s.

Drag a GestureRecognizer component onto your application form and it is placed next to the default mainMenu1 component.  The GestureRecognizer component has very few properties and most important are the “Name” and “TargetControl”. You should name your component so that it reflects the target control you intend to “gesturize”. The TargetControl property has a drop down list with all components in your form. You will need to attach the GestureRecognizer to a component, or to the form itself.

Visual Studio 2008

The interesting part of the component is found when you view the events that GestureRecognizer exposes. The events are Begin, DoubleSelect, End, Gesture, Hold, Pan, Scroll and Select.

  • gestureeventsPan gesture is the event you want to use for moving things around with the finger in your UI.
  • Scroll is triggered when you accelerate the pan, meaning that when a pan event occurs, and you move your finger in any direction a Scroll event is fired. The pan state has entered “Inertia”.
  • Select is when you tap the screen.
  • DoubleSelect is the same as a double tap.
  • Hold fired when you tap and then hold your finger on the screen.
  • Begin is as the name implies an event that is triggered at the start of any gesture.
  • End is triggered when any gesture is ending.
  • Gesture is a generic event that fires on all events.

Each of the event work in a familiar way and each event carries an Microsoft.WindowsMobile.Gestures.GestureEventArgs object that extends from EventArgs. Here are the properties from GestureEventArgs:

  • .Kind gives you an enum with what type of gesture was triggered (Begin, DoubleSelect, End, Hold, Pan, Scroll and Select)
  • .State gives you an enum value with the state of the gesture. The gesture state can be one of the following: Begin, End, Inertia or None.
  • .X is the int coordinate from left
  • .Y is the int coordinate from the top.
  • .Location is a Point of X and Y

The exception from this is the Scroll event that gives you a GestureScrollEventArgs object that inherits from GestureEventArgs. The GestureScrollEventArgs object has some additional properties.

  • .Angle of the scroll movement.
  • .ScrollDirection is an enum value of either Up, Down, Left or Right.
  • .Velocity is the speed of your moment as a number representing pixels per second movement.

The best way to see this in work is to add a label control to your form, resize it so it can contain multiple lines. Then try to subscribe to the ie. pan event. Inside the Pan event method you can add the following code:

private void gestureRecognizer1_Pan(object sender, Microsoft.WindowsMobile.Gestures.GestureEventArgs e)
     string outPattern = "{0}:{1}-({2}:{3})";
     label1.Text = string.Format(outPattern, e.Kind, e.State, e.X, e.Y);

If you then run this on your Windows Mobile 6.5 device or emulator you can see the tracking information from the event inside the label. Playing around with this is useful and you can add more events to try the interaction between them. When you are familiar with how it work it is much easier to use it in your later projects.

Use Facebook to Comment on this Post

3 Responses to “How to use the MSDN managed code gesture wrapper in a Windows Mobile 6.5 device project”

  1. A cardinal principle of Total Quality escapes too many managers: you cannot continuously improve interdependent systems and processes before you progressively perfect interdependent, interpersonal relationships.
    Corporation: A nifty device for obtaining profit without individual responsibility.

  2. No matter if some one searches for his required
    thing, so he/she needs to be available that in detail, so that thing is maintained over here.

  3. Superb site you have here but I was curious about if you knew of any community forums that
    cover the same topics discussed here? I’d really like to be a part of group where I can get responses from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Thanks!


Leave a Reply