青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Coding for Gestures and Flicks on Tablet PC running Vista

LINK: http://www.therobotgeek.net/articles/gestureblocks.aspx

For this article, I wanted to demonstrate how to access gestures and flicks using C# code. I'll talk about accessing flicks using the tablet API and accessing gestures using the N-Trig native libraries. Surprisingly I couldn't find much out there that goes into any kind of depth in coding for either of these topics. So it seemed like a good opportunity to present some examples. I've included code for a C# game that uses the gestures for control. I hope you find it fun and useful.

Even though they are called "flicks", a flick is really a single touch gesture and an N-Trig gesture is a double touch gesture.  All the examples run on Windows Vista Ultimate 32bit. Windows Vista will only detect up to two fingers on the touch surface. However, Windows 7 promises to allow more than two finger detection. I'll have to try that next. HP is already shipping hardware that is multi-touch enabled on their TouchSmart PCs.  The Dell Latitude XT and XT2 tablet PCs are also using the N-Trig hardware for multi-touch.


Code to Detect If Running on a Tablet PC

I found some simple code to determine if your app is running on a tablet PC. It is a native call to GetSystemMetrics which is in User32.dll and you pass in SM_TABLETPC. I've included this code in the Flicks class.  You may want your app to auto-detect if it's running on a tablet to determine which features to enable.

 

        [DllImport("User32.dll", CharSet = CharSet.Auto)]

        public static extern int GetSystemMetrics(int nIndex);

 

        public static bool IsTabletPC()

        {

            int nResult = GetSystemMetrics(SM_TABLETPC);

            if (nResult != 0)

                return true;

 

            return false;

        }

 


Accessing Flicks (Single Touch Gestures) or UniGesture

If you've never heard of flicks before, they are single touch gestures that are triggered based on the speed of the touch across the tablet surface.  You can find more detail here.  It currently gives you eight directions that can be programmed at the OS level for use by applications.

I used the tabflicks.h file that I found in the folder - "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include" This header file is included with the Windows SDK. It contains all the flick structures and macro definitions needed to access flicks. I created a  class library project called FlickLib that contains the C# structures, DllImports and code to store and process the data. I also wrote a test WinForm application that shows the usage of the library.

   97 

   98         /// <summary>

   99         /// Override the WndProc method to capture the tablet flick messages

  100         /// </summary>

  101         /// <param name="msg"></param>

  102         protected override void WndProc(ref Message msg)

  103         {

  104             try

  105             {

  106                 if (msg.Msg == Flicks.WM_TABLET_FLICK)

  107                 {

  108                     Flick flick = Flicks.ProcessMessage(msg);

  109                     if (flick != null)

  110                     {

  111                         this.txtOutput.Text = string.Format("Point=({0},{1}) {2}\r\n",

  112                                                 flick.Point.X,

  113                                                 flick.Point.Y,

  114                                                 flick.Data.Direction);

  115 

  116                         // Set to zero to tell WndProc that message has been handled

  117                         msg.Result = IntPtr.Zero;

  118                     }

  119                 }

  120 

  121                 base.WndProc(ref msg);

  122             }

  123             catch (Exception ex)

  124             {

  125                 this.txtOutput.Text += string.Format("{0}\r\n", ex.Message);

  126             }

  127         }

  128 

I override the WndProc method of the WinForm to gain access to the WM_TABLET_FLICK messages sent to the window. The flick data is encoded in the WParam and the LParam of the windows message. I discovered that even though the params are IntPtr type, they are not actually pointers but are the real integer values to be used. I kept getting an Access Violation exception when I was trying to marshal the IntPtr to a structure. The solution was non-obvious. I couldn't find that documented anywhere. But it works correctly now so this is my contribution to the web for anyone trying to solve the same problem.

It is important to note that on line # 117, I set msg.Result = IntPtr.Zero.  This tells the base.WndProc method that the message has been handled so ignore it.  This is important because the underlying pen flicks can be assigned to actions such as copy and paste.  If the message is not flagged as handled, the app will attempt to perform the action.

WinForm Flicks Test C# source code WinFlickTest.zip

Accessing Double Touch Gestures or DuoGestures

The N-Trig hardware on the HP TouchSmart tablet provides the ability to detect two (or more) touches on the surface. This allows the tablet to respond on two finger gestures. You can see the current DuoGestures in use from N-Trig here.

I've created a class library project called GestureLib which wraps the native libraries from N-Trig so that they can be called using C#. Obviously this will only run on tablets that have the N-Trig hardware. Currently there is the HP TouchSmart tx2 and the Dell Latitude XT & XT2 laptops. I'll be testing and updating code for the HP TouchSmart IQ505 panel that uses the NextWindow hardware. If someone has any other tablets, touch panels and/or UMPC devices, I'd be happy to work together to create a version for that as well.

 

        private Gestures _myGestures = new Gestures();

        private int NTR_WM_GESTURE = 0;

 

        /// <summary>

        /// Override OnLoad method to Connect to N-Trig hardware and

        /// Register which gestures you want to receive messages for and

        /// Register to receive the Window messages in this WinForm

        /// </summary>

        /// <param name="eventArgs"></param>

        protected override void OnLoad(EventArgs eventArgs)

        {

            try

            {

                bool bIsConnected = this._myGestures.Connect();

                if (bIsConnected == true)

                {

                    this.txtOutput.Text += "Connected to DuoSense\r\n";

 

                    TNtrGestures regGestures = new TNtrGestures();

                    regGestures.ReceiveRotate = true;

                    regGestures.UseUserRotateSettings = true;

                    regGestures.ReceiveFingersDoubleTap = true;

                    regGestures.UseUserFingersDoubleTapSettings = true;

                    regGestures.ReceiveZoom = true;

                    regGestures.UseUserZoomSettings = true;

                    regGestures.ReceiveScroll = true;

                    regGestures.UseUserScrollSettings = true;

 

                    bool bRegister = this._myGestures.RegisterGestures(this.Handle, regGestures);

                    if (bRegister == true)

                    {

                        this.NTR_WM_GESTURE = Gestures.RegisterGestureWinMessage();

                        if (this.NTR_WM_GESTURE != 0)

                            this.txtOutput.Text += string.Format("NTR_WM_GESTURE = {0}\r\n", this.NTR_WM_GESTURE);

                    }

                }

                else

                    this.txtOutput.Text = "Error connecting to DuoSense\r\n";

            }

            catch (Exception ex)

            {

                this.txtOutput.Text += string.Format("{0}\r\n", ex.Message);

            }

        }

 

        /// <summary>

        /// Override OnClosing method to ensure that we Disconnect from N-Trig hardware

        /// </summary>

        /// <param name="cancelEventArgs"></param>

        protected override void OnClosing(CancelEventArgs cancelEventArgs)

        {

            this._myGestures.Disconnect();

 

            base.OnClosing(cancelEventArgs);

        }

 

Once you look at the code you will note that you have to connect to the N-Trig hardware at the start of the app.  I put that call in the OnLoad method.  Once you have a handle to the hardware, then you will use that throughout the lifetime of the app.  It is stored in the Gestures class.  With the handle, you will register which gesture messages you want the window to receive.  Once registered, you will start to see NTR_WM_GESTURE message showing up in the WndProc method.  I created a ProcessMessage method in the Gestures class that will determine which gesutre type it is and extract the data for the particular gesture.

One thing to note is if you look at the DllImports for the NtrigISV.dll native library you will see that there is name mangling with the method calls. I had to use Dependency Walker to determine the actual names of the methods. So be warned that when N-Trig releases a new version of their DLL that this code will probably break.

N-Trig Gestures WinForm Test source code WinGestureTest.zip

Problems with Marshalling Data from C++ to C#

I had an issue where I was only getting the Zoom messages.  My friend, Ben Gavin, helped me solve the problem.  It had to do with marshalling the data into the struct.  The original C++ struct looks like this:

 

typedef struct _TNtrGestures

{  

    bool ReceiveZoom;

    bool UseUserZoomSettings;

    bool ReceiveScroll;

    bool UseUserScrollSettings;

    bool ReceiveFingersDoubleTap;

    bool UseUserFingersDoubleTapSettings;

    bool ReceiveRotate;

    bool UseUserRotateSettings;

} TNtrGestures;

 

For my original port, I just did a LayoutKind.Sequential and set everything as a bool like below.

    [StructLayout(LayoutKind.Sequential)]

    public struct TNtrGestures

    {

        public bool ReceiveZoom;

        public bool UseUserZoomSettings;

        public bool ReceiveScroll;

        public bool UseUserScrollSettings;

        public bool ReceiveFingersDoubleTap;

        public bool UseUserFingersDoubleTapSettings;

        public bool ReceiveRotate;

        public bool UseUserRotateSettings;

    }

Trouble is that bool in C++ is one byte where as a bool in C# is an Int32 or four bytes. Now if the C++ struct was labeled with a BOOL, then it would have been four bytes. So the new declaration of the struct in C# looks like this:

    [StructLayout(LayoutKind.Explicit)]

    public struct TNtrGestures

    {

        [FieldOffset(0)]public bool ReceiveZoom;

        [FieldOffset(1)]public bool UseUserZoomSettings;

        [FieldOffset(2)]public bool ReceiveScroll;

        [FieldOffset(3)]public bool UseUserScrollSettings;

        [FieldOffset(4)]public bool ReceiveFingersDoubleTap;

        [FieldOffset(5)]public bool UseUserFingersDoubleTapSettings;

        [FieldOffset(6)]public bool ReceiveRotate;

        [FieldOffset(7)]public bool UseUserRotateSettings;

    }

Once I used the FieldOffsetAttribute to set each bool to one byte each, the Rotate messages started to work correctly. Thanks Ben...


WPF Gestures Example Code

 

                WindowInteropHelper winHelper = new WindowInteropHelper(this);

                HwndSource hwnd = HwndSource.FromHwnd(winHelper.Handle);

                hwnd.AddHook(new HwndSourceHook(this.MessageProc));

 

Using the same GestureLib class library, I also created an app that shows how to capture the gestures using a WPF application.  That was an interesting exercise because I had never gotten a Windows handle from a WPF app.  I discovered the WinInteropHelper class that gets the underlying Windows handle. I also had to hook the MessageProc handler to get the messages.  The WndProc method is not available to override in WPF.

WPF Gestures Test source code WpfGestureTest.zip

Gesture Blocks - C# Game using Gestures and Flicks

Just creating test apps is boring and I wanted to create a game example that uses the flicks and gestures for control. I chose to build a simple game that shows off some of the possibilities for touch control. I call the game Gesture Blocks. It will give you a good starting point on using gestures in games. Watch the video to see the gestures in action.

Gesture Blocks Game source code WinGestureBlocks.zip

Conclusion

I hope the code I provided was useful and helpful. I will try to update the examples as issues are resolved. I'm also going to work on some other game examples that continue to show what can be done with gestures. The next project will be to load Windows 7 onto the tablet and write some code for more than DuoGestures.


posted on 2009-05-19 17:52 zmj 閱讀(1742) 評論(1)  編輯 收藏 引用

評論

# re: Coding for Gestures and Flicks on Tablet PC running Vista 2011-01-12 22:52 rena_yang

你好,我是前面問你問題的人,能不能發到我郵箱呢,謝謝。48388266@qq.com  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            老鸭窝毛片一区二区三区| 久久久久久高潮国产精品视| 欧美激情一区二区在线| 久久一本综合频道| …久久精品99久久香蕉国产| 女仆av观看一区| 欧美aⅴ99久久黑人专区| 91久久精品一区| 亚洲激情影视| 欧美日韩国产精品一区二区亚洲| 一本久道久久综合中文字幕| 亚洲视频中文字幕| 国产欧美日韩在线| 久热re这里精品视频在线6| 欧美 日韩 国产 一区| 一区二区三区av| 亚洲在线电影| 最新国产精品拍自在线播放| 亚洲毛片在线观看.| 国产精品自在线| 欧美mv日韩mv国产网站| 欧美三级欧美一级| 久久精品一区蜜桃臀影院| 免费久久精品视频| 午夜精品久久久久久| 久久综合狠狠综合久久激情| 制服丝袜激情欧洲亚洲| 久久成人18免费观看| 夜夜嗨av一区二区三区网页| 欧美中日韩免费视频| 亚洲毛片在线| 久久精品网址| 亚洲一区免费观看| 久热精品视频在线| 亚洲欧美日韩成人| 你懂的国产精品| 久久精品一本久久99精品| 欧美日韩大片一区二区三区| 久久精品在线观看| 欧美亚洲成人精品| 亚洲黄一区二区三区| 国内精品久久久久久久影视蜜臀 | 国产精品高潮视频| 欧美激情亚洲另类| 很黄很黄激情成人| 亚洲尤物在线视频观看| 99re6热在线精品视频播放速度| 午夜精品在线观看| 亚洲综合首页| 欧美区二区三区| 欧美大成色www永久网站婷| 国产一区二区精品久久91| 99re66热这里只有精品4| 亚洲欧洲在线免费| 欧美1区免费| 欧美国产精品专区| 亚洲国产欧洲综合997久久| 久久国产精品高清| 久久久五月婷婷| 国产一区二区三区日韩欧美| 亚洲欧美日韩另类| 久久精品亚洲一区二区| 国产欧美午夜| 欧美一区二区三区久久精品| 欧美有码在线视频| 国产精品综合不卡av| 亚洲欧美国产三级| 久久久久久久综合| 在线播放视频一区| 免费在线观看精品| 亚洲精品久久久久久久久久久久| 亚洲日本电影在线| 欧美日产一区二区三区在线观看| 亚洲黄色av| 亚洲视频在线视频| 国产精品久久久久久久7电影 | 亚洲青涩在线| 亚洲视频999| 国产精品国产三级国产普通话三级| 日韩午夜激情av| 午夜精品美女久久久久av福利| 国产精品久久久久久久久久久久久 | 亚洲欧洲在线一区| 在线中文字幕一区| 国产精品一区二区欧美| 久久国产精品亚洲va麻豆| 美女国内精品自产拍在线播放| 亚洲黄色高清| 欧美日韩一区二区在线| 午夜精品久久久久久| 免费永久网站黄欧美| 一本久久青青| 国产在线精品一区二区夜色| 裸体丰满少妇做受久久99精品| 亚洲人成在线观看一区二区| 欧美一二三区精品| 亚洲动漫精品| 国产精品二区影院| 久久人人爽人人| 亚洲乱码国产乱码精品精天堂 | 麻豆91精品91久久久的内涵| 亚洲国产精品一区二区尤物区 | 国产精品少妇自拍| 久久久91精品国产| 一区二区三区不卡视频在线观看| 久久爱另类一区二区小说| 亚洲日韩中文字幕在线播放| 国产精品视频在线观看| 男同欧美伦乱| 欧美一区二区日韩一区二区| 亚洲人成网站777色婷婷| 久久精品国产久精国产爱| 日韩视频中文字幕| 精品51国产黑色丝袜高跟鞋| 国产精品成人一区二区| 免费亚洲一区| 久久国产一二区| 亚洲一区二区三区中文字幕在线| 欧美成人激情视频| 欧美专区18| 在线亚洲高清视频| 亚洲国产精品va在线观看黑人| 国产日韩精品一区| 欧美体内she精视频| 欧美福利视频一区| 久久香蕉精品| 久久久久久久久一区二区| 欧美一区二区| 亚洲欧美三级伦理| 亚洲校园激情| 一本色道久久综合一区 | 亚洲一区影音先锋| 99天天综合性| 99精品视频一区| 亚洲精品国产日韩| 亚洲国产日韩欧美在线动漫| 一色屋精品视频在线观看网站| 国产一区二区av| 国产欧美日韩91| 国产精品网曝门| 国产欧美精品在线观看| 国产欧美在线视频| 国产一区二区三区视频在线观看| 国产精品美女主播在线观看纯欲| 国产精品福利在线观看网址| 欧美午夜视频一区二区| 国产精品vvv| 国产精品一区二区女厕厕| 国产精品毛片大码女人| 国产精品日本一区二区| 国产精品一区免费视频| 国产日韩av高清| 国内精品久久国产| 亚洲国产导航| av成人免费在线| 亚洲欧美中文日韩v在线观看| 亚洲欧美电影在线观看| 久久精品国产欧美亚洲人人爽| 久久成人一区| 免费观看日韩av| 亚洲日本va午夜在线影院| 99热在这里有精品免费| 亚洲一二区在线| 久久大香伊蕉在人线观看热2| 久久久久久国产精品一区| 欧美福利网址| 国产伦精品一区二区三区视频黑人 | 国产主播一区二区三区| 在线观看视频免费一区二区三区 | 红桃av永久久久| 亚洲第一级黄色片| 日韩香蕉视频| 久久aⅴ乱码一区二区三区| 欧美99久久| 亚洲深夜激情| 久久网站免费| 欧美性大战久久久久久久蜜臀| 国产网站欧美日韩免费精品在线观看 | 欧美国产在线电影| 国产精品一区二区在线观看不卡 | 亚洲欧洲三级| 午夜精品久久久久99热蜜桃导演| 久久综合九色九九| 亚洲精品在线观看免费| 小辣椒精品导航| 欧美精品福利视频| 国产一区二区三区高清播放| 亚洲美女中出| 久久人人爽人人爽爽久久| 99在线热播精品免费| 久久婷婷国产综合国色天香| 国产精品h在线观看| 亚洲国产影院| 久久男人av资源网站| 中日韩视频在线观看| 欧美高清视频免费观看| 狠狠色丁香久久婷婷综合丁香| 在线综合亚洲| 亚洲日本免费| 久久人体大胆视频|