Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Image Manipulation in Multitouch Development

, 3 Apr 2010
In this article, I will describe Image manipulation in Windows 7 multitouch Environment
Win7MultitouchDemo.zip
Win7MultitouchDemo
Win7MultitouchDemo.suo
Win7MultitouchDemo
images
Hydrangeas.jpg
Properties
Settings.settings
Windows7API
MultiTouchAPI
Windows7.Multitouch.WinForms
Properties
Windows7.Multitouch.WinForms.csproj.vspscc
Windows7.Multitouch.WPF
Properties
Windows7.Multitouch.WPF.csproj.vspscc
Windows7.Multitouch
Properties
Windows7.Multitouch.csproj.vspscc
Win7MultitouchDemo_1_.zip
Win7_20MultiTouchAPI_1_.zip
Win7_MultiTouchAPI.zip
MultiTouchAPI
Windows7.Multitouch.WinForms
Properties
Windows7.Multitouch.WinForms.csproj.vspscc
Windows7.Multitouch.WPF
Properties
Windows7.Multitouch.WPF.csproj.vspscc
Windows7.Multitouch
Properties
Windows7.Multitouch.csproj.vspscc
//-----------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Windows7.Multitouch.Interop;

namespace Windows7.Multitouch.Win32Helper
{
    class Win32HwndWrapper : IHwndWrapper
    {
        private readonly IntPtr _hWnd;

        public Win32HwndWrapper(IntPtr hWnd)
        {
            _hWnd = hWnd;

            HandleCreated += (s, e) => { };
            HandleDestroyed += (s, e) => { };
        }

        #region IHwndWrapper Members

        public IntPtr Handle
        {
            get { return _hWnd; }
        }

        public object Source
        {
            get { return _hWnd; }
        }

        public event EventHandler HandleCreated;

        public event EventHandler HandleDestroyed;

        public bool IsHandleCreated
        {
            get { return User32.IsWindow(_hWnd); }
        }

        public System.Drawing.Point PointToClient(System.Drawing.Point point)
        {
            POINT p = new POINT { x = point.X, y = point.Y };
            User32.ScreenToClient(_hWnd, ref p);
            return new System.Drawing.Point(p.x, p.y);
        }

        #endregion

        internal void NotifyHandleDestroyed()
        {
            HandleDestroyed(this, EventArgs.Empty);
        }
    }

    /// <summary>
    /// A factory that creates touch or gesture handler for a HWnd based Window
    /// </summary>
    public class Factory
    {
        /// <summary>
        ///  A factory that creates touch or gesture handler for a HWnd based Window
        /// </summary>
        /// <remarks>We use factory to ensure that only one handler will be created for a window, since Gesture and Touch are mutually exclude</remarks>
        /// <typeparam name="T">The handler type</typeparam>
        /// <param name="hWnd">The Windows handle that need touch or gesture events</param>
        /// <returns>TouchHandler or Gesture Handler</returns>
        public static T CreateHandler<T>(IntPtr hWnd) where T : Windows7.Multitouch.Handler
        {
            Win32HwndWrapper win32HwndWrapper = new Win32HwndWrapper(hWnd);
            T handler = Windows7.Multitouch.Handler.CreateHandler<T>(win32HwndWrapper);

            //Register fot Windows Messages in order to raise the destroy handle event
            handler.WindowMessage += (s, e) =>
            {
                if (e.HWnd == hWnd && e.Message == User32.WM_NCDESTROY)
                {
                    win32HwndWrapper.NotifyHandleDestroyed();
                }
            };

            return handler;
        }
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

_ Kunal Chowdhury _
Technical Lead
India India
Kunal Chowdhury is a Microsoft "Client Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik MVP, Nokia Developer Champion, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.
 
He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows 8 (WinRT). He posts his findings, articles in his technical blog and CodeProject.
 
Technical Blog: http://www.kunal-chowdhury.com
Facebook: http://facebook.com/blog.kunal
Twitter : http://twitter.com/kunal2383
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 3 Apr 2010
Article Copyright 2010 by _ Kunal Chowdhury _
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid