Click here to Skip to main content
15,882,152 members
Articles / Desktop Programming / WPF

Image Manipulation in Multitouch Development

Rate me:
Please Sign up or sign in to vote.
4.81/5 (8 votes)
3 Apr 2010CPOL3 min read 60.8K   2.5K   19  
In this article, I will describe Image manipulation in Windows 7 multitouch Environment
//-----------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Windows7.Multitouch.Interop;

namespace Windows7.Multitouch.WinForms
{
    /// <summary>
    /// Represents a WinForms Control
    /// </summary>
    class ControlWrapper : IHwndWrapper
    {
        private readonly Control _control;

        public ControlWrapper(Control control)
        {
            //It is better to add this to the application manifest, but if the user
            //forgot to do that, we do.
            User32.SetProcessDPIAware();

            _control = control;
 
        }

        #region IHwndWrapper Members

        public IntPtr Handle
        {
            get { return _control.Handle; }
        }

        public object Source
        {
            get { return _control; }
        }


        public event EventHandler HandleCreated
        {
            add
            {
                _control.HandleCreated += value;
            }
            remove
            {
                _control.HandleCreated -= value;
            }
        }


        public event EventHandler HandleDestroyed
        {
            add
            {
                _control.HandleDestroyed += value;
            }
            remove
            {
                _control.HandleDestroyed -= value;
            }
        }
        
        public bool IsHandleCreated
        {
            get { return _control.IsHandleCreated; }
        }

        public Point PointToClient(Point point)
        {
            return _control.PointToClient(point);
        }


        public IGUITimer CreateTimer()
        {
            return new GUITimer();
        }

        #endregion
    }

    /// <summary>
    /// The WinForm GUI Timer for Inerta Events
    /// </summary>
    public class GUITimer : Timer, IGUITimer
    {
    }


    /// <summary>
    /// A factory that creates touch or gesture handler for a Windows Forms controls
    /// </summary>
    public class Factory
    {
        /// <summary>
        /// A factory that creates touch or gesture handler for a Windows Forms controls
        /// </summary>
        /// <remarks>We use factory to ensure that only one handler will be created for a control, since Gesture and Touch are mutually exclude</remarks>
        /// <typeparam name="T">The handler type</typeparam>
        /// <param name="control">The control that need touch or gesture events</param>
        /// <returns>TouchHandler or Gesture Handler</returns>
        public static T CreateHandler<T>(Control control) where T : Windows7.Multitouch.Handler
        {
            return Windows7.Multitouch.Handler.CreateHandler<T>(new ControlWrapper(control));
        }

        /// <summary>
        /// Create a wrapper for a UI based timer 
        /// </summary>
        /// <remarks>This timer is called in the context of the UI thread</remarks>
        /// <returns>A timer Wrapper</returns>
        public static IGUITimer CreateTimer()
        {
            return new GUITimer();
        }
    }
}

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)


Written By
Technical Lead
India India

Kunal Chowdhury is a former Microsoft "Windows Platform Development" MVP (Most Valuable Professional, 2010 - 2018), a Codeproject Mentor, Speaker in various Microsoft events, Author, passionate Blogger and a Senior Technical Lead 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 app development. He posts his findings, articles, tutorials in his technical blog (www.kunal-chowdhury.com) and CodeProject.


Books authored:


Connect with Kunal on:





Comments and Discussions