16 December 2010 0 Comments

Multitouch Part 3: Multitouch in managed code and WPF

After yesterday’s post on developing with gestures , there may have been wailing and gnashing of teeth that all of the code samples were C++.  Well, today we will discuss multitouch in managed code.  Now, a little trip down memory lane…remember that Windows 7 was released before .NET 4.0.  Therefore, there were multitouch resources made available for developers at the launch of Windows 7 (that would work with .NET 3.5).  Then, when .NET 4.0 was released (with WPF as a part of that), a lot of multitouch support was moved and baked in WPF 4.0.  Therefore, it may sometimes be a little confusing to work with multitouch since there are differences in the before and after .NET 4.0 worlds.    Pre-.NET 4.0 Since not everyone is on .NET 4.0 yet, I do want to cover what you can do with .NET 3.5.  There are some great resources at http://code.msdn.microsoft.com/WindowsTouch .  Specifically, check out the Windows 7 Multitouch .NET Interop Sample Library .  It provides developers with full multitouch functionality for both managed WinForms and WPF 3.5 SP1.  This library contains a few demos for reference, including detailed samples showcasing multitouch gesture support, as well as manipulation and inertia for both managed WinForms and WPF. In the sample library, there is a class called Windows7.Multitouch.Handler.  This is an abstract base class for the derived classes TouchHandler and GestureHandler.  A form can have one handler, either a touch handler or a gesture handler.  The form will need to create the handler and register to events.  You can use Factory to create one of the handlers.  This can be done slightly differently depending on the type of touch support that you need:  For Windows Forms, managed Win32 hWnd, and WPF gesture support , the handler wraps the Window (hWnd).  In the below code snippet (taken from the mtWPFGesture project in the Interop Sample Library), the constructor of the MainWindow first checks for multitouch support, calls Factory.CreateGestureHandler() to create a gesture handler, and then wires up event handlers on all of the gesture events on the gesture handler.  private readonly Windows7.Multitouch. GestureHandler _gestureHandler; public MainWindow() { InitializeComponent(); if (!Windows7.Multitouch.

Continued here:
Multitouch Part 3: Multitouch in managed code and WPF

If you liked this post, buy me a Coffee.

Leave a Reply