2

Before you mark this as a duplicate of this post, know that I am asking for more clarity and specificity than the answer to that question provides.

Specifically, I want to know how to, in C#, build a WM_TOUCH message and send it out.

The documentation on it (linked above) tells what it's composed of and how to gather the information it sends, but it says nothing about how to actually build a WM_TOUCH message, and I don't know enough about C# to work with what I've been able to find.

I know that it should look something like this:

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int wMSg, IntPtr wParam, IntPtr lParam);

/* code to make wParam and lParam */

SendMessage(HWND_BROADCAST, WM_TOUCH, _wParam, _lParam);

The wParam is going to be an int that tells how many multi-touch points found within the lParam. The lParam itself "Contains a touch input handle that can be used in a call to GetTouchInputInfo to retrieve detailed information about the touch points associated with this message" according to the msdn page. The GetTouchInputInfo function returns TOUCHINPUT structs.

My question is how to build the TOUCHINPUT structs in C# (since the documentation is in C++) and also how to pass that information through the SendMessage() function so that I can treat the kinect as a general multi-touch device in any multi-touch application.

Community
  • 1
  • 1
Scott M
  • 417
  • 5
  • 16

1 Answers1

1

You will need to represent the C++ structure in C# code.
Once you have a C# struct, you can use it as an input or output parameter.
The best way I have found of converting these structures is to use the P/Invoke Interop Assistant at : http://clrinterop.codeplex.com/releases/view/14120

Copying the TOUCHINPUT structure from the link you posted gives this output :

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct TOUCHINPUT {
    /// LONG->int
    public int x;
    /// LONG->int
    public int y;
    /// HANDLE->void*
    public System.IntPtr hSource;
    /// DWORD->unsigned int
    public uint dwID;
    /// DWORD->unsigned int
    public uint dwFlags;
    /// DWORD->unsigned int
    public uint dwMask;
    /// DWORD->unsigned int
    public uint dwTime;
    /// ULONG_PTR->unsigned int
    public uint dwExtraInfo;
    /// DWORD->unsigned int
    public uint cxContact;
    /// DWORD->unsigned int
    public uint cyContact;
}
blorkfish
  • 21,800
  • 4
  • 33
  • 24
  • Thank you for helping with how to build the struct, but I still have to tackle the GetTouchInputInfo handle that returns the structs. Or is that not an issue and I can just pass an array of TOUCHINPUT structs as the lParam? – Scott M Aug 28 '12 at 18:28
  • 1
    Hey Scott, You will need to Marshall the calls from C# ( managed ) to C/C++ (unmanaged). Have a look here : http://msmvps.com/blogs/gdicanio/ at the SAFEARRAY method being used. This creates an array in C#, and then uses CComSafeArray to do the marshalling. – blorkfish Aug 29 '12 at 03:29
  • Scott and/or blorkfish, did either of you figure out how to create a valid "touch input handle"? Is it actually just a pointer to a bunch of TOUCHINPUT structures, or something of the kind? If you have an answer, you might want to give it at http://stackoverflow.com/questions/15117490/creating-a-wm-touch-message-for-postmessage-in-c-sharp-net and I'll be extremely grateful! Thanks. – Gareth McCaughan Feb 27 '13 at 16:43